Skip to content

Instantly share code, notes, and snippets.

@caraar12345
Forked from thatdoogieguy/sync_2_switches.yaml
Last active April 15, 2023 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caraar12345/8e3f6158795c37b6fd5f0143cb48943d to your computer and use it in GitHub Desktop.
Save caraar12345/8e3f6158795c37b6fd5f0143cb48943d to your computer and use it in GitHub Desktop.
Sync Two Switches in Home Assistant
blueprint:
name: Sync two switch entities
description: Mirror two switches by updating the status of the other linked switch to match the triggered switch state
# Credit to https://github.com/bmaehr for original script logic
domain: automation
input:
switch_object1:
name: Automation
selector:
entity:
domain: automation
switch_object2:
name: Toggle
selector:
entity:
domain: input_boolean
variables:
switch_object1: !input switch_object1
switch_object2: !input switch_object2
trigger:
- platform: state
entity_id:
- !input switch_object1
- !input switch_object2
from: 'on'
to: 'off'
- platform: state
entity_id:
- !input switch_object1
- !input switch_object2
from: 'off'
to: 'on'
condition: "{{ trigger.to_state.context.parent_id == none }}"
action:
- wait_template: "{{ (as_timestamp(now()) - as_timestamp(this.attributes.last_triggered | default(0)) | int > 2) }}"
timeout: 2
- service_template: >
{% if trigger.to_state.state == 'on' %}
switch.turn_on
{% elif trigger.to_state.state == 'off' %}
switch.turn_off
{% endif %}
data_template:
entity_id: >
{% if trigger.entity_id == switch_object1 %}
{{ switch_object2 }}
{% elif trigger.entity_id == switch_object2 %}
{{ switch_object1 }}
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment