-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZHA IKEA Tradfri on-off Switch (Scene Preset).yaml
303 lines (303 loc) · 11.2 KB
/
ZHA IKEA Tradfri on-off Switch (Scene Preset).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
blueprint:
name: MQTT IKEA Tradfri on/off Switch (Scene Preset) v0.1.2
description: Control lights with a IKEA Tradfri on/off Switch. Scene Preset integration is required https://github.com/Hypfer/hass-scene_presets
domain: automation
input:
dimmer_switch:
name: Dimmer Switch
description: The dimmer switch to use
selector:
entity:
domain: sensor
filter:
- integration: mqtt
multiple: false
light:
name: Lights
description: The lights to control
selector:
entity:
domain:
- light
multiple: true
included_scenes:
name: ON Button Scenes
description: Scenes to be included.
default: []
selector:
select:
mode: dropdown
options:
- label: Static Rest
value: >
{
"preset_id": "e03267e7-9914-4f47-97fe-63c0bd317fe7",
"type": "static"
}
- label: Static Relax
value: >
{
"preset_id": "e71b2ef3-1b15-4c4b-b036-4b3d6efe58f8",
"type": "static"
}
- label: Static Read
value: >
{
"preset_id": "035b6ecf-414e-4781-abc7-3911556097cb",
"type": "static"
}
- label: Static Concentrate
value: >
{
"preset_id": "0cbec4e8-d064-4457-986a-fe6078a63f39",
"type": "static"
}
- label: Static Bright
value: >
{
"preset_id": "6d10a807-7330-46d1-b093-c15520ba72c0",
"type": "static"
}
- label: Static Dimmed
value: >
{
"preset_id": "8f55e62a-e5f8-456a-9e8b-61f314bd4e99",
"type": "static"
}
- label: Dynamic Galaxy
value: >
{
"preset_id": "a6ba3a6e-1e3a-41fd-84f2-f7b021935deb",
"type": "dynamic"
}
- label: Dynamic Nighttime
value: >
{
"preset_id": "cfdb43c7-ccb3-4dd1-b4c7-036e0d74aeb9",
"type": "dynamic"
}
- label: Dynamic Sleepy
value: >
{
"preset_id": "6170702c-f2fc-46fc-99ef-ac98b6c1293e",
"type": "dynamic"
}
- label: Dynamic Unwind
value: >
{
"preset_id": "f7c2f4ce-f957-4745-b9bf-651d5b81c9a6",
"type": "dynamic"
}
- label: Dynamic Storybook
value: >
{
"preset_id": "4f76cd74-28db-455b-9c11-04654be86281",
"type": "dynamic"
}
- label: Dynamic Shine
value: >
{
"preset_id": "ded92eba-901e-4675-8a77-2d17d95aac54",
"type": "dynamic"
}
- label: Dynamic Arise
value: >
{
"preset_id": "d7225176-5cb9-47f3-ab99-8ca9908866fc",
"type": "dynamic"
}
multiple: true
dynamic_transition:
name: Dynamic Transition
description: Transition time between changes of the dynamic colour states
default: 45
selector:
number:
min: 0
max: 300
step: 1
unit_of_measurement: sec
mode: slider
dynamic_interval:
name: Dynamic Interval
description: Time between changes of the dynamic colour states
default: 60
selector:
number:
min: 0
max: 300
step: 1
unit_of_measurement: sec
mode: slider
scene_helper:
name: Scene Helper
description: Please select an Input Text Helper to be used to record the scene sequence in JSON format with timestamp.
selector:
entity:
domain:
- input_text
multiple: false
transition_time:
name: Transition Time
description: Transition time between changes of the light state (appied on ON/OFF/+/-)
default: 0.7
selector:
number:
min: 0.0
max: 3.0
step: 0.1
unit_of_measurement: sec
mode: slider
hold_press_change:
name: Hold Press Change
description: Transition step between changes of the light state (appied on ON/OFF/+/-)
default: 18
selector:
number:
min: 0.0
max: 25.0
step: 1.0
unit_of_measurement: "%"
mode: slider
reset_after:
name: Reset After
description: Timeout in seconds after which the order is reset to the first scene.
default: 5
selector:
number:
min: 1.0
max: 120.0
step: 1.0
unit_of_measurement: s
mode: slider
mode: restart
max_exceeded: silent
trigger:
- platform: state
entity_id: !input dimmer_switch
action:
- variables:
command: "{{ trigger.to_state.state }}"
included_scenes: !input included_scenes
scene_helper: !input scene_helper
reset_after: !input reset_after
target_lights: !input light
hold_press_change: !input hold_press_change
current_preset: >
{% set data = states(scene_helper) %}
{% if data != "unknown" %}
{% if (as_timestamp(now()) - (data | from_json).timestamp) < reset_after %}
{{ (data | from_json).scene }}
{% else %}
0
{% endif %}
{% else %}
0
{% endif %}
- choose:
- conditions: "{{ command == 'on' }}"
sequence:
- service: scene_presets.stop_dynamic_scenes_for_targets
data:
targets:
entity_id: !input light
- choose:
- conditions: "{{ (included_scenes[current_preset] | from_json).type == 'static' }}"
sequence:
- service: scene_presets.apply_preset
data:
preset_id: "{{ (included_scenes[current_preset] | from_json).preset_id }}"
targets:
entity_id: !input light
shuffle: false
smart_shuffle: false
transition: !input transition_time
- conditions: "{{ (included_scenes[current_preset] | from_json).type == 'dynamic' }}"
sequence:
- service: scene_presets.start_dynamic_scene
data:
preset_id: "{{ (included_scenes[current_preset] | from_json).preset_id }}"
targets:
entity_id: !input light
transition: !input dynamic_transition
interval: !input dynamic_interval
- service: input_text.set_value
target:
entity_id: !input scene_helper
data:
value: >
{{ {"scene": (current_preset + 1) % included_scenes | length, "timestamp": as_timestamp(now())} | to_json }}
- conditions:
- "{{ command == 'off' }}"
sequence:
- service: light.turn_off
target:
entity_id: !input light
data:
transition: !input transition_time
- service: scene_presets.stop_dynamic_scenes_for_targets
data:
targets:
entity_id: !input light
- conditions:
- "{{ command == 'brightness_move_up' }}"
sequence:
- repeat:
while:
- condition: template
value_template: "{{ expand(target_lights) | selectattr('state', 'eq', 'on') | selectattr('attributes.brightness', 'lt', 255) | list | length > 0 }}"
sequence:
- choose:
- conditions: "{{ expand(target_lights) | selectattr('state', 'eq', 'on') | selectattr('attributes.brightness', 'lt', 255 - hold_press_change) | list | length > 0 }}"
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: !input transition_time
- conditions: "{{ expand(target_lights) | selectattr('state', 'eq', 'on') | selectattr('attributes.brightness', 'gte', 255 - hold_press_change) | list | length > 0 }}"
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: !input transition_time
- delay:
seconds: !input transition_time
- conditions:
- "{{ command == 'brightness_move_down' }}"
sequence:
- repeat:
while:
- condition: template
value_template: "{{ expand(target_lights) | selectattr('state', 'eq', 'on') | selectattr('attributes.brightness', 'gt', 1) | list | length > 0 }}"
sequence:
- choose:
- conditions: "{{ expand(target_lights) | selectattr('state', 'eq', 'on') | selectattr('attributes.brightness', 'gt', hold_press_change) | list | length > 0 }}"
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: !input transition_time
- conditions: "{{ expand(target_lights) | selectattr('state', 'eq', 'on') | selectattr('attributes.brightness', 'le', hold_press_change) | list | length > 0 }}"
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: !input transition_time
- delay:
seconds: !input transition_time