summaryrefslogtreecommitdiffstats
path: root/blueprints/automation/lights/light_switch.yaml
diff options
context:
space:
mode:
Diffstat (limited to 'blueprints/automation/lights/light_switch.yaml')
-rw-r--r--blueprints/automation/lights/light_switch.yaml115
1 files changed, 115 insertions, 0 deletions
diff --git a/blueprints/automation/lights/light_switch.yaml b/blueprints/automation/lights/light_switch.yaml
new file mode 100644
index 0000000..b3a4f81
--- /dev/null
+++ b/blueprints/automation/lights/light_switch.yaml
@@ -0,0 +1,115 @@
+blueprint:
+ name: Light Switch
+ description: Switch to control light bulb or power plug (including two-way synchronization)
+ domain: automation
+ input:
+ switch:
+ name: Switch
+ description: controller
+ selector:
+ entity:
+ domain: switch
+ light:
+ name: Bulb
+ description: smart bulb or power socket
+ selector:
+ entity:
+ domain: [light, switch]
+ dblclick:
+ name: dblclick
+ description: Actions to perform on double click
+ default: []
+ selector:
+ action:
+ on_click:
+ name: on_click
+ description: Additional actions to perform while turning on master switch
+ default: []
+ selector:
+ action:
+ off_click:
+ name: off_click
+ description: Additional actions to perform while turning off master switch
+ default: []
+ selector:
+ action:
+
+variables:
+ switch_entity: !input switch
+ light_entity: !input light
+ dblclick: !input dblclick
+
+trigger:
+ - platform: state
+ entity_id: !input "switch"
+ - platform: state
+ entity_id: !input "light"
+
+mode: single
+action:
+ - choose:
+ - conditions:
+ - "{{ trigger.entity_id == switch_entity }}"
+ sequence:
+ - if:
+ - condition: template
+ value_template: '{{ dblclick | length > 0 }}'
+ then:
+ - wait_for_trigger:
+ - platform: state
+ entity_id: !input switch
+ timeout: '1'
+ continue_on_timeout: true
+ - if:
+ - condition: template
+ value_template: '{{ wait.trigger == None }}'
+ then:
+ - if:
+ - condition: template
+ value_template: '{{trigger.to_state.state == "on" }}'
+ then:
+ - parallel:
+ - choose: []
+ default: !input "on_click"
+ - service: homeassistant.turn_on
+ target:
+ entity_id: !input light
+ else:
+ - parallel:
+ - choose: []
+ default: !input "off_click"
+ - service: homeassistant.turn_off
+ target:
+ entity_id: !input light
+ else:
+ - choose: []
+ default: !input "dblclick"
+ else:
+ - if:
+ - condition: template
+ value_template: '{{trigger.to_state.state == "on" }}'
+ then:
+ - parallel:
+ - choose: []
+ default: !input "on_click"
+ - service: homeassistant.turn_on
+ target:
+ entity_id: !input light
+ else:
+ - parallel:
+ - choose: []
+ default: !input "off_click"
+ - service: homeassistant.turn_off
+ target:
+ entity_id: !input light
+ - conditions:
+ - "{{ trigger.entity_id == light_entity }}"
+ sequence:
+ - service: >
+ {% if trigger.to_state.state == "on" %}
+ switch.turn_on
+ {% else %}
+ switch.turn_off
+ {% endif %}
+ target:
+ entity_id: !input switch