Multi-switch switching

Hey there. I’m almost setup with home assistant now. Have one automation which I cannot figure out. I have deta 2,3&4 gang switches using tuya local.
I have two switches, one 3 gang hall and one 3 gang studio. With the hall switch (switch 3) I want to be able to turn on one studio switch (switch 2). With the two studio switches either/or switch 2&3, I want to be able to turn on the same hall switch 3. I then still want to be able to manually switch the two studio switches on/off. But I then want to turn the hall switch 3 off and it triggers off either of the studio switches 2&3 if one or both are off.

It’s getting stuck with the two nodes.

Please read the thread on how to paste code and edit your post.

As is, it probably can't be used by anyone anyway.

Ta. I’ll get into it soon

Yes please repost your code

As Andrew has said it will not be useable because of the Tuya nodes - however you can put inject nodes to inject the values you expect at each point so we can see what you are trying to achieve.

It sounds to me like you are trying to make a (what we call it in Australia - where i assume you are from) a Two Way switch - i.e i have physical switch at the top and bottom of the stairs and i wish to turn the light on/off from either switch

In the physical world we accomplish that with an extra wire between the switches that carries the looped "message" - in the Smart switch world we have many more options - you can leave one swich completely disconnected from the wires and handle all of the logic in your Home Automation system - which i assume is Home Assistant.

Have you installed the full version of Node Red or the Dockerized version that they supply through HACS ?

If you have the full version then i would suggest you install the HA add-ons from the Palette.

This will expose all of the HA entties and States - it is an easy thing then to find the state of each of the switches and act on that accordingly.


Here is the code in the correct format now. Thanks

[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":80,"y":480,"wires":[["7e8d85ae.54220c"]]},{"id":"5f3512a9.d8043c","type":"api-call-service","z":"e00cd641.ad0ad8","name":"Turn Off studio W","server":"f00937d0.5543d8","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.studio_w","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":490,"y":300,"wires":[["507fe979.929b88"]]},{"id":"507fe979.929b88","type":"api-current-state","z":"e00cd641.ad0ad8","name":"Studio E Already On?","server":"8ac3cd7f.58d3e","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"switch.studio_e","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"x":720,"y":300,"wires":[["987af7c9.b38a48"],[]]},{"id":"f00937d0.5543d8","type":"server","name":"Home Assistant","addon":true},{"id":"8ac3cd7f.58d3e","type":"server","name":"Home Assistant"}]

Thanks Craig. Not quite a two way switch. something slightly more nuanced.

3 Gang Bottom Stairs switch - Switch 3 (blank switch)
3 Gang Switch Studio switch - Switch 2 controls 6xDLs on west of room. Switch 3 controls 6xDLs on east of room.

The behavior i am attempting to create is:

Press On bottom stairs switch 3 -- turns studio switch 2 On
Press Off bottom stairs switch 3 -- turns studio switch 2 &/or switch 3 Off

Press ON either Studio switch 2/3 - turn stairs bottom switch 3 On
Press Off either Studio switch 2/3 - turn stairs bottom switch 3 Off

The problem i have is that while each separate control works, when both are activated, when i turn off Studio Switch 3, it then calls the bottom stairs and turns studio switch 2 on. I need a few if statements but not sure if it is actually possible??

Yeah i can not follow that one - sorry !!

Draw up a diagram (even hand written and take a picture) and put it up.

Show the proposed on/off sequencing to let me get a better handle on it.

I guess a better question is what are you trying to achieve ? i.e. why are you trying to get a single switch to do both (or have you run out of switches at th bottom of the stairs ?)

I think if you look at the Boolean Ultimate nodes they will do what you want - but draw up the diagram first.

Also is it the full blown Node Red or the HACS Docker container ?


So to simplify it a little and make the programming easier to visualise

Bottom stairs
Turn on - Turns on just switch 2 in studio
Turn off - always turns off switch 2 and 3 in studio

Turn on either switch - turn on switch at the bottom of the stairs
Turn off either switch - turn off switch at the bottom of the stairs

I can not see a problem with this - make sure the actions are discrete on and off - not toggle which is what i suspect you are doing

Are the switches physically wired as two way or you are trying to do it all in software ?

If they were actually hardwired i would simplify it and remove the hardwiring and do it all in software

If toggle is your only option (rather than discrete on off) then use a global variable to represnt the state of the switch and use that to perform your action


Craig, yes this functionality is correct.

Bottom stairs - Switch is a virtual Switch
Turn on - Turns on just switch 2 in studio
Turn off - always turns off switch 2 and 3 in studio

Studio- Both switches are hard wired to lights
Turn on either switch - turn on switch at the bottom of the stairs
Turn off either switch - turn off switch at the bottom of the stairs

I am using service call - turn on/off commands
Using Node-red inside home assistant

With no switches on, when i press Studio switch 3, it then calls bottom stairs switch 3 which then turns studio switch 2 on. Which i don't want it to do.

Aaah got it now - you have a loop happening - now i understand the issue

So what i would do is seperate the logic from the physical

Create a Flow object that represents each switch and use change nodes to manipulate it

Let me do some playing around - back shortly


1 Like

OK what about this - have a look at the change nodes for the stair switch and studio switch 3

Basically you are setting flow variables as per the logic you require

You then need a seperate routine to poll those flow variables and send off the status of each of the switches to HA

[{"id":"4ed3fdb1.fe9634","type":"inject","z":"6975fa7b.a97a34","name":"Switch3 Stairs on","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ON","payloadType":"str","x":310,"y":100,"wires":[["69d28202.c58d2c"]]},{"id":"69d28202.c58d2c","type":"change","z":"6975fa7b.a97a34","name":"Set Flow Variable","rules":[{"t":"set","p":"StairSwitch3State","pt":"flow","to":"payload","tot":"msg"},{"t":"set","p":"StudioSwitch2State","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":140,"wires":[[]]},{"id":"a7360e44.cec5b","type":"inject","z":"6975fa7b.a97a34","name":"Switch3 Stairs off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"OFF","payloadType":"str","x":300,"y":160,"wires":[["69d28202.c58d2c"]]},{"id":"3957ca42.389296","type":"inject","z":"6975fa7b.a97a34","name":"Switch2 Studio on","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ON","payloadType":"str","x":310,"y":240,"wires":[[]]},{"id":"fe659e19.4b085","type":"inject","z":"6975fa7b.a97a34","name":"Switch2 Studio off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"OFF","payloadType":"str","x":310,"y":300,"wires":[[]]},{"id":"c34acfe3.5270f","type":"inject","z":"6975fa7b.a97a34","name":"Switch3 Studio off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"OFF","payloadType":"str","x":310,"y":420,"wires":[["e4ede1c1.fdde5"]]},{"id":"c7564a08.283278","type":"inject","z":"6975fa7b.a97a34","name":"Switch3 Studio on","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ON","payloadType":"str","x":310,"y":360,"wires":[["c27b60b5.db265"]]},{"id":"e4ede1c1.fdde5","type":"change","z":"6975fa7b.a97a34","name":"Set Flow Variable","rules":[{"t":"set","p":"StudioSwitch3State","pt":"flow","to":"payload","tot":"msg"},{"t":"set","p":"StairSwitch3State","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":420,"wires":[[]]},{"id":"c27b60b5.db265","type":"change","z":"6975fa7b.a97a34","name":"Set Flow Variable","rules":[{"t":"set","p":"StudioSwitch3State","pt":"flow","to":"payload","tot":"msg"},{"t":"set","p":"StairSwitch3","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":360,"wires":[[]]}]

Try that and see if that gets you further

Thanks Craig.

Being a complete novice in this. this assumes i know what i'm doing, which when it comes to my complex things, i dont!!

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