# Lock the switches against each other

**URL:** https://discourse.nodered.org/t/lock-the-switches-against-each-other/24608
**Category:** General
**Created:** [10 April 2020 19:13 UTC](https://discourse.nodered.org/t/lock-the-switches-against-each-other/24608 "2020-04-10T19:13:18Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![volker1078](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/volker1078/32/19735_2.png) [@volker1078](https://discourse.nodered.org/u/volker1078)
#### Post date: [10 April 2020 19:13 UTC](https://discourse.nodered.org/t/lock-the-switches-against-each-other/24608/1 "2020-04-10T19:13:19Z")

</div>

Hello,  
I'm looking for a solution to interlock 2 switches in the dashboard. If 1 switch goes "on", switch 2 goes "off" and vice versa. I plan to have several switches and only one should always be on, all others must then automatically switch to off.

Is there a solution for this?

Greetings Volker

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [10 April 2020 19:20 UTC](https://discourse.nodered.org/t/lock-the-switches-against-each-other/24608/2 "2020-04-10T19:20:33Z")

</div>

Welcome to the forum @volker1078

This should be easy. Add an `inject` node and connect it to a `switch` node and connect that to a `debug` node. So first, go to the dashboard and press the switch then go to the editor and see what arrives in the `debug`.

Now look at the `switch` node and check out it's options. Can you put something in the `inject` node to effect the switch?

If you can have the output of the `switch` node feed a second `switch` node with a `debug` node attached to it. What happens?

You will probably have to flip something (like on to off) so you will need some more logic but get to this point first.

---

<div class="post-metadata">

### Author: ![volker1078](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/volker1078/32/19735_2.png) [@volker1078](https://discourse.nodered.org/u/volker1078)
#### Post date: [10 April 2020 19:46 UTC](https://discourse.nodered.org/t/lock-the-switches-against-each-other/24608/3 "2020-04-10T19:46:18Z")

</div>

Thank you for your answer,  
I've already built something, but unfortunately it doesn't work. When I press the switch, the information keeps running through the two switches and Node-Red crashes. The information may only run once after switching through the switch and not again and again.

Here is my node:

`[{"id":"8050bd6f.1d3a98","type":"ui_switch","z":"55c5e2d9.cbd9c4","name":"","label":"switch","tooltip":"","group":"3a9a86da.eed4a2","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"1","onvalueType":"num","onicon":"","oncolor":"","offvalue":"0","offvalueType":"str","officon":"","offcolor":"","x":210,"y":820,"wires":[["6a52f78a.7f11f","621ddf1f.a14ca"]]},{"id":"edfbfb04.f32dd8","type":"ui_switch","z":"55c5e2d9.cbd9c4","name":"","label":"switch","tooltip":"","group":"3a9a86da.eed4a2","order":1,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"1","onvalueType":"str","onicon":"","oncolor":"","offvalue":"0","offvalueType":"str","officon":"","offcolor":"","x":210,"y":940,"wires":[["24224811.a85b9"]]},{"id":"17dbcc7f.da00ec","type":"InvertUltimate","z":"55c5e2d9.cbd9c4","name":"Invert","x":530,"y":820,"wires":[["99bc7a4b.572d28","edfbfb04.f32dd8"]]},{"id":"99bc7a4b.572d28","type":"debug","z":"55c5e2d9.cbd9c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":750,"y":820,"wires":[]},{"id":"6a52f78a.7f11f","type":"debug","z":"55c5e2d9.cbd9c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":350,"y":740,"wires":[]},{"id":"4feb16db.681ce8","type":"debug","z":"55c5e2d9.cbd9c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":590,"y":740,"wires":[]},{"id":"621ddf1f.a14ca","type":"switch","z":"55c5e2d9.cbd9c4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":380,"y":820,"wires":[["17dbcc7f.da00ec","4feb16db.681ce8"],[]]},{"id":"60bb035c.cba2bc","type":"InvertUltimate","z":"55c5e2d9.cbd9c4","name":"Invert","x":530,"y":940,"wires":[["8050bd6f.1d3a98","149f9e0e.0d2e3a"]]},{"id":"24224811.a85b9","type":"switch","z":"55c5e2d9.cbd9c4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":380,"y":940,"wires":[["60bb035c.cba2bc"],[]]},{"id":"149f9e0e.0d2e3a","type":"debug","z":"55c5e2d9.cbd9c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":730,"y":920,"wires":[]},{"id":"3a9a86da.eed4a2","type":"ui_group","z":"","name":"Test","tab":"4e23a76c.608818","disp":true,"width":"6","collapse":false},{"id":"4e23a76c.608818","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]`

Greetings Volker

---

<div class="post-metadata">

### Author: ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)
#### Post date: [10 April 2020 19:49 UTC](https://discourse.nodered.org/t/lock-the-switches-against-each-other/24608/4 "2020-04-10T19:49:54Z")

</div>

That is what will happen with switches. They can't really be grouped in the way we are expecting to.  
But it is easy enough to get done with buttons.  
See this example  
[https://flows.nodered.org/flow/cd90709d95fcba9970bd88205871c3c7](https://flows.nodered.org/flow/cd90709d95fcba9970bd88205871c3c7)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [11 April 2020 08:35 UTC](https://discourse.nodered.org/t/lock-the-switches-against-each-other/24608/5 "2020-04-11T08:35:05Z")

</div>

I haven't looked in detail at your flow but it sounds as if you have Pass Through selected in the switches, clear that selection and it should stop the loop.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [10 June 2020 08:35 UTC](https://discourse.nodered.org/t/lock-the-switches-against-each-other/24608/6 "2020-06-10T08:35:11Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
