# Use one switch to control multiple lights

**URL:** <https://discourse.nodered.org/t/use-one-switch-to-control-multiple-lights/5913>\
**Category:** General\
**Created:** [18 December 2018 01:05 UTC](https://discourse.nodered.org/t/use-one-switch-to-control-multiple-lights/5913 "2018-12-18T01:05:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![moita](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@moita](https://discourse.nodered.org/u/moita)\
**Post date:** [18 December 2018 01:05 UTC](https://discourse.nodered.org/t/use-one-switch-to-control-multiple-lights/5913/1 "2018-12-18T01:05:57Z")

</div>

Hi, i have home assistant with nodered and some sonoff basic flashed with tasmota, i use GPIO pins to control the relays but by switchtopic (mqtt, not directly) and i want to create a flow based in how many times i turn the switch on or off (its a switch not a press button) for example:  
on - ceiling light  
on/off/on - desk light  
is it possible ? i've searched a lot on internet and found anything  
thanks

---

<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:** [18 December 2018 05:09 UTC](https://discourse.nodered.org/t/use-one-switch-to-control-multiple-lights/5913/2 "2018-12-18T05:09:59Z")

</div>

If tasmota already in use, then I suggest to replace switch with pushbutton and then you can use the "long press" (HOLD command) option.

---

<div class="post-metadata">

**Author:** ![rgerrans](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@rgerrans](https://discourse.nodered.org/u/rgerrans)\
**Post date:** [18 December 2018 14:47 UTC](https://discourse.nodered.org/t/use-one-switch-to-control-multiple-lights/5913/3 "2018-12-18T14:47:03Z")

</div>

What about using a Join node with a timeout (you could also use multiple join nodes in parallel with # of message parts / timeout to not have to wait for the timeout before sending). Then feed it to a switch node that evaluates the joined string looking for the combination in question. Something like this:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/619ff522b4d72098c1f499855f0cc96ca33c46c3.png)

```
[{"id":"2d878d4c.e51e12","type":"join","z":"1535d28d.7fd35d","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"/","joinerType":"str","accumulate":false,"timeout":"2","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":490,"y":600,"wires":[["b025cafa.c402f8"]]},{"id":"89c55db4.6f8d2","type":"debug","z":"1535d28d.7fd35d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":950,"y":600,"wires":[]},{"id":"3e5e15b9.af44ca","type":"inject","z":"1535d28d.7fd35d","name":"","topic":"","payload":"ON","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":310,"y":580,"wires":[["2d878d4c.e51e12"]]},{"id":"27f9be51.24f442","type":"inject","z":"1535d28d.7fd35d","name":"","topic":"","payload":"OFF","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":310,"y":620,"wires":[["2d878d4c.e51e12"]]},{"id":"b025cafa.c402f8","type":"switch","z":"1535d28d.7fd35d","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"ON","vt":"str"},{"t":"eq","v":"OFF","vt":"str"},{"t":"eq","v":"ON/OFF/ON","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":650,"y":600,"wires":[["89c55db4.6f8d2"],["89c55db4.6f8d2"],["89c55db4.6f8d2"]]}]
```

---

<div class="post-metadata">

**Author:** ![moita](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@moita](https://discourse.nodered.org/u/moita)\
**Post date:** [20 December 2018 14:24 UTC](https://discourse.nodered.org/t/use-one-switch-to-control-multiple-lights/5913/4 "2018-12-20T14:24:50Z")

</div>

thanks, i have one regular wall switch and one pushbutton attatched to the sonoff basic, the switch is just to be a regular switch like without any sonoff stuff, and the push i've already changed the topic to control another sonoff and im itself  
But i want to keep the wall switch and make it "more clever" than just control one light...

---

<div class="post-metadata">

**Author:** ![moita](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@moita](https://discourse.nodered.org/u/moita)\
**Post date:** [20 December 2018 14:27 UTC](https://discourse.nodered.org/t/use-one-switch-to-control-multiple-lights/5913/5 "2018-12-20T14:27:03Z")

</div>

Thanks a lot, im going to try it, im a bit newbie on node red automation but i think i can make it, soon i'l give you some feedback  
Again thanks, apreciate your help

---

<div class="post-metadata">

**Author:** ![moita](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@moita](https://discourse.nodered.org/u/moita)\
**Post date:** [10 March 2019 13:28 UTC](https://discourse.nodered.org/t/use-one-switch-to-control-multiple-lights/5913/6 "2019-03-10T13:28:29Z")

</div>

Sorry for taking a while to answer but this was what i've been looking for, thanks !! really appreciate it

---

<div class="post-metadata">

**Author:** ![moita](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@moita](https://discourse.nodered.org/u/moita)\
**Post date:** [23 May 2019 18:55 UTC](https://discourse.nodered.org/t/use-one-switch-to-control-multiple-lights/5913/7 "2019-05-23T18:55:03Z")

</div>

Hi, this is working pretty good in the last months, but now i was thinking about the solution to dont have to wait for a timeout and i didnt understand the part of the multiple join to dont have to wait for the timeout.  
my switch only outputs "TOGGLE" payload  
do you have any idea in how to do it ?  
Thanks!

---

<div class="post-metadata">

**Author:** ![rgerrans](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@rgerrans](https://discourse.nodered.org/u/rgerrans)\
**Post date:** [24 May 2019 13:42 UTC](https://discourse.nodered.org/t/use-one-switch-to-control-multiple-lights/5913/8 "2019-05-24T13:42:30Z")

</div>

> [@moita](#):
>
> i was thinking about the solution to dont have to wait for a timeout and i didnt understand the part of the multiple join to dont have to wait for the timeout.

@moita Had to think back to when I looked at this. My original thought was that you could setup a separate join for each set of sequences by the # of changes that would be involved (i.e. you'd have one that waited for 2 toggles - on/off, you could have one waiting for 3 toggles - on/off/on, etc) all wired in parallel. Thinking it back over I don't think this would create any improvement over the current approach since you'd still have to figure out how not to send the single toggle or the double toggle if you were doing a triple.

Maybe you can try shortening the timeout to see if you still can get 3 toggles in but decrease the delay for a single toggle?

---

<div class="post-metadata">

**Author:** ![moita](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@moita](https://discourse.nodered.org/u/moita)\
**Post date:** [25 May 2019 19:04 UTC](https://discourse.nodered.org/t/use-one-switch-to-control-multiple-lights/5913/9 "2019-05-25T19:04:31Z")

</div>

Thanks, thats the point i've reached too, i decreased the delay to 0.3 and the toggles too, i have single toggle to one light and double to another light.  
i did this a month ago or so to decrease the timeout, and actually its pretty fast.  
But i was looking for a faster method, anyway i think thats it, thanks again !
