# A handy way for testing different ways of doing something in your flows

**URL:** https://discourse.nodered.org/t/a-handy-way-for-testing-different-ways-of-doing-something-in-your-flows/54724
**Category:** Share Your Projects
**Created:** [5 December 2021 00:23 UTC](https://discourse.nodered.org/t/a-handy-way-for-testing-different-ways-of-doing-something-in-your-flows/54724 "2021-12-05T00:23:45Z")
**Posts on this page:** 13
**Page:** 1

<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: [5 December 2021 00:23 UTC](https://discourse.nodered.org/t/a-handy-way-for-testing-different-ways-of-doing-something-in-your-flows/54724/1 "2021-12-05T00:23:45Z")

</div>

If you are only clawing your way through node-red and are open to trying different ways to get something done, this maybe handy for you.

 ![Screenshot from 2021-12-05 11-25-39](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/3/934d5fef9833eb5913d9d53c991547481feae5a0.png)

Here you can see how I have one _incoming message_ and you are not sure which code (connected where the `debug` nodes are) will work best for you.

(Given you have all 4 versions of the code in the flow. And `4` is nominal only to show it is flexible with how many can be done/used.)

The `4` inject` nodes at the top select where the message goes.  
Only 1 _output_ is active at any time.

So you can have the different ways of doing what you are testing and switch which bit of the code is used.

Real handy if you are trying more than 1 way of getting something done.  
I would suggest you use `link` nodes on the input and multiple outputs to go to the various parts of the code. As having all the alternatives **there** may become a bit cluttered and confusing.  
Maybe even on separate tabs during the initial testing.

# EXTERNAL NODE NEEDED!

`node-red-contrib-simple-gate`

Of course when all is done, you will delete the other nodes and this part of it too.  
But it is handy and makes it easier to switch between different ways without needing to deploy.

I know that you are editing things and so it is a given that you will `deploy`.  
But I have been caught a few times when I haven't re-wired to the bit of code on which I am working and so have to re-deploy again.

It isn't rocket science and could be made into a subflow easily enough.  
(Which could be done but it is a bit more mucking about because of the `inject` nodes)  
Here it is simple and you can easily control where messages are going during testing.

Hope it helps someone.

```auto
[{"id":"0920c79d3c937bfd","type":"inject","z":"e089622.6a906a","name":"ON","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"open","payloadType":"str","x":320,"y":1120,"wires":[["eddec65d7bd49d3d","b83361418671bdea"]]},{"id":"eddec65d7bd49d3d","type":"change","z":"e089622.6a906a","name":"OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":1120,"wires":[["aac3da4f81ed1491","1c815229de707473","e5045037e386432a"]]},{"id":"3655c402f0cac406","type":"inject","z":"e089622.6a906a","name":"ON","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"open","payloadType":"str","x":320,"y":1160,"wires":[["bf5803d5a37bbf7a","aac3da4f81ed1491"]]},{"id":"bf5803d5a37bbf7a","type":"change","z":"e089622.6a906a","name":"OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":1160,"wires":[["b83361418671bdea","1c815229de707473","e5045037e386432a"]]},{"id":"0ccb89b56be09826","type":"inject","z":"e089622.6a906a","name":"ON","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"open","payloadType":"str","x":320,"y":1200,"wires":[["b4dfb7dc5d7ff7ad","1c815229de707473"]]},{"id":"b4dfb7dc5d7ff7ad","type":"change","z":"e089622.6a906a","name":"OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":1200,"wires":[["b83361418671bdea","aac3da4f81ed1491","e5045037e386432a"]]},{"id":"d88f30cdbb2d6d48","type":"inject","z":"e089622.6a906a","name":"ON","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"open","payloadType":"str","x":320,"y":1240,"wires":[["2e83c7b57742c990","e5045037e386432a"]]},{"id":"2e83c7b57742c990","type":"change","z":"e089622.6a906a","name":"OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":1240,"wires":[["1c815229de707473","aac3da4f81ed1491","b83361418671bdea"]]},{"id":"b83361418671bdea","type":"gate","z":"e089622.6a906a","name":"","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":500,"y":1290,"wires":[["d7041a4fc93d304b"]]},{"id":"aac3da4f81ed1491","type":"gate","z":"e089622.6a906a","name":"","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":500,"y":1330,"wires":[["d4cc5ef8d7767e3a"]]},{"id":"1c815229de707473","type":"gate","z":"e089622.6a906a","name":"","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":500,"y":1370,"wires":[["42b2069c39229406"]]},{"id":"e5045037e386432a","type":"gate","z":"e089622.6a906a","name":"","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":500,"y":1410,"wires":[["ef485e68644a06f9"]]},{"id":"59e0f09f57b01661","type":"inject","z":"e089622.6a906a","name":"Incoming message","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":280,"y":1360,"wires":[["b83361418671bdea","aac3da4f81ed1491","1c815229de707473","e5045037e386432a"]]},{"id":"d7041a4fc93d304b","type":"debug","z":"e089622.6a906a","name":"To option 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":1290,"wires":[]},{"id":"d4cc5ef8d7767e3a","type":"debug","z":"e089622.6a906a","name":"To option 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":1330,"wires":[]},{"id":"42b2069c39229406","type":"debug","z":"e089622.6a906a","name":"To option 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":1370,"wires":[]},{"id":"ef485e68644a06f9","type":"debug","z":"e089622.6a906a","name":"To option 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":1410,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![Jean-Luc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jean-luc/32/89996_2.png) [@Jean-Luc](https://discourse.nodered.org/u/Jean-Luc)
#### Post date: [6 December 2021 12:31 UTC](https://discourse.nodered.org/t/a-handy-way-for-testing-different-ways-of-doing-something-in-your-flows/54724/2 "2021-12-06T12:31:04Z")

</div>

I just tried it with the provided demo, it's looks pretty much like a node I use a lot which is named [node-red-contrib-traffic](https://flows.nodered.org/node/node-red-contrib-traffic).  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/f/ff9c4543a5d660fa7d9789cf5206e9ccd76d6f31.png)

The node-red-contrib-simple-gate node seems more granular in the possible actions.  
I will analyze the use of the first one vis-avis the second one.  
Thanks for sharing !

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [6 December 2021 19:07 UTC](https://discourse.nodered.org/t/a-handy-way-for-testing-different-ways-of-doing-something-in-your-flows/54724/3 "2021-12-06T19:07:08Z")

</div>

> [@Trying\_to\_learn](#):
>
> use `link` nodes

Definitely visually cleaner.

 ![Screenshot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/9/99fda1521f6923cad6c0eda633cf1d5a7b43b6bf.jpeg)

Also, logically a bit tighter, although you have to ignore the warnings. Perhaps it would be good to have an option to suppress the warnings for uses like this.

```auto
[{"id":"1ffc9bbb08552d04","type":"gate","z":"7b70bf3ccc9b1efa","name":"","controlTopic":"control","defaultState":"open","openCmd":"open1","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"memoryOnly","x":470,"y":260,"wires":[["0a5b8c19ba0fcc8a"]]},{"id":"17c46c6a6535a1b8","type":"gate","z":"7b70bf3ccc9b1efa","name":"","controlTopic":"control","defaultState":"open","openCmd":"open2","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"memoryOnly","x":470,"y":320,"wires":[["692b0679192eb19b"]]},{"id":"fd4d38baa2c530c1","type":"gate","z":"7b70bf3ccc9b1efa","name":"","controlTopic":"control","defaultState":"open","openCmd":"open3","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"memoryOnly","x":470,"y":380,"wires":[["c3fae2f0730f4642"]]},{"id":"afad83419cba4c4b","type":"gate","z":"7b70bf3ccc9b1efa","name":"","controlTopic":"control","defaultState":"open","openCmd":"open4","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"memoryOnly","x":470,"y":440,"wires":[["6392e55df30efb9b"]]},{"id":"5ce08cc87cec016e","type":"inject","z":"7b70bf3ccc9b1efa","name":"1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"open1","payloadType":"str","x":230,"y":100,"wires":[["f3ceb6fbd35edf47"]]},{"id":"f3ceb6fbd35edf47","type":"function","z":"7b70bf3ccc9b1efa","name":"","func":"let msg0 = {payload:'close', topic:'control'}\nnode.send (msg0)\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":160,"wires":[["373985c65f543143"]]},{"id":"e953f0eb5e705a34","type":"inject","z":"7b70bf3ccc9b1efa","name":"2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"open2","payloadType":"str","x":230,"y":140,"wires":[["f3ceb6fbd35edf47"]]},{"id":"c4c7130f5540f3a1","type":"inject","z":"7b70bf3ccc9b1efa","name":"3","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"open3","payloadType":"str","x":230,"y":180,"wires":[["f3ceb6fbd35edf47"]]},{"id":"082260d87c0be51b","type":"inject","z":"7b70bf3ccc9b1efa","name":"4","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"open4","payloadType":"str","x":230,"y":220,"wires":[["f3ceb6fbd35edf47"]]},{"id":"0a5b8c19ba0fcc8a","type":"debug","z":"7b70bf3ccc9b1efa","name":"To option 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":260,"wires":[]},{"id":"692b0679192eb19b","type":"debug","z":"7b70bf3ccc9b1efa","name":"To option 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":320,"wires":[]},{"id":"c3fae2f0730f4642","type":"debug","z":"7b70bf3ccc9b1efa","name":"To option 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":380,"wires":[]},{"id":"6392e55df30efb9b","type":"debug","z":"7b70bf3ccc9b1efa","name":"To option 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":440,"wires":[]},{"id":"1226459e1a7d6acc","type":"inject","z":"7b70bf3ccc9b1efa","name":"Incoming message","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":190,"y":260,"wires":[["373985c65f543143"]]},{"id":"cdef125c1307bf15","type":"link in","z":"7b70bf3ccc9b1efa","name":"","links":["373985c65f543143"],"x":315,"y":340,"wires":[["1ffc9bbb08552d04","17c46c6a6535a1b8","fd4d38baa2c530c1","afad83419cba4c4b"]]},{"id":"373985c65f543143","type":"link out","z":"7b70bf3ccc9b1efa","name":"","mode":"link","links":["cdef125c1307bf15"],"x":555,"y":160,"wires":[]}]

```

---

<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: [6 December 2021 19:49 UTC](https://discourse.nodered.org/t/a-handy-way-for-testing-different-ways-of-doing-something-in-your-flows/54724/4 "2021-12-06T19:49:07Z")

</div>

I used to use `traffic` but the gate I used in this case seemed nicer and had more features at the time.

`traffic` was (then) very basic where as the `gate` wasn't.

---

<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: [6 December 2021 19:51 UTC](https://discourse.nodered.org/t/a-handy-way-for-testing-different-ways-of-doing-something-in-your-flows/54724/5 "2021-12-06T19:51:26Z")

</div>

Um, when I import that code, it is the same as what I posted.

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [6 December 2021 20:11 UTC](https://discourse.nodered.org/t/a-handy-way-for-testing-different-ways-of-doing-something-in-your-flows/54724/6 "2021-12-06T20:11:08Z")

</div>

Sorry. Cut but didn't paste. Corrected in my earlier post.

---

<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: [6 December 2021 20:17 UTC](https://discourse.nodered.org/t/a-handy-way-for-testing-different-ways-of-doing-something-in-your-flows/54724/7 "2021-12-06T20:17:24Z")

</div>

Ok.

Don't know what to say. All those warnings would complicate things if you are debugging (or testing) other code.

What I posted is a _tool_ for people to use if they are trying/comparing different things to see what is what with the different nodes.

And.... your code has all the gates open by default. closed would be better.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [6 December 2021 21:10 UTC](https://discourse.nodered.org/t/a-handy-way-for-testing-different-ways-of-doing-something-in-your-flows/54724/8 "2021-12-06T21:10:28Z")

</div>

Or do the same with standard nodes no messy wires

```auto
[{"id":"0920c79d3c937bfd","type":"inject","z":"88fadd65b9040724","name":"Toggle 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control1","payload":"toggle","payloadType":"str","x":220,"y":1860,"wires":[["94cb46ef.780c98"]]},{"id":"94cb46ef.780c98","type":"function","z":"88fadd65b9040724","name":"set gate context","func":"let gate_bools = flow.get(\"gate\") || {[msg.topic]:false}\ngate_bools[msg.topic] = gate_bools[msg.topic] ? false : true\nflow.set(\"gate.\" + msg.topic, gate_bools[msg.topic])\nlet fill = Object.values(gate_bools).find(e => e) ? \"green\" : \"red\";\nlet text = Object.entries(gate_bools).map(e => (e[1] ? e[0][e[0].length-1] : \"\")).sort().join(\" \") \nnode.status({fill,shape:\"dot\",text});\nreturn null;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":460,"y":1920,"wires":[[]]},{"id":"3655c402f0cac406","type":"inject","z":"88fadd65b9040724","name":"Toggle 2","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control2","x":220,"y":1900,"wires":[["94cb46ef.780c98"]]},{"id":"0ccb89b56be09826","type":"inject","z":"88fadd65b9040724","name":"Toggle 3","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control3","x":220,"y":1940,"wires":[["94cb46ef.780c98"]]},{"id":"d88f30cdbb2d6d48","type":"inject","z":"88fadd65b9040724","name":"Toggle","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control4","x":220,"y":1980,"wires":[["94cb46ef.780c98"]]},{"id":"59e0f09f57b01661","type":"inject","z":"88fadd65b9040724","name":"Incoming msg","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":290,"y":2100,"wires":[["909ebc8f.81dbc8"]]},{"id":"909ebc8f.81dbc8","type":"switch","z":"88fadd65b9040724","name":"","property":"payload","propertyType":"msg","rules":[{"t":"jsonata_exp","v":"$flowContext(\"gate.control1\")","vt":"jsonata"},{"t":"jsonata_exp","v":"$flowContext(\"gate.control2\")","vt":"jsonata"},{"t":"jsonata_exp","v":"$flowContext(\"gate.control3\")","vt":"jsonata"},{"t":"jsonata_exp","v":"$flowContext(\"gate.control4\")","vt":"jsonata"}],"checkall":"true","repair":false,"outputs":4,"x":475,"y":2100,"wires":[["d7041a4fc93d304b"],["d4cc5ef8d7767e3a"],["42b2069c39229406"],["ef485e68644a06f9"]],"l":false},{"id":"d4cc5ef8d7767e3a","type":"debug","z":"88fadd65b9040724","name":"To option 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":2090,"wires":[]},{"id":"d7041a4fc93d304b","type":"debug","z":"88fadd65b9040724","name":"To option 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":2050,"wires":[]},{"id":"42b2069c39229406","type":"debug","z":"88fadd65b9040724","name":"To option 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":2130,"wires":[]},{"id":"ef485e68644a06f9","type":"debug","z":"88fadd65b9040724","name":"To option 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":2170,"wires":[]}]

```

 ![Screenshot_20211206-210957](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/4/04117b3e753dee33b4e62466455776e9f1845b6c.png)

[edit]  
or use a function node instead of a switch

```auto
[{"id":"59e0f09f57b01661","type":"inject","z":"88fadd65b9040724","name":"Incoming msg","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":290,"y":2100,"wires":[["5b210de6.349b4c"]]},{"id":"5b210de6.349b4c","type":"function","z":"88fadd65b9040724","name":"","func":"let msg1 = [null,null,null,null];\nlet gate_bools = flow.get(\"gate\") || {};\nlet bool_keys = Object.keys(gate_bools).reduce((a,e) => gate_bools[e] ? a.concat(e.substr(-1)-1) : a ,[]).sort();\nlet fill = Object.values(gate_bools).find(e => e) ? \"green\" : \"red\";\nlet text = Object.entries(gate_bools).map(e => (e[1] ? e[0][e[0].length-1] : \"\")).sort().join(\" \") \nnode.status({fill,shape:\"dot\",text});//node.warn(bool_keys);\nbool_keys.forEach(e => msg1[e] = msg);\nreturn msg1;","outputs":4,"noerr":0,"initialize":"","finalize":"","x":455,"y":2100,"wires":[["d7041a4fc93d304b"],["d4cc5ef8d7767e3a"],["42b2069c39229406"],["ef485e68644a06f9"]],"l":false},{"id":"d7041a4fc93d304b","type":"debug","z":"88fadd65b9040724","name":"To option 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":2050,"wires":[]},{"id":"d4cc5ef8d7767e3a","type":"debug","z":"88fadd65b9040724","name":"To option 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":2090,"wires":[]},{"id":"42b2069c39229406","type":"debug","z":"88fadd65b9040724","name":"To option 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":2130,"wires":[]},{"id":"ef485e68644a06f9","type":"debug","z":"88fadd65b9040724","name":"To option 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":2170,"wires":[]}]

```

[edit] fixed function to add status

---

<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: [6 December 2021 21:15 UTC](https://discourse.nodered.org/t/a-handy-way-for-testing-different-ways-of-doing-something-in-your-flows/54724/9 "2021-12-06T21:15:11Z")

</div>

Yeah, that is cute.

I guess I got stuck in the mind set of using gates to control things.

The use of a `switch` node controlled by flow.context is sneaky. Top marks for thinking of it.

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [6 December 2021 23:30 UTC](https://discourse.nodered.org/t/a-handy-way-for-testing-different-ways-of-doing-something-in-your-flows/54724/10 "2021-12-06T23:30:09Z")

</div>

> [@Trying\_to\_learn](#):
>
> those warnings would complicate things

This use case is not one I expected when I developed the node, but as I said, it would be easy to suppress the warnings if there were enough interest.

> [@Trying\_to\_learn](#):
>
> all the gates open by default

You can set the defaults however you like.

> [@E1cid](#):
>
> no messy wires

True enough. Fundamentally, the difference is whether the state is being stored locally in the node context or distributed more widely in the flow context. To me, it's a matter of taste, except for questions of scaling. When many instances are needed, it can become cumbersome and error-prone to define many distinct flow variables and to keep track of where they are defined or used.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [6 December 2021 23:56 UTC](https://discourse.nodered.org/t/a-handy-way-for-testing-different-ways-of-doing-something-in-your-flows/54724/11 "2021-12-06T23:56:25Z")

</div>

> [@drmibell](#):
>
> stored locally in the node context or distributed more widely in the flow context.

I see very little difference. it writes to memory/ file on the same device.

> [@drmibell](#):
>
> When many instances are needed, it can become cumbersome and error-prone to define many distinct flow variables and to keep track of where they are defined or used.

And this is not cumbersome and error prone , multiple gate nodes need configuring.  
While the flow variables define them selves just add a new topic (this area needs refining as I would probably change the the indexing there), then add another output via copy and past. You could possible wrap it up in a nice subflow for multiple instances.

All the gate values are in one place in a context object called gate.

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [7 December 2021 21:02 UTC](https://discourse.nodered.org/t/a-handy-way-for-testing-different-ways-of-doing-something-in-your-flows/54724/12 "2021-12-07T21:02:46Z")

</div>

> [@E1cid](#):
>
> And this is not cumbersome and error prone , multiple gate nodes need configuring.

I'm not quite sure what you mean here. If you copy and paste multiple instances of the flow I proposed, each instance will be independent of the others and fully functional with no further editing. Do he same with flows based on context variables, and careful editing or clever definition is needed to avoid errors. (I admit, "cumbersome" may be too strong a word for the code in your function node, but it really would not be obvious to an inexperienced user who might prefer a no-code solution.)

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [7 December 2021 22:14 UTC](https://discourse.nodered.org/t/a-handy-way-for-testing-different-ways-of-doing-something-in-your-flows/54724/13 "2021-12-07T22:14:49Z")

</div>

Wrapped in a subflow multiple instances

```auto
[{"id":"d159acc6.ca319","type":"subflow","name":"Router","info":"Name the subflow, each subflow name must be unique.\nSelect the starting default state.\nThe default topic will be the vale you set msg.topic to. The defaulty topic does not have a integer on end. \nThe msg. topic must be the deault topic value plus a integer od 1-4","category":"","in":[{"x":160,"y":140,"wires":[{"id":"d7abe51d.14958"}]}],"out":[{"x":520,"y":40,"wires":[{"id":"d7abe51d.14958","port":1}]},{"x":460,"y":80,"wires":[{"id":"d7abe51d.14958","port":2}]},{"x":520,"y":100,"wires":[{"id":"d7abe51d.14958","port":3}]},{"x":460,"y":140,"wires":[{"id":"d7abe51d.14958","port":4}]}],"env":[{"name":"name","type":"str","value":"alpha","ui":{"label":{"en-US":"Name"},"type":"input","opts":{"types":["str"]}}},{"name":"default_state","type":"str","value":"0","ui":{"label":{"en-US":"Default state"},"type":"select","opts":{"opts":[{"l":{"en-US":"Closed"},"v":"0"},{"l":{"en-US":"Open"},"v":"1"}]}}},{"name":"control_topic","type":"str","value":"control","ui":{"label":{"en-US":"Control Topic"},"type":"input","opts":{"types":["str"]}}}],"color":"#DDAA99","status":{"x":460,"y":20,"wires":[{"id":"d7abe51d.14958","port":0}]}},{"id":"d7abe51d.14958","type":"function","z":"d159acc6.ca319","name":"","func":"let msg1 = [null,null,null,null,null];\nlet name = env.get(\"name\");\nlet control = env.get(\"control_topic\") || \"control\";\nlet default_state = (env.get(\"default_state\") || \"0\") == 1 ? true : false;\nlet default_object = {[`${control}1`]:default_state,[`${control}2`]:default_state,[`${control}3`]:default_state,[`${control}4`]:default_state};\nlet gate_bools = global.get(\"gate.\" + name) || default_object;\nif(msg.topic.substr(0,msg.topic.length-1) === control){\n gate_bools[msg.topic] = gate_bools[msg.topic] ? false : true;\n gate_bools = msg.reset ? default_object : gate_bools;\n}else{\n Object.keys(gate_bools).reduce((a,e) => gate_bools[e] ? a.concat(e.substr(-1)) : a ,[]).sort().forEach(e => msg1[e] = msg);\n}\nglobal.set(\"gate.\" + name, gate_bools);\nlet fill = Object.values(gate_bools).find(e => e) ? \"green\" : \"red\";\nlet text = Object.entries(gate_bools).map(e => (e[1] ? e[0].substr(-1) : \"\")).sort().join(\" \") \nmsg1[0] = {status: {fill,shape:\"dot\",text}};\nreturn msg1;","outputs":5,"noerr":0,"initialize":"","finalize":"","x":335,"y":140,"wires":[[],[],[],[],[]],"l":false},{"id":"f57f6cba.9d09a","type":"inject","z":"88fadd65b9040724","name":"Reset all to default","props":[{"p":"reset","v":"true","vt":"bool"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control1","x":270,"y":1820,"wires":[["96d6ba1a.970b1"]]},{"id":"96d6ba1a.970b1","type":"subflow:d159acc6.ca319","z":"88fadd65b9040724","name":"router","env":[],"x":410,"y":1940,"wires":[["d7041a4fc93d304b"],["d4cc5ef8d7767e3a"],["42b2069c39229406"],["ef485e68644a06f9"]]},{"id":"0920c79d3c937bfd","type":"inject","z":"88fadd65b9040724","name":"Toggle 1","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control1","x":220,"y":1860,"wires":[["96d6ba1a.970b1"]]},{"id":"3655c402f0cac406","type":"inject","z":"88fadd65b9040724","name":"Toggle 2","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control2","x":220,"y":1900,"wires":[["96d6ba1a.970b1"]]},{"id":"0ccb89b56be09826","type":"inject","z":"88fadd65b9040724","name":"Toggle 3","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control3","x":220,"y":1940,"wires":[["96d6ba1a.970b1"]]},{"id":"d88f30cdbb2d6d48","type":"inject","z":"88fadd65b9040724","name":"Toggle 4","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control4","payloadType":"str","x":220,"y":1980,"wires":[["96d6ba1a.970b1"]]},{"id":"59e0f09f57b01661","type":"inject","z":"88fadd65b9040724","name":"Incoming msg","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":2020,"wires":[["96d6ba1a.970b1"]]},{"id":"d7041a4fc93d304b","type":"debug","z":"88fadd65b9040724","name":"To option 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":2020,"wires":[]},{"id":"d4cc5ef8d7767e3a","type":"debug","z":"88fadd65b9040724","name":"To option 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":2090,"wires":[]},{"id":"42b2069c39229406","type":"debug","z":"88fadd65b9040724","name":"To option 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":2130,"wires":[]},{"id":"ef485e68644a06f9","type":"debug","z":"88fadd65b9040724","name":"To option 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":2170,"wires":[]}]

```

Just give each subflow a name.  
Or anyone can choose to do it however they wish

[Edit] added default starting state and a msg.topic control input value.
