Created
June 5, 2026 14:21
-
-
Save narektutikian/e15b54f23c4e5e5fd3cd836608229be5 to your computer and use it in GitHub Desktop.
Blueprint for Sync Two Switches Bi-directionally in Home Assistant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| blueprint: | |
| name: Sync Two Switches Bi-directionally | |
| description: Keeps two switches perfectly in sync. If you turn one on/off, the other follows, while preventing infinite loops. | |
| domain: automation | |
| input: | |
| switch_1: | |
| name: Switch 1 | |
| description: The first switch to keep in sync. | |
| selector: | |
| entity: | |
| domain: switch | |
| switch_2: | |
| name: Switch 2 | |
| description: The second switch to keep in sync. | |
| selector: | |
| entity: | |
| domain: switch | |
| variables: | |
| # We bind the inputs to variables so the Jinja templates below can read them. | |
| switch_1_entity: !input switch_1 | |
| switch_2_entity: !input switch_2 | |
| mode: parallel | |
| max: 10 | |
| triggers: | |
| - id: "switch_1" | |
| entity_id: !input switch_1 | |
| trigger: state | |
| - id: "switch_2" | |
| entity_id: !input switch_2 | |
| trigger: state | |
| conditions: | |
| # Prevents infinite loops by ensuring the trigger wasn't caused by this automation itself | |
| - condition: template | |
| value_template: "{{ trigger.to_state.context.parent_id != this.context.id }}" | |
| - condition: template | |
| value_template: "{{ trigger.to_state.state in ['on','off'] }}" | |
| actions: | |
| - choose: | |
| # --- TRIGGERED BY SWITCH 1 --- | |
| - conditions: | |
| - condition: template | |
| value_template: "{{ trigger.id == 'switch_1' }}" | |
| sequence: | |
| - if: | |
| - condition: template | |
| value_template: "{{ states(switch_2_entity) != trigger.to_state.state }}" | |
| then: | |
| - target: | |
| entity_id: !input switch_2 | |
| action: switch.turn_{{ trigger.to_state.state }} | |
| # --- TRIGGERED BY SWITCH 2 --- | |
| - conditions: | |
| - condition: template | |
| value_template: "{{ trigger.id == 'switch_2' }}" | |
| sequence: | |
| - if: | |
| - condition: template | |
| value_template: "{{ states(switch_1_entity) != trigger.to_state.state }}" | |
| then: | |
| - target: | |
| entity_id: !input switch_1 | |
| action: switch.turn_{{ trigger.to_state.state }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment