Node for switching flow on and off

#1

Hi,

Have been searching for days now but can't seem to find a node that fits my needs. So I am about to write a function instead. But then I thought that I can't be the only one in need of this function. So is there node that I cant find that works like this:

Two inputs, one output.
The first input is simply for switching the flow on and off.
The second input just passes the message through to the output.

So for example if a message is sent to the first input with payload "off" then all messages to the second input will be dropped, until a message sent to the first input with payload "on". Then all messages will be just passed on to the output.

0 Likes

#2

Have one flow that sets a context variable with the on/off

Have a switch in the second flow that checks the context variable

1 Like

#3

This recipe in the cookbook shows how you can do that with a Change and Switch node using context

(edit: just as @ukmoose suggests)

https://cookbook.nodered.org/basic/route-on-context

1 Like

#4

Thanks!

That is what I'm writing in a function right now. And of course I could use both your examples instead.
Just thought it would be more intuitive with the node I tried to describe.

0 Likes

#5

There are contrib nodes already - such as the simple-gate node that do a similar thing. Personally I think the approach with the core nodes is simple enough.

The key thing to remember is nodes only have one input.

1 Like

#6

Ok. I thought you could write nodes with more than one input, just like outputs. That explains why I was not able to find one.

The node you suggested is exactly what I am trying to write my on function for.

Thanks a lot. I will see which I end up using.

0 Likes