forked from EPMatt/awesome-ha-blueprints
-
Notifications
You must be signed in to change notification settings - Fork 0
/
philips_8718699693985.yaml
279 lines (274 loc) · 12.7 KB
/
philips_8718699693985.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# Blueprint metadata
blueprint:
name: Controller - Philips 8718699693985 Hue Smart Button
description: |
# Controller - Philips 8718699693985 Hue Smart Button
Controller automation for executing any kind of action triggered by the provided Philips 8718699693985 Hue Smart Button. Allows to optionally loop an action on a button long press.
Supports deCONZ, ZHA.
Automations created with this blueprint can be connected with one or more [Hooks](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/hooks) supported by this controller.
Hooks allow to easily create controller-based automations for interacting with media players, lights, covers and more.
See the list of [Hooks available for this controller](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/controllers/philips_8718699693985#available-hooks) for additional details.
📕 Full documentation regarding this blueprint is available [here](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/controllers/philips_8718699693985).
🚀 This blueprint is part of the **[Awesome HA Blueprints](https://epmatt.github.io/awesome-ha-blueprints) project**.
ℹ️ Version 2022.08.08
source_url: https://github.com/EPMatt/awesome-ha-blueprints/blob/main/blueprints/controllers/philips_8718699693985/philips_8718699693985.yaml
domain: automation
input:
integration:
name: (Required) Integration
description: Integration used for connecting the remote with Home Assistant. Select one of the available values.
selector:
select:
options:
- deCONZ
- ZHA
controller_device:
name: (deCONZ, ZHA) Controller Device
description: The controller device to use for the automation. Choose a value only if the remote is integrated with deCONZ, ZHA.
default: ''
selector:
device:
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
# inputs for custom actions
action_button_short:
name: (Optional) Button short press
description: Action to run on short button press.
default: []
selector:
action:
action_button_long:
name: (Optional) Button long press
description: Action to run on long button press.
default: []
selector:
action:
action_button_release:
name: (Optional) Button release
description: Action to run on button release after long press.
default: []
selector:
action:
action_button_double:
name: (Optional) Button double press
description: Action to run on double button press.
default: []
selector:
action:
# inputs for looping custom actions on long button press events until the corresponding release event is received
button_long_loop:
name: (Optional) Button long press - loop until release
description: Loop the button action until the button is released.
default: false
selector:
boolean:
button_long_max_loop_repeats:
name: (Optional) 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
# inputs for enabling double press events
button_double_press:
name: (Optional) Expose button double press event
description: Choose whether or not to expose the virtual double press event for the button. Turn this on if you are providing an action for the button double press event.
default: false
selector:
boolean:
# helpers used to properly recognize the remote button events
helper_double_press_delay:
name: (Optional) Helper - Double Press delay
description: Max delay between the first and the second button press for the double press event. Provide a value only if you are using a double press action. Increase this value if you notice that the double press action is not triggered properly.
default: 500
selector:
number:
min: 100
max: 5000
unit_of_measurement: milliseconds
mode: box
step: 10
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
integration: !input integration
button_long_loop: !input button_long_loop
button_long_max_loop_repeats: !input button_long_max_loop_repeats
button_double_press: !input button_double_press
helper_last_controller_event: !input helper_last_controller_event
helper_double_press_delay: !input helper_double_press_delay
helper_debounce_delay: !input helper_debounce_delay
# integration id used to select items in the action mapping
integration_id: '{{ integration | lower }}'
# adjusted debounce delay so that the resulting double press delay is exactly as specified by the user when running the action, taking also account of debouncing
# make sure it never goes below the minimum double press delay
adjusted_double_press_delay: '{{ [helper_double_press_delay - helper_debounce_delay, 100] | max }}'
# mapping between actions and integrations
actions_mapping:
deconz:
button_short: ['1000']
button_long: ['1001']
button_release: ['1003']
zha:
button_short: [on_short_release]
button_long: [on_hold]
button_release: [on_long_release]
# pre-choose actions for buttons based on configured integration
# no need to perform this task at automation runtime
button_short: '{{ actions_mapping[integration_id]["button_short"] }}'
button_long: '{{ actions_mapping[integration_id]["button_long"] }}'
button_release: '{{ actions_mapping[integration_id]["button_release"] }}'
# build data to send within a controller event
controller_device: !input controller_device
controller_id: '{{controller_device}}'
mode: restart
max_exceeded: silent
trigger:
# trigger for other integrations
- platform: event
event_type:
- deconz_event
- zha_event
event_data:
device_id: !input controller_device
condition:
# check that the button event is not empty
- >-
{%- set trigger_action -%}
{%- if integration_id == "zigbee2mqtt" -%}
{{ trigger.event.data.new_state.state }}
{%- elif integration_id == "deconz" -%}
{{ trigger.event.data.event }}
{%- elif integration_id == "zha" -%}
{{ trigger.event.data.command }}
{%- endif -%}
{%- endset -%}
{{ trigger_action not in ["","None"] }}
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: >-
{%- if integration_id == "zigbee2mqtt" -%}
{{ trigger.event.data.new_state.state }}
{%- elif integration_id == "deconz" -%}
{{ trigger.event.data.event }}
{%- elif integration_id == "zha" -%}
{{ trigger.event.data.command }}
{%- endif -%}
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_short }}'
sequence:
- choose:
# if double press event is enabled
- conditions: '{{ button_double_press }}'
sequence:
- choose:
# if previous event was a short press
- conditions: '{{ trigger_action | string in states(helper_last_controller_event) and trigger_delta | int <= helper_double_press_delay | int }}'
sequence:
# store the double press event in the last controller event helper
- service: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: '{{ {"a":"double_press","t":as_timestamp(now())} | to_json }}'
# run the double press action
# fire the event
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: button_double
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_double
# previous event was not a short press
default:
# wait for the double press event to occur, within the provided delay
# if the second press is received, automation is restarted
- delay:
milliseconds: '{{ adjusted_double_press_delay }}'
# if delay expires, no second press was received, therefore run the short press action
# run the short press action
# fire the event
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: button_short
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_short
# if double press event is disabled run the action for the single short press
default:
# fire the event
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: button_short
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_short
- conditions: '{{ trigger_action | string in button_long }}'
sequence:
# fire the event only once before looping the action
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: button_long
- choose:
# if looping is enabled, loop the action for a finite number of iterations
- conditions: '{{ button_long_loop }}'
sequence:
- repeat:
while: '{{ repeat.index < button_long_max_loop_repeats | int }}'
sequence: !input action_button_long
# if looping is not enabled run the custom action only once
default: !input action_button_long
- conditions: '{{ trigger_action | string in button_release }}'
sequence:
# fire the event
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: button_release
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_release