Insert flow variables in message payloads

Hi everyone,
here comes another easy challenge for the Node-Red pros among you :smile: Following situation: Based on a certain trigger, I would like to send a message payload to an Alexa node that contains data from some flow variables I defined.

Here is my example for the msg.payload I would like to create from a change node using the JSONata editor:

"Outside temperature is about "& flow.get("OutsideTemp") &" degrees at "& flow.get("Humidity") &" % humidity"

Unfortunately, the variables get simply ignored when creating the actual object. Now tell me what´s the trick to integrate flow variables into messages :mage:

I will do this myself in a function node.
In a function node you concatenate strings with a + instead &.

msg.payload= "Outside temperature is about "+ flow.get("OutsideTemp") +" degrees at "+ flow.get("Humidity") +" % humidity"
return msg
1 Like

In JSONata expression it would be $flowContext("OutsideTemp") not flow.get

1 Like

Beautiful :smiley: Thanks both @edje11 & @E1cid for the quick response!

Here's a picture of my flow to get a report on my Raspberry Pi.


And here's what 'Format response' looks like using Javascript...

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.