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

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.

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.

[{"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":[]}]
1 Like

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.
image

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 !

Definitely visually cleaner.

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.

[{"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":[]}]
1 Like

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.

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

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

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.

Or do the same with standard nodes no messy wires

[{"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":[]}]

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

[{"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

2 Likes

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.

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.

You can set the defaults however you like.

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.

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

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.

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.)

Wrapped in a subflow multiple instances

[{"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.

1 Like