[分享] 同步雙切開關寫法分享 (ESPHOME)

群組很多人問過,乾脆寫在這邊,非完美,還是有人會遇到舞廳燈,但我自己則是試不出來。

alias: 1_同步開關 (zigbee)
description: ''
trigger:
  - platform: state
    entity_id: switch.0x00158d00018f6d7b_top
  - platform: state
    entity_id: switch.0x00158d00018f6d7b_bottom
condition:
  - condition: template
    value_template: >-
      {{ 'states.switch.0x00158d00018f6d7b_top.state' !=
      'states.switch.0x00158d00018f6d7b_bottom.state' }}
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 200
  - service: homeassistant.turn_{{ trigger.to_state.state }}
    data:
      entity_id: |-
        {% if trigger.entity_id == 'switch.0x00158d00018f6d7b_bottom' %}
           switch.0x00158d00018f6d7b_top
        {% else%}
           switch.0x00158d00018f6d7b_bottom
        {% endif %}
mode: restart