Use one switch to control multiple lights

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

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

1 Like

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

[{"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"]]}]
1 Like

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...

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

1 Like

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

1 Like

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!

@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?

1 Like

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 !

1 Like