# Using subflow environment variable to set mqtt topic

**URL:** <https://discourse.nodered.org/t/using-subflow-environment-variable-to-set-mqtt-topic/15331>\
**Category:** General\
**Created:** [9 September 2019 20:53 UTC](https://discourse.nodered.org/t/using-subflow-environment-variable-to-set-mqtt-topic/15331 "2019-09-09T20:53:40Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [13 September 2019 16:26 UTC](https://discourse.nodered.org/t/using-subflow-environment-variable-to-set-mqtt-topic/15331/8 "2019-09-13T16:26:27Z")

</div>

The trick is to use additional subflow properties:

 ![Node-RED](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/13f000a6c8cdb95984ef153ab8e3e5656238fb8f.png)

Here you can see we've defined the `ROOM` env var. We then define four further env vars, one for each of the topics you want to use. In the subflow properties table, I've set their type to be Env Var - note the `$` next to each one. That field type allows you to compose a value in the way you need.

You can then use `${TOPIC1}` etc in your MQTT nodes.

---

_[View the full topic](https://discourse.nodered.org/t/using-subflow-environment-variable-to-set-mqtt-topic/15331)._
