Can anyone recommend a more efficient way to copy a switch state from one to another, emulating a 3-way switch, without creating a loop?
For example, this works by explicitly checking each switch state so that it’s not turned on if already on and not turned off if already off… but is quite long:
##################################################################
- alias: Turn on patio light 1 with patio light 2
##################################################################
trigger:
platform: state
entity_id: switch.patio_light_2
from: 'off'
to: 'on'
condition:
condition: state
entity_id: switch.patio_light_1
state: 'off'
action:
service: homeassistant.turn_on
entity_id: switch.patio_light_1
##################################################################
- alias: Turn off patio light 1 with patio light 2
##################################################################
trigger:
platform: state
entity_id: switch.patio_light_2
from: 'on'
to: 'off'
condition:
condition: state
entity_id: switch.patio_light_1
state: 'on'
action:
service: homeassistant.turn_off
entity_id: switch.patio_light_1
##################################################################
- alias: Turn on patio light 2 with patio light 1
##################################################################
trigger:
platform: state
entity_id: switch.patio_light_1
from: 'off'
to: 'on'
condition:
condition: state
entity_id: switch.patio_light_2
state: 'off'
action:
service: homeassistant.turn_on
entity_id: switch.patio_light_2
##################################################################
- alias: Turn off patio light 2 with patio light 1
##################################################################
trigger:
platform: state
entity_id: switch.patio_light_1
from: 'on'
to: 'off'
condition:
condition: state
entity_id: switch.patio_light_2
state: 'on'
action:
service: homeassistant.turn_off
entity_id: switch.patio_light_2