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

**URL:** <https://discourse.nodered.org/t/using-a-subflow-environment-variable-to-set-msg-payload-probably-simple-but-i-dont-get-it/27460>\
**Category:** General\
**Created:** [28 May 2020 20:51 UTC](https://discourse.nodered.org/t/using-a-subflow-environment-variable-to-set-msg-payload-probably-simple-but-i-dont-get-it/27460 "2020-05-28T20:51:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![santaklon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/santaklon/32/16737_2.png) [@santaklon](https://discourse.nodered.org/u/santaklon)\
**Post date:** [28 May 2020 20:51 UTC](https://discourse.nodered.org/t/using-a-subflow-environment-variable-to-set-msg-payload-probably-simple-but-i-dont-get-it/27460/1 "2020-05-28T20:51:56Z")

</div>

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:

```auto
[{"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?

---

<div class="post-metadata">

**Author:** ![nlecaude](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nlecaude/32/25_2.png) [@nlecaude](https://discourse.nodered.org/u/nlecaude)\
**Post date:** [29 May 2020 00:35 UTC](https://discourse.nodered.org/t/using-a-subflow-environment-variable-to-set-msg-payload-probably-simple-but-i-dont-get-it/27460/2 "2020-05-29T00:35:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![santaklon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/santaklon/32/16737_2.png) [@santaklon](https://discourse.nodered.org/u/santaklon)\
**Post date:** [29 May 2020 00:52 UTC](https://discourse.nodered.org/t/using-a-subflow-environment-variable-to-set-msg-payload-probably-simple-but-i-dont-get-it/27460/3 "2020-05-29T00:52:03Z")

</div>

...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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [28 July 2020 00:52 UTC](https://discourse.nodered.org/t/using-a-subflow-environment-variable-to-set-msg-payload-probably-simple-but-i-dont-get-it/27460/4 "2020-07-28T00:52:11Z")

</div>

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