Template Light for 4-Way Switch

Hello, I want to make a 4-way switch using 3 physical light switch but only one of them is wired to the actual light (switch.2nd_livingroom_2_right). I followed this thread (Trouble with two 3-way smart switches in Home Assistant - #13 by finity) for 3-way switch, but it doesn’t seem to work with my setup. Here is my current light.yaml file:

- platform: template
  lights:
    front_staircase_3_way:
      friendly_name: Front Staircase 3 Way
      availability_template: >-
        {% if not is_state('switch.2nd_livingroom_2_right', 'unavaiable') %}
          true
        {% endif %}
      value_template: >-
        {% if (is_state('switch.2nd_livingroom_2_right', 'on')
          and is_state('switch.1st_livingroom1_2_right', 'on')
          and is_state('switch.front_door_2_left', 'on'))
          or (is_state('switch.2nd_livingroom_2_right', 'off')
          and is_state('switch.1st_livingroom1_2_right', 'off')
          and is_state('switch.front_door_2_left', 'off')) %}
            on
        {% else %}
          off
        {% endif %}
      turn_on:
        service: switch.turn_on
        entity_id:
        - switch.2nd_livingroom_2_right
        - switch.1st_livingroom1_2_right
        - switch.front_door_2_left
      turn_off:
        service: switch.turn_off
        entity_id:
        - switch.2nd_livingroom_2_right

It works if I turn on and turn off the created light entity itself, but not always working when I flip the actual switch. Thanks before.

What is the “actual switch”?
If I get you right, what you show is working, so you might want to show what is not working :wink:

I wrote “the actual light”, not switch :blush:

So, I have 3 switches, one of them is wired to the light, and the other two is not wired to the light, just live and neutral wire for power. So, I want to simulate 4 way switch in home assistant using template light. The situation I want is:

  • if the light is off and I press one of the switch, home assistant would turn on the switch that is connected to the light.
  • if the light is on and I press one of the switch, home assistant would turn off the switch that is connected to the light.

Thanks for replying, sorry my post wasn’t clear enough. Hope you can help me, my brain is hurt from thinking how to get this working :sweat_smile:

You did write “actual switch” :wink:

Still, what you show is the HA light entity.
You do have some automations that turn this light on or off when a switch is activated, do you?

By itself, the light entity does nothing unless you toggle it inside the HA UI or via an automation (light.turn_on / light.turn_off)

Oh sorry. I did :smile:

Yes, I only show the light template. Did I misunderstood something here? I want to use Template Light for the switch so I don’t need to create automation. I was thinking I can use the value_template of the light to turn on/off the switch by using the turn_on and turn_off actions in the template.

I’m afraid you got it wrong. The value_template here only defines the state of your light entity, ie it’s “passive”, not “active” at all.

Yeah, I ended up with an automation to call light.toggle to the switch that is connected to the light whenever switches that are not connected to the light change state. Seems like this is the only right way for this. Thanks for the valuable information :blush: