Need help for my first function

#1

Hi,

I'm struggling with a very basic principle.

I would like to trigger a custom message payload based on a time trigger.

For example, if it's 9:00 AM I'd like to send this payload "colorTemp":153 to another node.

Right now I'm experimenting with a timestamp chained with a series of "time range" nodes.
Each time range node has a time frame, if my message doesn't match node's timeframe then it goes one node further etc until it triggers a function.

My function contains this code

    msg.payload="colorTemp\"\:153"
    return msg;

I'm confused because returning the function above doesn't create the same effect as this code from my inject node

{"colorTemp":153}

Here is what I get from the debugging window:

msg.payload : string[14]
"colorTemp":153"

Thanks for your help

0 Likes

#2

you are creating it as a string but you need/want to create it as a javascript object.

The w3schools web pages on javascript objects will give you all the information you need and will also help you understand what you need to do in a Node-RED function node

0 Likes