# Node for switching flow on and off

**URL:** <https://discourse.nodered.org/t/node-for-switching-flow-on-and-off/8431>\
**Category:** General\
**Created:** [27 February 2019 08:49 UTC](https://discourse.nodered.org/t/node-for-switching-flow-on-and-off/8431 "2019-02-27T08:49:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![strixx](https://avatars.discourse-cdn.com/v4/letter/s/a6a055/32.png) [@strixx](https://discourse.nodered.org/u/strixx)\
**Post date:** [27 February 2019 08:49 UTC](https://discourse.nodered.org/t/node-for-switching-flow-on-and-off/8431/1 "2019-02-27T08:49:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [27 February 2019 08:51 UTC](https://discourse.nodered.org/t/node-for-switching-flow-on-and-off/8431/2 "2019-02-27T08:51:31Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [27 February 2019 08:52 UTC](https://discourse.nodered.org/t/node-for-switching-flow-on-and-off/8431/3 "2019-02-27T08:52:32Z")

</div>

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](https://cookbook.nodered.org/basic/route-on-context)

---

<div class="post-metadata">

**Author:** ![strixx](https://avatars.discourse-cdn.com/v4/letter/s/a6a055/32.png) [@strixx](https://discourse.nodered.org/u/strixx)\
**Post date:** [27 February 2019 08:55 UTC](https://discourse.nodered.org/t/node-for-switching-flow-on-and-off/8431/4 "2019-02-27T08:55:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [27 February 2019 08:58 UTC](https://discourse.nodered.org/t/node-for-switching-flow-on-and-off/8431/5 "2019-02-27T08:58:46Z")

</div>

There are contrib nodes already - such as the [simple-gate node](https://flows.nodered.org/node/node-red-contrib-simple-gate) 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.

---

<div class="post-metadata">

**Author:** ![strixx](https://avatars.discourse-cdn.com/v4/letter/s/a6a055/32.png) [@strixx](https://discourse.nodered.org/u/strixx)\
**Post date:** [27 February 2019 09:02 UTC](https://discourse.nodered.org/t/node-for-switching-flow-on-and-off/8431/6 "2019-02-27T09:02:44Z")

</div>

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.
