# Subflow vs mqtt

**URL:** <https://discourse.nodered.org/t/subflow-vs-mqtt/18074>\
**Category:** General\
**Created:** [17 November 2019 20:52 UTC](https://discourse.nodered.org/t/subflow-vs-mqtt/18074 "2019-11-17T20:52:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kris](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@kris](https://discourse.nodered.org/u/kris)\
**Post date:** [17 November 2019 20:52 UTC](https://discourse.nodered.org/t/subflow-vs-mqtt/18074/1 "2019-11-17T20:52:20Z")

</div>

Hi,

I started using Node-Red one year ago.  
It's really a pleasure to use it.

I would like to optimize my project for one aspect and I don't find how to do it by myself, so I expect someone could give me a good idea.

On my Dashboard I have a screen where are shown regular information of each node. It's an easy way to have the status of each of them. For each node I get information from an mqtt input.  
Right now, I duplicate flows for each node, that is a really poor basic method to do it.

I would like to put a generic flow as a subflow, not to have to duplicate many times the same things. I used some subflows for other needs without any problem.  
On this one, I would like to give to the subflow input the name of the node to use to get is status. I was looking for environment variables or similar principal but I don't find the right way.

Here I give you an example of things I would like to to inside a subflow.

Hope to be clear enough?  
regards

```auto
[{"id":"402dca36.6c4d94","type":"mqtt in","z":"5361bd8e.79b4dc","name":"","topic":"RM-CUI-L1/board","qos":"2","broker":"11a7e268.e231a6","x":790,"y":100,"wires":[["858e1cf5.ee3548"]]},{"id":"858e1cf5.ee3548","type":"ui_text","z":"5361bd8e.79b4dc","group":"75409553.e56a64","order":2,"width":0,"height":0,"name":"Bord name","label":"","format":"{{msg.payload}}","layout":"row-left","x":1170,"y":100,"wires":[]},{"id":"c01b6dbe.9ac02","type":"mqtt in","z":"5361bd8e.79b4dc","name":"","topic":"RM-CUI-L1/status","qos":"2","broker":"11a7e268.e231a6","x":790,"y":200,"wires":[["df2fe446.4a207"]]},{"id":"df2fe446.4a207","type":"change","z":"5361bd8e.79b4dc","name":"0/1 -> A/P","rules":[{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"str","to":"Absent","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"str","to":"Présent","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":980,"y":200,"wires":[["1fe2b15e.089a67"]]},{"id":"1fe2b15e.089a67","type":"ui_text","z":"5361bd8e.79b4dc","group":"75409553.e56a64","order":4,"width":0,"height":0,"name":"","label":"Status :","format":"{{msg.payload}}","layout":"row-left","x":1160,"y":200,"wires":[]},{"id":"d2028a08.2cb468","type":"mqtt in","z":"5361bd8e.79b4dc","name":"","topic":"RM-CUI-L1/host","qos":"2","broker":"11a7e268.e231a6","x":800,"y":40,"wires":[["b36f894a.6a4698"]]},{"id":"b36f894a.6a4698","type":"ui_text","z":"5361bd8e.79b4dc","group":"75409553.e56a64","order":1,"width":0,"height":0,"name":"Host","label":"","format":"{{msg.payload}}","layout":"row-left","x":1150,"y":40,"wires":[]},{"id":"da105396.d1408","type":"mqtt in","z":"5361bd8e.79b4dc","name":"","topic":"RM-CUI-L1/version","qos":"2","broker":"11a7e268.e231a6","x":790,"y":160,"wires":[["8c866e8f.6732a8"]]},{"id":"8c866e8f.6732a8","type":"ui_text","z":"5361bd8e.79b4dc","group":"75409553.e56a64","order":3,"width":"6","height":"1","name":"Version","label":"","format":"{{msg.payload}}","layout":"row-left","x":1160,"y":160,"wires":[]},{"id":"11a7e268.e231a6","type":"mqtt-broker","z":"","name":"mosquitto","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"75409553.e56a64","type":"ui_group","z":"","name":"Sonoff T1 - 1 ","tab":"537fac73.f7a754","order":3,"disp":true,"width":"6","collapse":false},{"id":"537fac73.f7a754","type":"ui_tab","z":"","name":"Boards","icon":"dashboard","order":6}]

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 November 2019 21:41 UTC](https://discourse.nodered.org/t/subflow-vs-mqtt/18074/2 "2019-11-17T21:41:45Z")

</div>

The only thing I could see to simplify the flow would be to have one `mqtt-in` node with a topic of `RM-CUI-L1/#` and feed that into a switch node what would examine the whole topic and send out the msg to a particular leg based on the matching subtopic.
