Is there a way to make a nested if statement using only by structuring nodes out on the GUI vs. writing js in a function node? How would you do it?
Can you provide an example of what you want to do.
You could use swtich nodes nested, a simple example.
[{"id":"1838876b.1af279","type":"tab","label":"Flow 7","disabled":false,"info":""},{"id":"c892bfe8.cfbf18","type":"switch","z":"1838876b.1af279","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"tall","vt":"str"},{"t":"eq","v":"short","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":480,"y":240,"wires":[["813627ca.52ac1"],["56abe8e3.56dfb8"]]},{"id":"1c9eb799.329c5","type":"function","z":"1838876b.1af279","name":"","func":"msg.options = msg.payload.split(\"\\n\");\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":290,"y":680,"wires":[[]]},{"id":"6ae981ae.b315f8","type":"switch","z":"1838876b.1af279","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":200,"wires":[["4fa89b.6653ff64"],["c892bfe8.cfbf18"]]},{"id":"4fa89b.6653ff64","type":"switch","z":"1838876b.1af279","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"red","vt":"str"},{"t":"eq","v":"blue","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":480,"y":160,"wires":[["97a48419.188d28"],["1d1af41a.f28c5c"]]},{"id":"97a48419.188d28","type":"debug","z":"1838876b.1af279","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":120,"wires":[]},{"id":"1d1af41a.f28c5c","type":"debug","z":"1838876b.1af279","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":180,"wires":[]},{"id":"813627ca.52ac1","type":"debug","z":"1838876b.1af279","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":220,"wires":[]},{"id":"56abe8e3.56dfb8","type":"debug","z":"1838876b.1af279","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":280,"wires":[]},{"id":"32fa4fef.12e18","type":"inject","z":"1838876b.1af279","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"tall","payload":"2","payloadType":"num","x":110,"y":180,"wires":[["6ae981ae.b315f8"]]},{"id":"54728e44.635f1","type":"comment","z":"1838876b.1af279","name":"","info":"1 tall or short -will not pass\n2 red or blue - will not pass","x":180,"y":100,"wires":[]}]
added a and / or example
[{"id":"1838876b.1af279","type":"tab","label":"Flow 7","disabled":false,"info":""},{"id":"c892bfe8.cfbf18","type":"switch","z":"1838876b.1af279","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"tall","vt":"str"},{"t":"eq","v":"short","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":480,"y":240,"wires":[["813627ca.52ac1"],["813627ca.52ac1"]]},{"id":"1c9eb799.329c5","type":"function","z":"1838876b.1af279","name":"","func":"msg.options = msg.payload.split(\"\\n\");\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":290,"y":680,"wires":[[]]},{"id":"6ae981ae.b315f8","type":"switch","z":"1838876b.1af279","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":200,"wires":[["4fa89b.6653ff64"],["c892bfe8.cfbf18"]]},{"id":"4fa89b.6653ff64","type":"switch","z":"1838876b.1af279","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"red","vt":"str"},{"t":"eq","v":"blue","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":480,"y":160,"wires":[["813627ca.52ac1"],["813627ca.52ac1"]]},{"id":"813627ca.52ac1","type":"debug","z":"1838876b.1af279","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":220,"wires":[]},{"id":"32fa4fef.12e18","type":"inject","z":"1838876b.1af279","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"tall","payload":"2","payloadType":"num","x":110,"y":180,"wires":[["6ae981ae.b315f8","d6ccee4f.cf6d6"]]},{"id":"54728e44.635f1","type":"comment","z":"1838876b.1af279","name":"or","info":"","x":190,"y":140,"wires":[]},{"id":"d6ccee4f.cf6d6","type":"switch","z":"1838876b.1af279","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"red","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":200,"y":280,"wires":[["5d7b9b63.83c39c"]]},{"id":"5d7b9b63.83c39c","type":"switch","z":"1838876b.1af279","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"2","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":340,"y":280,"wires":[["813627ca.52ac1"]]},{"id":"2f24968c.1e36e2","type":"comment","z":"1838876b.1af279","name":"and","info":"","x":260,"y":340,"wires":[]}]
I have 2 switches inputting to an XOR node. When a button is pressed I want the state of that XOR to stop/allow the message from the button to proceed.
Not sure what that has to do with nested if. Feed the XOR into a node-red-simple-gate to block or allow the message from the button. Alternatively (possibly better) feed the output of the XOR back to the button, with a change node so as it enables or disables the button.
Oh, maybe I'm wrong. I was looking at it like, IF the button is pressed, IF the XOR is true, etc. I will try the simple gate. Thanks
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.