Mutual exclusion with switch node

#1

Dears,

I want to use switch node do mutual exclusion on lighting(light A is on-- light B is off, light B is on--light A is off). However I don't know how to implement it with switch node.

light-a

BR,
Chris

0 Likes

#2

Think through the logic first:

When lightA changes:

if (lightA === true) lightB = false;

When lightB changes:

if (lightB === true) lightA = false;

0 Likes

#3
[{"id":"90b02a78.a31118","type":"ui_switch","z":"75be3680.18cac8","name":"","label":"LIGHT A","group":"ac2c8e97.2a413","order":0,"width":0,"height":0,"passthru":false,"decouple":"false","topic":"","style":"","onvalue":"1","onvalueType":"str","onicon":"","oncolor":"","offvalue":"0","offvalueType":"str","officon":"","offcolor":"","x":310,"y":540,"wires":[["a9df4ef9.64f4d","e96d6ba1.6ed668"]]},{"id":"2ee42378.c35cbc","type":"ui_switch","z":"75be3680.18cac8","name":"","label":"LIGHT B","group":"ac2c8e97.2a413","order":0,"width":0,"height":0,"passthru":false,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"str","onicon":"","oncolor":"","offvalue":"false","offvalueType":"str","officon":"","offcolor":"","x":300,"y":600,"wires":[["f9454df0.6fddb","e96d6ba1.6ed668"]]},{"id":"e96d6ba1.6ed668","type":"debug","z":"75be3680.18cac8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":750,"y":580,"wires":[]},{"id":"a9df4ef9.64f4d","type":"change","z":"75be3680.18cac8","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"str","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":540,"wires":[["2ee42378.c35cbc"]]},{"id":"f9454df0.6fddb","type":"change","z":"75be3680.18cac8","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"str","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":600,"wires":[["90b02a78.a31118"]]},{"id":"ac2c8e97.2a413","type":"ui_group","z":"","name":"test","tab":"d92ab4b4.55f5c8","order":3,"disp":true,"width":"7","collapse":true},{"id":"d92ab4b4.55f5c8","type":"ui_tab","z":"","name":"test","icon":"fa-television","order":2}]
0 Likes

#4

Thanks. I see. Below is my flow with function node + switch node to implement.

[{"id":"b888eb90.f58e38","type":"ui_switch","z":"2c2fe5ba.c6ea6a","name":"","label":"light A","group":"db50e537.4096e8","order":0,"width":0,"height":0,"passthru":false,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":240,"y":200,"wires":[["51a8b614.842668","2cf2dca9.827404"]]},{"id":"52b5570b.29f958","type":"ui_switch","z":"2c2fe5ba.c6ea6a","name":"","label":"light B","group":"db50e537.4096e8","order":0,"width":0,"height":0,"passthru":false,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":240,"y":260,"wires":[["61e58da7.1ba524","f7d3d7dc.2f6218"]]},{"id":"51a8b614.842668","type":"function","z":"2c2fe5ba.c6ea6a","name":"change payload","func":"if (msg.payload===true)\n msg.payload=false;\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":200,"wires":[["52b5570b.29f958"]]},{"id":"61e58da7.1ba524","type":"function","z":"2c2fe5ba.c6ea6a","name":"change payload","func":"if (msg.payload===true)\n msg.payload=false;\nreturn msg;","outputs":1,"noerr":0,"x":460,"y":260,"wires":[["b888eb90.f58e38"]]},{"id":"2cf2dca9.827404","type":"debug","z":"2c2fe5ba.c6ea6a","name":"light A","active":true,"console":"false","complete":"payload","x":590,"y":140,"wires":[]},{"id":"f7d3d7dc.2f6218","type":"debug","z":"2c2fe5ba.c6ea6a","name":"light B","active":true,"console":"false","complete":"payload","x":590,"y":300,"wires":[]},{"id":"db50e537.4096e8","type":"ui_group","z":"","name":"Light","tab":"5167dfe6.e7d11","order":1,"disp":true,"width":"6"},{"id":"5167dfe6.e7d11","type":"ui_tab","z":"","name":"Dashboard","icon":"dashboard"}]

0 Likes

#5

Thanks david. It's good way.

0 Likes

#6

I took your code and changed it slightly. It eliminates the use of the function node, which makes it easier to read. And it is really mutually exclusive now. You can click on any of the two buttons in the dashboard, and the other button changes its state too.
Does this fit your need?

[{"id":"637be1ab.fff2","type":"ui_switch","z":"8a8860c2.8bae6","name":"","label":"light A","group":"c5de6ddc.866bf8","order":0,"width":0,"height":0,"passthru":false,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":470,"y":180,"wires":[["6a3c6e42.e32188","1c14f263.cfaf16"]]},{"id":"c12c290e.94e26","type":"ui_switch","z":"8a8860c2.8bae6","name":"","label":"light B","group":"c5de6ddc.866bf8","order":0,"width":0,"height":0,"passthru":false,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":470,"y":340,"wires":[["b8443192.103cc8","730ad674.c7504"]]},{"id":"6a3c6e42.e32188","type":"debug","z":"8a8860c2.8bae6","name":"light A","active":true,"console":"false","complete":"payload","x":620,"y":180,"wires":[]},{"id":"b8443192.103cc8","type":"debug","z":"8a8860c2.8bae6","name":"light B","active":true,"console":"false","complete":"payload","x":630,"y":340,"wires":[]},{"id":"1c14f263.cfaf16","type":"switch","z":"8a8860c2.8bae6","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":190,"y":340,"wires":[["916170a3.459168"],["6d1526ac.53c11"]]},{"id":"916170a3.459168","type":"change","z":"8a8860c2.8bae6","name":"false","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":320,"wires":[["c12c290e.94e26"]]},{"id":"6d1526ac.53c11","type":"change","z":"8a8860c2.8bae6","name":"true","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":360,"wires":[["c12c290e.94e26"]]},{"id":"730ad674.c7504","type":"switch","z":"8a8860c2.8bae6","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":190,"y":180,"wires":[["b58cf08a.63039"],["25e1b090.d9858"]]},{"id":"b58cf08a.63039","type":"change","z":"8a8860c2.8bae6","name":"false","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":160,"wires":[["637be1ab.fff2"]]},{"id":"25e1b090.d9858","type":"change","z":"8a8860c2.8bae6","name":"true","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":200,"wires":[["637be1ab.fff2"]]},{"id":"c5de6ddc.866bf8","type":"ui_group","z":"","name":"Light","tab":"b987fe51.3b5d48","order":1,"disp":true,"width":"6"},{"id":"b987fe51.3b5d48","type":"ui_tab","z":"","name":"Dashboard","icon":"dashboard"}]

0 Likes

#7

Thank you. It looks cool. But I just want the mutual exclusion on light on(light A is on--light B is off, light B is on--light A is off) not light off. Another question is how to solve external input condition on switch node for mutual exclusion not only click function.

Below is my flow I believe still have issue.
[{"id":"b888eb90.f58e38","type":"ui_switch","z":"2c2fe5ba.c6ea6a","name":"","label":"light A","group":"db50e537.4096e8","order":0,"width":0,"height":0,"passthru":false,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":370,"y":200,"wires":[["51a8b614.842668","2cf2dca9.827404"]]},{"id":"52b5570b.29f958","type":"ui_switch","z":"2c2fe5ba.c6ea6a","name":"","label":"light B","group":"db50e537.4096e8","order":0,"width":0,"height":0,"passthru":false,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":370,"y":260,"wires":[["61e58da7.1ba524","f7d3d7dc.2f6218"]]},{"id":"51a8b614.842668","type":"function","z":"2c2fe5ba.c6ea6a","name":"change payload","func":"if (msg.payload===true)\n msg.payload=false;\nreturn msg;","outputs":1,"noerr":0,"x":600,"y":200,"wires":[["52b5570b.29f958"]]},{"id":"61e58da7.1ba524","type":"function","z":"2c2fe5ba.c6ea6a","name":"change payload","func":"if (msg.payload===true)\n msg.payload=false;\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":260,"wires":[["b888eb90.f58e38"]]},{"id":"2cf2dca9.827404","type":"debug","z":"2c2fe5ba.c6ea6a","name":"light A","active":true,"console":"false","complete":"payload","x":720,"y":140,"wires":},{"id":"f7d3d7dc.2f6218","type":"debug","z":"2c2fe5ba.c6ea6a","name":"light B","active":true,"console":"false","complete":"payload","x":720,"y":300,"wires":},{"id":"91afe59e.d9c5e8","type":"inject","z":"2c2fe5ba.c6ea6a","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"x":150,"y":180,"wires":[["b888eb90.f58e38"]]},{"id":"8ef7a87c.fed578","type":"inject","z":"2c2fe5ba.c6ea6a","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"x":150,"y":260,"wires":[["52b5570b.29f958"]]},{"id":"db50e537.4096e8","type":"ui_group","z":"","name":"Light","tab":"5167dfe6.e7d11","order":1,"disp":true,"width":"6"},{"id":"5167dfe6.e7d11","type":"ui_tab","z":"","name":"Dashboard","icon":"dashboard"}]

0 Likes

#8

OK, I understand.

In your dashboard nodes 'light A' and 'light B' there is a configuration option which reads:
if msg arrives on input, pass through to output

I suggest you enable this option and see in awe what happens :wink:

Kind regards,

Urs.

0 Likes