summaryrefslogtreecommitdiffstats
path: root/blueprints/automation/lights/light_switch.yaml
blob: b3a4f81030ee3352775908e63bf23000fb96b3a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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