-
Notifications
You must be signed in to change notification settings - Fork 0
/
enocean-ptm-215z-friends-of-hue-switch_st0ma.yaml
413 lines (409 loc) · 15.7 KB
/
enocean-ptm-215z-friends-of-hue-switch_st0ma.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
blueprint:
name: Z2M Controller - EnOcean PTM 215z Dimmer Switch (Friends of Hue) (St0ma)
description: |
# Controller - EnOcean PTM Dimmer Switch (Friends of Hue)
Controller automation for executing any kind of action triggered by the provided EnOcean PTM Dimmer Switch (Friends of Hue).
button assignment:
left upper = button_1
left lower = button_2
right uper = button_3
right lower= button_4
The switch only supports two physical actions "press" and "release".
The blueprint emulates a short press (single press) and a long hold button.
Allows to optionally loop an action on a button long press.
Supports deCONZ, ZHA, Zigbee2MQTT.
Although currently Zigbee Green Power Devices are not available in ZHA!
Version 2023.09.01
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
- Zigbee2MQTT
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:
controller_entity:
name: (Zigbee2MQTT) Controller Entity
description: The action sensor of the controller to use for the automation.
default: ''
selector:
entity:
domain: sensor
multiple: false
input_boolean_longpress:
name: (Required) Helper - Long press input_boolean
description: You need to create this helper input_boolean and select it here
selector:
entity:
domain:
- input_boolean
multiple: false
longpress_duration:
name: Long press duration (ms)
description: The amount of time to hold the button before long press is detected
default: 250
selector:
number:
min: 0.0
max: 1000.0
unit_of_measurement: ms
step: 1.0
mode: slider
longpress_step_delay:
name: Long press step delay for a long press (ms)
description: Delay between each long press step while holding the button. Works only if loop until release is enabled for a button.
default: 250
selector:
number:
min: 0.0
max: 2000.0
unit_of_measurement: ms
step: 1.0
mode: slider
action_button_1_pressed:
name: (Optional) Button 1 short press
description: Action to run, when button 1 is short pressed.
default: []
selector:
action: {}
action_button_1_held:
name: (Optional) Button 1 long hold
description: Action to run, when the button 1 is long held.
default: []
selector:
action: {}
# inputs for looping custom actions on long button press events until the corresponding release event is received
button_1_long_loop:
name: (Optional) button 1 long press - loop until release
description: Loop the button 1 action until the button is released.
default: false
selector:
boolean:
action_button_2_pressed:
name: (Optional) Button 2 short press
description: Action to run, when the button 2 is short pressed.
default: []
selector:
action: {}
action_button_2_held:
name: (Optional) Button 2 long hold
description: Action to run, when the button 2 is long hold.
default: []
selector:
action: {}
button_2_long_loop:
name: (Optional) button 2 long press - loop until release
description: Loop the button 2 action until the button is released.
default: false
selector:
boolean:
action_button_3_pressed:
name: (Optional) Button 3 short pressed
description: Action to run, when the button 3 is short pressed.
default: []
selector:
action: {}
action_button_3_held:
name: (Optional) Button 3 long hold
description: Action to run, when the button 3 is long hold.
default: []
selector:
action: {}
button_3_long_loop:
name: (Optional) button 3 long press - loop until release
description: Loop the button 3 action until the button is released.
default: false
selector:
boolean:
action_button_4_pressed:
name: (Optional) Button 4 short press
description: Action to run, when the button 4 is short pressed.
default: []
selector:
action: {}
action_button_4_held:
name: (Optional) Button 4 long hold
description: Action to run, when the button 4 is long hold.
default: []
selector:
action: {}
button_4_long_loop:
name: (Optional) button 4 long press - loop until release
description: Loop the off button 4 until the button is released.
default: false
selector:
boolean:
# inputs for looping custom actions on long button press events until the corresponding release event is received
button_1_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: 10
selector:
number:
min: 1
max: 5000
mode: slider
step: 1
button_2_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: 10
selector:
number:
min: 1
max: 5000
mode: slider
step: 1
button_3_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: 10
selector:
number:
min: 1
max: 5000
mode: slider
step: 1
button_4_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: 10
selector:
number:
min: 1
max: 5000
mode: slider
step: 1
variables:
# convert input tags to variables, to be used in templates
integration: !input integration
# integration id used to select items in the action mapping
integration_id: '{{ integration | lower }}'
button_1_long_loop: !input button_1_long_loop
button_1_long_max_loop_repeats: !input button_1_long_max_loop_repeats
button_2_long_loop: !input button_2_long_loop
button_2_long_max_loop_repeats: !input button_2_long_max_loop_repeats
button_3_long_loop: !input button_3_long_loop
button_3_long_max_loop_repeats: !input button_3_long_max_loop_repeats
button_4_long_loop: !input button_4_long_loop
button_4_long_max_loop_repeats: !input button_4_long_max_loop_repeats
actions_mapping:
deconz:
button_1_press: ['1000']
button_1_release: ['1003']
button_2_press: ['2000']
button_2_release: ['2003']
button_3_press: ['3000']
button_3_release: ['3003']
button_4_press: ['4000']
button_4_release: ['4003']
zha:
button_1_press: [not_implemented]
button_1_release: [not_implemented]
button_2_press: [not_implemented]
button_2_release: [not_implemented]
button_3_press: [not_implemented]
button_3_release: [not_implemented]
button_4_press: [not_implemented]
button_4_release: [not_implemented]
zigbee2mqtt:
button_1_press: [press_1]
button_1_release: [release_1]
button_2_press: [press_2]
button_2_release: [release_2]
button_3_press: [press_3]
button_3_release: [release_3]
button_4_press: [press_4]
button_4_release: [release_4]
# pre-choose actions for buttons based on configured integration
# no need to perform this task at automation runtime
button_1_press: '{{ actions_mapping[integration_id]["button_1_press"] }}'
button_1_release: '{{ actions_mapping[integration_id]["button_1_release"] }}'
button_2_press: '{{ actions_mapping[integration_id]["button_2_press"] }}'
button_2_release: '{{ actions_mapping[integration_id]["button_2_release"] }}'
button_3_press: '{{ actions_mapping[integration_id]["button_3_press"] }}'
button_3_release: '{{ actions_mapping[integration_id]["button_3_release"] }}'
button_4_press: '{{ actions_mapping[integration_id]["button_4_press"] }}'
button_4_release: '{{ actions_mapping[integration_id]["button_4_release"] }}'
controller_id: '{% if integration_id=="zigbee2mqtt" %}{{controller_entity}}{% else %}{{controller_device}}{% endif %}'
mode: restart
max_exceeded: silent
trigger:
# trigger for zigbee2mqtt
- platform: event
event_type: state_changed
event_data:
entity_id: !input controller_entity
# trigger for other integrations
- platform: event
event_type:
- deconz_event
- zha_event
event_data:
device_id: !input controller_device
condition:
- condition: and
conditions:
# 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"] }}
# 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
- '{{ integration_id != "zigbee2mqtt" or trigger.event.data.new_state.state != trigger.event.data.old_state.state }}'
action:
- 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 -%}
- choose:
- conditions: '{{ trigger_action | string in button_1_press }}'
sequence:
- service: input_boolean.turn_off
data: {}
target:
entity_id: !input input_boolean_longpress
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: !input longpress_duration
- service: input_boolean.turn_on
data: {}
target:
entity_id: !input input_boolean_longpress
- choose:
# if looping is enabled, loop the action for a finite number of iterations
- conditions: '{{ button_1_long_loop }}'
sequence:
- repeat:
while: '{{ repeat.index < button_1_long_max_loop_repeats | int }}'
sequence: !input action_button_1_held
# if looping is not enabled run the custom action only once
default: !input action_button_1_held
- conditions: '{{ trigger_action | string in button_2_press }}'
sequence:
- service: input_boolean.turn_off
data: {}
target:
entity_id: !input input_boolean_longpress
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: !input longpress_duration
- service: input_boolean.turn_on
data: {}
target:
entity_id: !input input_boolean_longpress
- choose:
# if looping is enabled, loop the action for a finite number of iterations
- conditions: '{{ button_2_long_loop }}'
sequence:
- repeat:
while: '{{ repeat.index < button_2_long_max_loop_repeats | int }}'
sequence: !input action_button_2_held
# if looping is not enabled run the custom action only once
default: !input action_button_2_held
- conditions: '{{ trigger_action | string in button_3_press }}'
sequence:
- service: input_boolean.turn_off
data: {}
target:
entity_id: !input input_boolean_longpress
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: !input longpress_duration
- service: input_boolean.turn_on
data: {}
target:
entity_id: !input input_boolean_longpress
- choose:
# if looping is enabled, loop the action for a finite number of iterations
- conditions: '{{ button_3_long_loop }}'
sequence:
- repeat:
while: '{{ repeat.index < button_3_long_max_loop_repeats | int }}'
sequence: !input action_button_3_held
# if looping is not enabled run the custom action only once
default: !input action_button_3_held
- conditions: '{{ trigger_action | string in button_4_press }}'
sequence:
- service: input_boolean.turn_off
data: {}
target:
entity_id: !input input_boolean_longpress
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: !input longpress_duration
- service: input_boolean.turn_on
data: {}
target:
entity_id: !input input_boolean_longpress
- choose:
# if looping is enabled, loop the action for a finite number of iterations
- conditions: '{{ button_4_long_loop }}'
sequence:
- repeat:
while: '{{ repeat.index < button_4_long_max_loop_repeats | int }}'
sequence: !input action_button_4_held
# if looping is not enabled run the custom action only once
default: !input action_button_4_held
- conditions:
- '{{ trigger_action | string in button_1_release }}'
- condition: state
entity_id: !input input_boolean_longpress
state: 'off'
sequence: !input action_button_1_pressed
- conditions:
- '{{ trigger_action | string in button_2_release }}'
- condition: state
entity_id: !input input_boolean_longpress
state: 'off'
sequence: !input action_button_2_pressed
- conditions:
- '{{ trigger_action | string in button_3_release }}'
- condition: state
entity_id: !input input_boolean_longpress
state: 'off'
sequence: !input action_button_3_pressed
- conditions:
- '{{ trigger_action | string in button_4_release }}'
- condition: state
entity_id: !input input_boolean_longpress
state: 'off'
sequence: !input action_button_4_pressed