-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathz2m-rwl020-scenes.yaml
338 lines (322 loc) · 10.6 KB
/
z2m-rwl020-scenes.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
blueprint:
name: MQTT Philips Hue Dimmer Switch (RWL020) v3.1.8
description: Control lights with a Philips Hue Dimmer Switch
domain: automation
input:
dimmer_switch:
name: Dimmer Switch Action Sensor
description: Select the action sensor of your Philips Hue Dimmer Switch
selector:
device:
filter:
- integration: mqtt
multiple: false
aux_scene_on:
name: ON Button Aux Scene
description: Scene will be active on double ON press
selector:
entity:
filter:
- domain:
- scene
multiple: false
aux_scene_off:
name: Off Button Aux Scene
description: Scene will be active on double OFF press
selector:
entity:
filter:
- domain:
- scene
multiple: false
light:
name: Lights
description: The lights to control with + / - and to turn off
selector:
entity:
domain:
- light
multiple: false
included_scenes:
name: ON Button Scene Cycle
description: Scenes to be included in ON press cycle
default: []
selector:
entity:
filter:
domain: scene
multiple: true
scene_helper:
name: Scene helper
description: Please select an Input Text Helper to be used to record the scene sequence.
selector:
entity:
domain:
- input_text
multiple: false
transition_time:
name: Transition time
description: Transition time when changes
default: 1
selector:
number:
min: 0
max: 3
step: 0.1
unit_of_measurement: sec
brightness_zigbee:
name: Brightness Control via Zigbee2MQTT
description: If enabled, brightness will be controlled directly by Zigbee2MQTT instead of the blueprint
default: false
selector:
boolean:
hold_press_change:
name: Hold press change
description: Transition time between changes
default: 17
selector:
number:
min: 0
max: 25
step: 1
unit_of_measurement: "%"
reset_after:
name: Reset After
description: Timeout can be set after which the order is reset to the first scene.
default: 5
selector:
number:
min: 1
max: 120
step: 1
unit_of_measurement: s
mode: single
max_exceeded: silent
trigger:
- trigger: device
domain: mqtt
device_id: !input dimmer_switch
type: action
subtype: on_press_release
id: on_press_release
# - trigger: device
# domain: mqtt
# device_id: !input dimmer_switch
# type: action
# subtype: on_hold_release
# id: on_hold_release
- trigger: device
domain: mqtt
device_id: !input dimmer_switch
type: action
subtype: off_press_release
id: off_press_release
# - trigger: device
# domain: mqtt
# device_id: !input dimmer_switch
# type: action
# subtype: off_hold_release
# id: off_hold_release
- trigger: device
domain: mqtt
device_id: !input dimmer_switch
type: action
subtype: up_press_release
id: up_press_release
# - trigger: device
# domain: mqtt
# device_id: !input dimmer_switch
# type: action
# subtype: up_hold_release
# id: up_hold_release
- trigger: device
domain: mqtt
device_id: !input dimmer_switch
type: action
subtype: down_press_release
id: down_press_release
# - trigger: device
# domain: mqtt
# device_id: !input dimmer_switch
# type: action
# subtype: down_hold_release
# id: down_hold_release
# - trigger: device
# domain: mqtt
# device_id: !input dimmer_switch
# type: action
# subtype: recall_0
# id: recall_0
# - trigger: device
# domain: mqtt
# device_id: !input dimmer_switch
# type: action
# subtype: recall_1
# id: recall_1
# - trigger: device
# domain: mqtt
# device_id: !input dimmer_switch
# type: action
# subtype: on_press
# id: on_press
- trigger: device
domain: mqtt
device_id: !input dimmer_switch
type: action
subtype: on_hold
id: on_hold
# - trigger: device
# domain: mqtt
# device_id: !input dimmer_switch
# type: action
# subtype: off_press
# id: off_press
- trigger: device
domain: mqtt
device_id: !input dimmer_switch
type: action
subtype: off_hold
id: off_hold
# - trigger: device
# domain: mqtt
# device_id: !input dimmer_switch
# type: action
# subtype: up_press
# id: up_press
- trigger: device
domain: mqtt
device_id: !input dimmer_switch
type: action
subtype: up_hold
id: up_hold
# - trigger: device
# domain: mqtt
# device_id: !input dimmer_switch
# type: action
# subtype: down_press
# id: down_press
- trigger: device
domain: mqtt
device_id: !input dimmer_switch
type: action
subtype: down_hold
id: down_hold
action:
- variables:
command: "{{ trigger.id }}"
included_scenes: !input included_scenes
scene_helper: !input scene_helper
reset_after: !input reset_after
scene_count: "{{ included_scenes | length }}"
target_lights: !input light
hold_press_change: !input hold_press_change
transition_time: !input transition_time
current_scene: >-
{% set data = states(scene_helper) %}
{% if data != "unknown" and data != "" %}
{% set parsed = data | from_json %}
{% if (as_timestamp(now()) - parsed.timestamp) < reset_after %}
{{ parsed.scene }}
{% else %}
0
{% endif %}
{% else %}
0
{% endif %}
- choose:
- conditions: "{{ command == 'on_press_release' }}"
sequence:
- variables:
next_scene: "{{ (current_scene | int + 1) % scene_count }}"
# Activate the current scene
- service: scene.turn_on
data:
transition: "{{ transition_time }}"
entity_id: "{{ included_scenes[current_scene | int] }}"
# Update the helper with next scene
- service: input_text.set_value
target:
entity_id: !input scene_helper
data:
value: '{"scene": {{ next_scene }}, "timestamp": {{ as_timestamp(now()) }}}'
- conditions:
- "{{ command == 'up_hold' or command == 'up_press_release'}}"
- "{{ not (brightness_zigbee | default(false)) }}"
sequence:
- choose:
- conditions: >-
{% set lights = expand(target_lights) | selectattr('state', 'eq', 'on') | list %}
{% set max_brightness = lights | map(attribute='attributes.brightness') | select('number') | list | max | default(0) %}
{{ (max_brightness + ((hold_press_change/100)*254) | round) <= 255 }}
sequence:
- service: light.turn_on
target:
entity_id: "{{ expand(target_lights) | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list }}"
data:
brightness_step_pct: "{{ hold_press_change }}"
transition: "{{ transition_time }}"
- conditions: >-
{% set lights = expand(target_lights) | selectattr('state', 'eq', 'on') | list %}
{% set max_brightness = lights | map(attribute='attributes.brightness') | select('number') | list | max | default(0) %}
{{ (max_brightness + ((hold_press_change/100)*254) | round) > 255 }}
sequence:
- service: light.turn_on
target:
entity_id: "{{ expand(target_lights) | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list }}"
data:
brightness_pct: 100
transition: "{{ transition_time }}"
- conditions:
- "{{ command == 'down_hold' or command == 'down_press_release' }}"
- "{{ not (brightness_zigbee | default(false)) }}"
sequence:
- choose:
- conditions: >-
{% set lights = expand(target_lights) | selectattr('state', 'eq', 'on') | list %}
{% set min_brightness = lights | map(attribute='attributes.brightness') | select('number') | list | min | default(0) %}
{{ min_brightness > 25 }}
sequence:
- service: light.turn_on
target:
entity_id: "{{ expand(target_lights) | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list }}"
data:
brightness_step_pct: "{{ -hold_press_change }}"
transition: "{{ transition_time }}"
- conditions: >-
{% set lights = expand(target_lights) | selectattr('state', 'eq', 'on') | list %}
{% set min_brightness = lights | map(attribute='attributes.brightness') | select('number') | list | min | default(0) %}
{{ min_brightness <= 25 }}
sequence:
- service: light.turn_on
target:
entity_id: "{{ expand(target_lights) | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list }}"
data:
brightness_pct: 1
transition: "{{ transition_time }}"
- conditions: "{{ command == 'off_press_release' }}"
sequence:
- service: light.turn_off
target:
entity_id: !input light
data:
transition: >-
{% set lights = expand(target_lights) | selectattr('state', 'eq', 'on') | list %}
{% set avg_brightness = (lights | map(attribute='attributes.brightness') | select('number') | list | sum) / (lights | length) %}
{% set avg_brightness_pct = (avg_brightness / 255 * 100) | round %}
{{ 0.0 if avg_brightness_pct < 10 else transition_time }}
- conditions: "{{ command == 'off_hold' }}"
sequence:
- service: scene.turn_on
target:
entity_id: !input aux_scene_off
data:
transition: "{{ transition_time }}"
- conditions: "{{ command == 'on_hold' }}"
sequence:
- service: scene.turn_on
target:
entity_id: !input aux_scene_on
data:
transition: "{{ transition_time }}"
- delay:
seconds: "{{ transition_time }}"