Using a Subflow environment variable to set msg.payload - probably simple, but i dont get it!

I am simply trying to create a subflow where i can set an environment variable that is then used within the subflow as the msg.payload to be sent over MQTT. Apparently i dont get the syntax right because it just wont work. Surely this is dead simple - so simple that i cant find any thread or how-to video even mentioning it!

Here is the current state of my hair-pulling:

[{"id":"8ee57000.919ee","type":"subflow","name":"set scene","info":"","category":"","in":[{"x":200,"y":320,"wires":[{"id":"49044512.b90e3c"}]}],"out":[],"env":[{"name":"scene","type":"str","value":"","ui":{"icon":"font-awesome/fa-paint-brush"}}],"color":"#3FADB5","icon":"node-red-dashboard/ui_colour_picker.png"},{"id":"49044512.b90e3c","type":"change","z":"8ee57000.919ee","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{scene}","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":320,"wires":[["8b1a6923.814a78"]]},{"id":"8b1a6923.814a78","type":"mqtt out","z":"8ee57000.919ee","name":"","topic":"scene","qos":"","retain":"","broker":"750b4b2d.152d34","x":530,"y":320,"wires":[]},{"id":"750b4b2d.152d34","type":"mqtt-broker","z":"","name":"Aedes","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"86b5e517.e0cfb8","type":"subflow:8ee57000.919ee","z":"84deed27.da601","name":"","env":[{"name":"scene","value":"cleaning","type":"str"}],"x":540,"y":560,"wires":[]}]

Could any of you smart people please end my misery?

Remove the curly braces, they are not needed when the property in the change node is set to an env var.

...I could have sworn i tried exactly this about a thousand times. It works - just as easy as I expected it to be. Thank you!

1 Like

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