forked from EPMatt/awesome-ha-blueprints
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ikea_e1744.yaml
343 lines (338 loc) · 14.9 KB
/
ikea_e1744.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
# Blueprint metadata
blueprint:
name: Controller - IKEA E1744 SYMFONISK Rotary Remote
description: |
# Controller - IKEA E1744 SYMFONISK Rotary Remote
Controller automation for executing any kind of action triggered by the provided IKEA E1744 SYMFONISK Rotary Remote. Allows to optionally loop a custom action during controller rotation.
Supports deCONZ, ZHA, Zigbee2MQTT.
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/ikea_e1744#available-hooks) for additional details.
📕 Full documentation regarding this blueprint is available [here](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/controllers/ikea_e1744).
🚀 This blueprint is part of the **[Awesome HA Blueprints](https://epmatt.github.io/awesome-ha-blueprints) project**.
ℹ️ Version 2021.10.26
source_url: https://github.com/EPMatt/awesome-ha-blueprints/blob/main/blueprints/controllers/ikea_e1744/ikea_e1744.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
- 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. 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
# inputs for custom actions
action_rotate_left:
name: (Optional) Rotate left
description: Action to run on rotate left.
default: []
selector:
action:
action_rotate_left_stop:
name: (Optional) Rotate left stop
description: Action to run when stopping to rotate left the remote.
default: []
selector:
action:
action_rotate_right:
name: (Optional) Rotate right
description: Action to run on rotate right.
default: []
selector:
action:
action_rotate_right_stop:
name: (Optional) Rotate right stop
description: Action to run when stopping to rotate right the remote.
default: []
selector:
action:
action_click_short:
name: (Optional) Remote short press
description: Action to run on short remote press.
default: []
selector:
action:
action_click_double:
name: (Optional) Remote double press
description: Action to run on double remote press.
default: []
selector:
action:
action_click_triple:
name: (Optional) Remote triple press
description: Action to run on triple remote press.
default: []
selector:
action:
# inputs for looping custom actions on long button press events until the corresponding release event is received
rotate_left_loop:
name: (Optional) Rotate left - loop until stop
description: Loop the rotate left action until the rotation is stopped.
default: false
selector:
boolean:
rotate_left_max_loop_repeats:
name: (Optional) Rotate left - 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
rotate_right_loop:
name: (Optional) Rotate right - loop until stop
description: Loop the rotate right action until the rotation is stopped.
default: false
selector:
boolean:
rotate_right_max_loop_repeats:
name: (Optional) Rotate right - 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
# helpers used to properly recognize the remote button events
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
rotate_left_loop: !input rotate_left_loop
rotate_left_max_loop_repeats: !input rotate_left_max_loop_repeats
rotate_right_loop: !input rotate_right_loop
rotate_right_max_loop_repeats: !input rotate_right_max_loop_repeats
helper_last_controller_event: !input helper_last_controller_event
helper_debounce_delay: !input helper_debounce_delay
# integration id used to select items in the action mapping
integration_id: '{{ integration | lower }}'
# mapping between actions and integrations
actions_mapping:
deconz:
rotate_left: ['3001']
rotate_stop: ['3003', '2003']
rotate_right: ['2001']
click_short: ['1002']
click_double: ['1004']
click_triple: ['1005']
zha:
rotate_left: [move_1_195, move_MoveMode.Down_195_bitmap8.0_bitmap8.0]
rotate_stop: [stop, stop_bitmap8.0_bitmap8.0]
rotate_right: [move_0_195, move_MoveMode.Up_195_bitmap8.0_bitmap8.0]
click_short: [toggle]
click_double: [step_0_1_0, step_StepMode.Up_1_0_bitmap8.0_bitmap8.0]
click_triple: [step_1_1_0, step_StepMode.Down_1_0_bitmap8.0_bitmap8.0]
zigbee2mqtt:
rotate_left: [brightness_move_down]
rotate_stop: [brightness_stop]
rotate_right: [brightness_move_up]
click_short: [toggle]
click_double: [brightness_step_up]
click_triple: [brightness_step_down]
# pre-choose actions for buttons based on configured integration
# no need to perform this task at automation runtime
rotate_left: '{{ actions_mapping[integration_id]["rotate_left"] }}'
rotate_stop: '{{ actions_mapping[integration_id]["rotate_stop"] }}'
rotate_right: '{{ actions_mapping[integration_id]["rotate_right"] }}'
click_short: '{{ actions_mapping[integration_id]["click_short"] }}'
click_double: '{{ actions_mapping[integration_id]["click_double"] }}'
click_triple: '{{ actions_mapping[integration_id]["click_triple"] }}'
# build data to send within a controller event
controller_entity: !input controller_entity
controller_device: !input controller_device
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 }}{{"_" if trigger.event.data.args|length > 0}}{{ trigger.event.data.args|join("_") }}
{%- 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:
# 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 }}{{"_" if trigger.event.data.args|length > 0}}{{ trigger.event.data.args|join("_") }}
{%- endif -%}
trigger_delta: '{{ (as_timestamp(now()) - as_timestamp((states(helper_last_controller_event) | from_json).last_triggered if helper_last_controller_event is not none and (states(helper_last_controller_event) | regex_match("^\{(\".*\": \".*\"(, )?)*\}$")) else "1970-01-01 00:00:00")) * 1000 }}'
last_controller_event: '{{ (states(helper_last_controller_event) | from_json).trigger_action if helper_last_controller_event is not none and (states(helper_last_controller_event) | regex_match("^\{(\".*\": \".*\"(, )?)*\}$")) else "" }}'
# update helper
- service: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: '{{ {"trigger_action":trigger_action,"last_triggered":now()|string} | to_json }}'
# choose the sequence to run based on the received button event
- choose:
- conditions: '{{ trigger_action | string in rotate_left }}'
sequence:
# fire the event only once before looping the action
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: rotate_left
- choose:
# if looping is enabled, loop the action for a finite number of iterations
- conditions: '{{ rotate_left_loop }}'
sequence:
- repeat:
while: '{{ repeat.index < rotate_left_max_loop_repeats | int }}'
sequence: !input action_rotate_left
# if looping is not enabled run the custom action only once
default: !input action_rotate_left
- conditions:
- '{{ trigger_action | string in rotate_stop }}'
# check the previous event to determine the event which the received stop action is relative to
- '{{ last_controller_event | string in rotate_left }}'
sequence:
# fire the event
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: rotate_left_stop
# run the custom action
- choose:
- conditions: []
sequence: !input action_rotate_left_stop
- conditions: '{{ trigger_action | string in rotate_right }}'
sequence:
# fire the event only once before looping the action
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: rotate_right
- choose:
# if looping is enabled, loop the action for a finite number of iterations
- conditions: '{{ rotate_right_loop }}'
sequence:
- repeat:
while: '{{ repeat.index < rotate_right_max_loop_repeats | int }}'
sequence: !input action_rotate_right
# if looping is not enabled run the custom action only once
default: !input action_rotate_right
- conditions:
- '{{ trigger_action | string in rotate_stop }}'
# check the previous event to determine the event which the received stop action is relative to
- '{{ last_controller_event | string in rotate_right }}'
sequence:
# fire the event
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: rotate_right_stop
# run the custom action
- choose:
- conditions: []
sequence: !input action_rotate_right_stop
- conditions: '{{ trigger_action | string in click_short }}'
sequence:
# fire the event
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: click_short
# run the custom action
- choose:
- conditions: []
sequence: !input action_click_short
- conditions: '{{ trigger_action | string in click_double }}'
sequence:
# fire the event
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: click_double
# run the custom action
- choose:
- conditions: []
sequence: !input action_click_double
- conditions: '{{ trigger_action | string in click_triple }}'
sequence:
# fire the event
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: click_triple
# run the custom action
- choose:
- conditions: []
sequence: !input action_click_triple