# Simple gate to switch on and off a flow

**URL:** <https://discourse.nodered.org/t/simple-gate-to-switch-on-and-off-a-flow/24611>\
**Category:** General\
**Created:** [10 April 2020 19:39 UTC](https://discourse.nodered.org/t/simple-gate-to-switch-on-and-off-a-flow/24611 "2020-04-10T19:39:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![volker1078](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/volker1078/32/19735_2.png) [@volker1078](https://discourse.nodered.org/u/volker1078)\
**Post date:** [10 April 2020 19:39 UTC](https://discourse.nodered.org/t/simple-gate-to-switch-on-and-off-a-flow/24611/1 "2020-04-10T19:39:22Z")

</div>

Hi there,  
I found this flow here in the forum:

[https://flows.nodered.org/flow/a985944e789d90e0cd2008d85b7aaa65](https://flows.nodered.org/flow/a985944e789d90e0cd2008d85b7aaa65)

That is almost exactly what I am looking for .... I only need a second output so that the message takes the output "1" or "2" depending on whether the switch is set to "on" or "off".

you can rewrite the code in the gate that it works that way

Greetings Volker

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 April 2020 06:02 UTC](https://discourse.nodered.org/t/simple-gate-to-switch-on-and-off-a-flow/24611/2 "2020-04-11T06:02:39Z")

</div>

Are you asking a question? If so then it is not clear what the question is.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [11 April 2020 06:14 UTC](https://discourse.nodered.org/t/simple-gate-to-switch-on-and-off-a-flow/24611/3 "2020-04-11T06:14:07Z")

</div>

Though slightly different, this flow does what you want - I think.

```auto
[{"id":"562ebf47.7816e","type":"inject","z":"b4f1ccd4.5e8d1","name":"1","topic":"control","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":2910,"wires":[["dfc4d3fa.da9c3"]]},{"id":"362d4e1a.8ac26a","type":"inject","z":"b4f1ccd4.5e8d1","name":"2","topic":"control","payload":"2","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":2950,"wires":[["dfc4d3fa.da9c3"]]},{"id":"dfc4d3fa.da9c3","type":"change","z":"b4f1ccd4.5e8d1","name":"","rules":[{"t":"set","p":"router","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":2930,"wires":[[]]},{"id":"e8c699c1.7bd3d","type":"inject","z":"b4f1ccd4.5e8d1","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":3070,"wires":[["f57f5c83.093b4"]]},{"id":"f57f5c83.093b4","type":"switch","z":"b4f1ccd4.5e8d1","name":"","property":"router","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":400,"y":3070,"wires":[["6eea1b84.8be9ac"],["a2c95c56.ee0cd"]]},{"id":"6eea1b84.8be9ac","type":"debug","z":"b4f1ccd4.5e8d1","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":550,"y":3030,"wires":[]},{"id":"a2c95c56.ee0cd","type":"debug","z":"b4f1ccd4.5e8d1","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":550,"y":3100,"wires":[]}]

```

It won't do anything until you press the `1` or `2` button (`inject` node)

BONUS!

If you add a third `inject` node to where the `1` and `2` are, and make it..... (anything else):  
When you press that _button_ the output will stop.

(Looking at your "picture".... You _love it when a plan comes together_ - yes?)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 June 2020 06:14 UTC](https://discourse.nodered.org/t/simple-gate-to-switch-on-and-off-a-flow/24611/4 "2020-06-10T06:14:08Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
