Hello!
I want to create a subflow that can turn off a bulb when a certain message is received and then poll its state to make sure the bulb is off. After confirmation it should repeat the input message. The purpose of this is to daisy-chain a bunch of these (one for each bulb) and watch bulbs being turned off one after another.
It would be great if I could make subscribing to the mqtt topic for the bulb configurable though the subflow environment variables so I could just instantiate the subflow once for each bulb.
I've tried the solution proposed in https://cookbook.nodered.org/mqtt/subscribe-to-topic where the mqtt topic field is set to $(MY_TOPIC) but it doesn't work.
After some debugging it looks like the variable is never expanded. I have replaced mqtt node with a change node for debugging purposes and it looks like the variable is indeed expanded in this case.
Is this a bug or a feature of the mqtt node?
Is my approach on this issue just wrong?
The environment variables are expanded at deploy time as that is when the configuration of each node is read. They are not dynamically read during execution.
That would be fine. Each subflow instance has a different topic set in the variable and I am not expecting that to change unless I change the flow and re-deploy.
Since it is properly expanded in a change node why isn't it expanded in the topic field of a mqtt node?
This only works if it replaces the entire property - it cannot be used to substitute just part of the value. For example, it is not possible to use CLIENT-${HOST}.
But it seems this is a limitation. In the subflow there are many mqtt subscribe nodes. For example I use Tasmota for esp8266:
stat / ROOM1 / power2
tele / ROOM1 / LWT
stat / ROOM1 / RESULT
tele / ROOM1 / STATE
Can you give me any solution to replace all ROOM1 in all topic mqtt subscribe node
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.
This works fine with Topic, but I can't make it work with the Server.
Added ${MQTT_HOST} in the Server field in a subflow. Added it also in the properties. All exactly as with Topic, but no output. Anyone has an idea?
Dear all NodeRed enthusiastics,
I notified I am not able to use environment variable in another environment variable definition in flow properties similar to example shown above. I don't know why, but the first variable (writen in format ${ID} in next variable definition) is empty string, despite ID variable was defined in special line above definition as string ... Would you be so kind and could you advise me, what I am doing wrong? Thx in advance. Regards, Josef.
You question does not appear to be related to the two year old topic that you added it to, so please start a new topic with at title that matches your problem. When you do that please show exactly what you are doing that does not work, rather than just describing it in words.