-
Notifications
You must be signed in to change notification settings - Fork 0
/
philips_929003017102.yaml
232 lines (231 loc) · 9.97 KB
/
philips_929003017102.yaml
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# Blueprint metadata
blueprint:
name: Controller - Philips 929003017102 Hue Dimmer switch
description: |
# Controller - Philips 929003017102 Hue Dimmer switch
ℹ️ Version 2024.01.24
source_url: https://github.com/thumer/homeassistant_blueprints/blob/main/philips_929003017102.yaml
domain: automation
input:
controller_entity:
name: (Zigbee2MQTT) Controller Entity
description: The action sensor of the controller to use for the automation. Choose a value only if the remote is integrated with Zigbee2MQTT.
default: ''
selector:
entity:
domain: sensor
helper_last_controller_event:
name: (Required) Helper - Last Controller Event
description: Input Text used to store the last event fired by the controller. You will need to manually create a text input entity for this, please read the blueprint Additional Notes for more info.
default: ''
selector:
entity:
domain: input_text
light_for_control:
name: (Required) Light for Status reading
description: Ließt den Zustand aus, ob das Licht leuchtet oder nicht.
default: ''
selector:
entity:
domain: light
up_down_toggle:
name: (Required) Toggle for dimming
description: Toggle, ob zuletzt nach oben oder nach unten gedimmt wurde.
default: ''
selector:
entity:
domain: input_boolean
# inputs for custom actions
action_button_press_release_on:
name: (Optional) On button press release 1
description: On button press release 1
default: []
selector:
action:
action_button_hold_on:
name: (Optional) On button hold 1
description: On button hold 1
default: []
selector:
action:
# action_button_hold_release_on:
# name: (Optional) On button release
# description: Action to run on on button release after long press.
# default: []
# selector:
# action:
action_button_press_release_off:
name: (Optional) On button press release 2
description: On button press release 2
default: []
selector:
action:
action_button_hold_off:
name: (Optional) On button hold 2
description: On button hold 2
default: []
selector:
action:
# action_button_hold_release_off:
# name: (Optional) Off button release
# description: Action to run on off button release after long press.
# default: []
# selector:
# action:
# inputs for looping custom actions on long button press events until the corresponding release event is received
button_on_long_loop:
name: (Optional) On button long press - loop until release
description: Loop the on button action until the button is released.
default: false
selector:
boolean:
button_on_long_max_loop_repeats:
name: (Optional) On button long press - Maximum loop repeats
description: >-
Maximum number of repeats for the custom action, when looping is enabled.
Use it as a safety limit to prevent an endless loop in case the corresponding stop event is not received.
default: 500
selector:
number:
min: 1
max: 5000
mode: slider
step: 1
button_off_long_loop:
name: (Optional) Off button long press - loop until release
description: Loop the off button action until the button is released.
default: false
selector:
boolean:
button_off_long_max_loop_repeats:
name: (Optional) Off button long press - Maximum loop repeats
description: >-
Maximum number of repeats for the custom action, when looping is enabled.
Use it as a safety limit to prevent an endless loop in case the corresponding stop event is not received.
default: 500
selector:
number:
min: 1
max: 5000
mode: slider
step: 1
helper_debounce_delay:
name: (Optional) Helper - Debounce delay
description:
Delay used for debouncing RAW controller events, by default set to 0. A value of 0 disables the debouncing feature. Increase this value if you notice custom actions or linked Hooks running multiple times when interacting with the device. When the controller needs to be debounced,
usually a value of 100 is enough to remove all duplicate events.
default: 0
selector:
number:
min: 0
max: 1000
unit_of_measurement: milliseconds
mode: box
step: 10
# Automation schema
variables:
# convert input tags to variables, to be used in templates
button_on_long_loop: !input button_on_long_loop
button_on_long_max_loop_repeats: !input button_on_long_max_loop_repeats
button_off_long_loop: !input button_off_long_loop
button_off_long_max_loop_repeats: !input button_off_long_max_loop_repeats
helper_last_controller_event: !input helper_last_controller_event
helper_debounce_delay: !input helper_debounce_delay
# mapping between actions
actions_mapping:
button_press_release: [left_press_release]
button_hold: [left_hold]
button_hold_release: [left_hold_release]
# no need to perform this task at automation runtime
button_press_release: '{{ actions_mapping["button_press_release"] }}'
button_hold: '{{ actions_mapping["button_hold"] }}'
button_hold_release: '{{ actions_mapping["button_hold_release"] }}'
# build data to send within a controller event
light_for_control: !input light_for_control
up_down_toggle: !input up_down_toggle
controller_entity: !input controller_entity
controller_id: controller_entity
mode: restart
max_exceeded: silent
trigger:
# trigger for zigbee2mqtt
- platform: event
event_type: state_changed
event_data:
entity_id: !input controller_entity
condition:
- condition: and
conditions:
# check that the button event is not empty
- >-
{%- set trigger_action -%}
{{ trigger.event.data.new_state.state }}
{%- endset -%}
{{ trigger_action not in ["","None"] }}
# only for zigbee2mqtt, check if the event is relative to a real state change, and not only some minor changes in the sensor attributes
# this is required since multiple state_changed events are fired for a single button press, with the result of the automation being triggered multiple times
- '{{ trigger.event.data.new_state.state != trigger.event.data.old_state.state }}'
action:
# debouncing - when automation is triggered multiple times, the last automation run is the one which completes execution, due to mode restart
# therefore previous runs must wait for the debounce delay before executing any other action
# if the delay expires and the automation is still running it means it's the last run and execution can continue
- delay:
milliseconds: !input helper_debounce_delay
# extract button event from the trigger
# provide a single string value to check against
- variables:
trigger_action: >-
{{ trigger.event.data.new_state.state }}
trigger_delta: '{{ (as_timestamp(now()) - ((states(helper_last_controller_event) | from_json).t if helper_last_controller_event is not none and (states(helper_last_controller_event) | regex_match("^\{((\"a\": \".*\"|\"t\": \d+\.\d+)(, )?){2}\}$")) else as_timestamp("1970-01-01 00:00:00"))) * 1000 }}'
# update helper
- service: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: '{{ {"a":trigger_action,"t":as_timestamp(now())} | to_json }}'
# choose the sequence to run based on the received button event
- choose:
- conditions: '{{ trigger_action | string in button_press_release }}'
sequence:
- choose:
- conditions: '{{ is_state(light_for_control, "off") }}'
sequence: !input action_button_press_release_on
- conditions: '{{ is_state(light_for_control, "on") }}'
sequence: !input action_button_press_release_off
- conditions: '{{ trigger_action | string in button_hold }}'
sequence:
- choose:
- conditions: '{{ is_state(light_for_control, "on") and is_state(up_down_toggle, "off") }}'
sequence:
- choose:
# if looping is enabled, loop the action for a finite number of iterations
- conditions: '{{ button_on_long_loop }}'
sequence:
- repeat:
while: '{{ repeat.index < button_on_long_max_loop_repeats | int }}'
sequence: !input action_button_hold_on
# if looping is not enabled run the custom action only once
default: !input action_button_hold_on
- conditions: '{{ is_state(light_for_control, "on") and is_state(up_down_toggle, "on") }}'
sequence:
- choose:
# if looping is enabled, loop the action for a finite number of iterations
- conditions: '{{ button_off_long_loop }}'
sequence:
- repeat:
while: '{{ repeat.index < button_off_long_max_loop_repeats | int }}'
sequence: !input action_button_hold_off
# if looping is not enabled run the custom action only once
default: !input action_button_hold_off
- conditions: '{{ trigger_action | string in button_hold_release }}'
sequence:
- choose:
- conditions: '{{ is_state(up_down_toggle, "off") }}'
sequence:
- service: input_boolean.turn_on
data:
entity_id: !input up_down_toggle
- conditions: '{{ is_state(up_down_toggle, "on") }}'
sequence:
- service: input_boolean.turn_off
data:
entity_id: !input up_down_toggle