If-set-else-set node

Hello there,
sorry for such easy question, probably I missed something, but I can't find a node for following thing.

I have system (Loxone) which feeds by flow by some values, for example "0" and "1" as a state of the button. And I need to convert these 0/1 to "on" / "off" string values and pass it as MQTT value to Zigbee2Mqtt system.

So, I can create "function" block and code this simple function in JS. Something like

if input=0 then output="off"
else if input="1" then output="on"
else ....

But because this will be used on several places, I would like to use some pre-build node. Is there something for this?

Because I can use "switch" block but then I have to also use some two other blocks (probably change") to modify the payload for the correct value.

But I would like to use only one element to do this thing. It's very inconvenient to create three nodes for every transformation. I would like to see something like this:

Where "TRANSFORM" node is a combination of switch and change node.

Is there any way how to do that?


I think what you need is a subflow.

Select the nodes to be "reused" then "selection to subflow"...


Then you can have multiple instances of the subflow.

This might be of some help...

1 Like

Thanks for the reply. I'm aware of the subflows, but I believed that such a basic feature has to be already implemented as a node.

It not, I will use subflows exactly as you mention.

Yes the change node.

1 Like

Im not certain what you really want. I suspected a subflow was what you wanted.

Alternatively, there is a node that operates like a subroutine - it is called node-red-contrib-components - perhaps that might be preferable?

1 Like

Thank you! This is exactly what I looking for.

I didn't know I can use change node in this way. Thank you.

This is also interesting for more complex tasks. Thanks!

Take a look at JSONata expressions to, It is very powerfull.

1 Like