Conditional toggle switch


#1

Hi,
i'm trying to make 2 switches on dashboard, that work opposite of each other, in another word if i turn on one switch the other one should turn off and vice versa, is there a way to do that ?

i attached the template flow that i want to have. thanks in advance for your help.

[{"id":"109a0d3d.bca853","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"8129cf98.f6947","type":"ui_switch","z":"109a0d3d.bca853","name":"mobility","label":"walk","group":"9d2023c7.17976","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"str","onicon":"","oncolor":"","offvalue":"false","offvalueType":"str","officon":"","offcolor":"","x":304.3000030517578,"y":163.8666763305664,"wires":[[]]},{"id":"d2c269cb.abd188","type":"ui_switch","z":"109a0d3d.bca853","name":"mobility","label":"bike","group":"9d2023c7.17976","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"str","onicon":"","oncolor":"","offvalue":"false","offvalueType":"str","officon":"","offcolor":"","x":308.00001525878906,"y":283.00001335144043,"wires":[[]]},{"id":"9d2023c7.17976","type":"ui_group","z":"","name":"Control","tab":"7f4a66df.baa528","disp":true,"width":"6","collapse":false},{"id":"7f4a66df.baa528","type":"ui_tab","z":"","name":"MYhome","icon":"dashboard"}]


#2

Will the switches ever be in the same position? What about at startup?
If they will be in different positions, which will be on and wich off?


#3

hi, the default position is not matter , but presumably the walk can be on and the bike is off


#4

First off I suggest you add two debug nodes and attach one to eht output of each button.
Then take an inject node and attach it to the input of each button.

Nextread what the Info tab about the button tell you. Then play with pressing the buttons and see what comes out in the debug node.

Next yo have to figure out how th get the output of one of the buttons change the state of the other. Experiment a bit and see what you can come up with.


#5

this is what i could come up with but there is 2 problem here:
first, the second switch does not show any output
second, the output of the second switch is always something reverse that means when it's on it shows false and vice versa. could you please show me how to fix this?
thanks

[{"id":"e6663c8f.8e8d8","type":"ui_switch","z":"da11c807.981968","name":"","label":"switch","group":"9d2023c7.17976","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":599.3000335693359,"y":456.33336639404297,"wires":[["9929cf7c.3ee41","db7ebf46.36aba"]]},{"id":"9929cf7c.3ee41","type":"ui_switch","z":"da11c807.981968","name":"switch2","label":"switch","group":"9d2023c7.17976","order":0,"width":0,"height":0,"passthru":false,"decouple":"false","topic":"","style":"","onvalue":"false","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"true","offvalueType":"bool","officon":"","offcolor":"","x":595.3002243041992,"y":553.3334589004517,"wires":[["e6663c8f.8e8d8","30b5af47.50ba6"]]},{"id":"40dcb691.f4a6d8","type":"debug","z":"da11c807.981968","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1019.3003158569336,"y":548.4001569747925,"wires":[]},{"id":"db7ebf46.36aba","type":"debug","z":"da11c807.981968","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":884.300178527832,"y":456.40009689331055,"wires":[]},{"id":"59a5196b.8e4328","type":"inject","z":"da11c807.981968","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":337.30001068115234,"y":454.2000217437744,"wires":[["e6663c8f.8e8d8"]]},{"id":"839449e7.4a1518","type":"inject","z":"da11c807.981968","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":354.0000762939453,"y":552.000093460083,"wires":[["9929cf7c.3ee41"]]},{"id":"30b5af47.50ba6","type":"Invert","z":"da11c807.981968","name":"Invert","x":832.500171661377,"y":551.2000274658203,"wires":[["40dcb691.f4a6d8"]]},{"id":"9d2023c7.17976","type":"ui_group","z":"","name":"Control","tab":"7f4a66df.baa528","disp":true,"width":"6","collapse":false},{"id":"7f4a66df.baa528","type":"ui_tab","z":"","name":"MYhome","icon":"dashboard"}]