Hello everyone.
I'm a newbie in Node Red / Hass, and I'm trying to create a sequence that can be easily duplicable and editable. This sequence interacts with two devices and makes them change together (when device 1 is activated, this sequence activates device 2, and vice versa), and it needs a "bypass" variable (I'll use a flow variable for this) that prevents it from starting an unneccessary loop.
My intention is to be able to duplicate this sequence for each group I want to create, and I would prefer it to be easily editable. Every time I duplicate it, I will set a new group name, and I want do do this by editing the first two nodes only, instead of needing to edit each change/switch node inside with the new variable name. In these first two nodes, I'll set the name of this bypass variable in the msg.bypassVar message. For the first one I'm testing, the bypass variable will be called laundryLightBypass.
These are the output properties of one of the first state nodes that trigger the sequence.
As you can see, there's a msg.bypassVar that contains the string laundryLightBypass. I want another node after this to get that variable name from the msg.bypassBar variable.
I was able to do similar things before with device names by using double mustache brackets (in a totally different flow):
And also today I learnt to make the Switch node grab the variable name from msg.bypassVar with a json expression:
This node reacts to the content of flow.laundryLightBypass even though that name is not written inside the node, but comes in the ypassVar message. First, I was trying to use the same double brackets that worked for other situations, but that didn't work, so I found some help in the forums and this was the successful result.
This last thing helped me make the Switch node work the way I intended, but I still need a way to make the Change node get the variable name from the msg.bypassVar, which ideally would work from something like this:
And I'm also open to try a function node, but I don't know how to write a function that does this. I imagine something like this, but I haven't found a way to make it work yet:
flow.set('(bypassVar)', true);
return msg;
So, I'll be thankful to anyone who could point me in any direction! I'm eager to learn
Thanks,
Rodrigo