#3 Way Light Switch Sync State Automation

1 messages · Page 1 of 1 (latest)

solid oak
#

I'm hoping someone can help me understand the home assistant automations. I have several matter light switches wired to 3 way lights. I need these switches to sync state, such that when switch_a changes to on or off, it will change switch_b to the corresponding state as well, and vice versa. I've written some python like pseudo code to illustrate what I'm trying to achieve here:

def sync_upstairs_hallway_lights(change_event):
    switch_a = "light.upstairs_hallway_front_light_switch_light_1"
    switch_b = "light.upstairs_hallway_rear_light_switch_light_1"

    if change_event.entity_id == switch_a:
        if change_event.new_state.state == "on":
            switch_b_state = "on"
        elif change_event.new_state.state == "off":
            switch_b_state = "off"
    elif change_event.entity_id == switch_b:
        if change_event.new_state.state == "on":
            switch_a_state = "on"
        elif change_event.new_state.state == "off":
            switch_a_state = "off"

So far I've tried building the automation in the gui but I seem to be running into recursion issues where the automation triggers itself. I've searched around online but I haven't found any good documentation for a solution to this issue. Does anyone have any ideas regarding how to achieve this? Thank you!

tawny briar
#

I guess you could make it such that switch_b state is only updated if it is not already in the target state. That should stop any recursion issue?

solid oak