-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZHA - IKEA Tradfri Shortcut.yaml
129 lines (129 loc) · 4.45 KB
/
ZHA - IKEA Tradfri Shortcut.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
blueprint:
name: ZHA - IKEA Tradfri Shortcut button
description: Control anything with the ikea shortcut button
source_url: https://github.com/evorgevol/hassio/blob/main/ZHA%20-%20IKEA%20Tradfri%20Shortcut.yaml
domain: automation
input:
shortcut_button:
name: Device
description: Select an IKEA shortcut button
selector:
device:
integration: zha
manufacturer: IKEA of Sweden
model: TRADFRI SHORTCUT Button
light:
name: Light(s)
description: The light(s) to control
selector:
target:
entity:
- domain:
- light
delay_between_action_repeats:
name: Delay between presses
default: 600
selector:
number:
min: 200
max: 5000
step: 10
unit_of_measurement: milliseconds
mode: box
debounce:
name: Debounce duration
default: 100
selector:
number:
min: 0
max: 500
step: 10
unit_of_measurement: milliseconds
mode: box
helper_last_controller_event:
name: (Required) Helper - Input Text
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.
default: ''
selector:
entity:
filter:
domain: input_text
# source_url: https://github.com/evorgevol/hassio/blob/main/ZHA%20-%20IKEA%20Tradfri%20Shortcut.yaml
mode: restart
max_exceeded: silent
variables:
button_device_id: !input shortcut_button
helper_last_controller_event: !input helper_last_controller_event
delay_between_action_repeats: !input delay_between_action_repeats
debounce: !input debounce
trigger:
- platform: event
event_type: zha_event
event_data:
device_id: !input shortcut_button
endpoint_id: 1
command: 'on'
- platform: event
event_type: zha_event
event_data:
device_id: !input shortcut_button
endpoint_id: 1
command: 'stop_with_on_off'
action:
- variables:
command: '{{ trigger.event.data.command }}'
- delay:
milliseconds: '{{ debounce }}'
- choose:
- conditions:
- "{{ command == 'on' }}"
sequence:
# write to helper
- variables:
last_value: "{{ states(helper_last_controller_event) if states(helper_last_controller_event) != 'unknown' else 'bob,bob,0,0' | string }}"
last_press_device: '{{ last_value.split(",")[0] | string }}'
last_press_command: '{{ last_value.split(",")[1] | string }}'
last_press_time: '{{ last_value.split(",")[2] | float }}'
last_press_count: '{{ last_value.split(",")[3] | int }}'
current_time: '{{ as_timestamp(now()) | float }}'
click_delta: '{{ ((current_time - last_press_time) * 1000) | int }}'
is_repeat: '{{ button_device_id == last_press_device|trim and click_delta <= delay_between_action_repeats }}'
- choose:
- conditions: '{{ is_repeat }}'
sequence:
- service: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: "{{ [button_device_id,command,current_time,(last_press_count+1)] | join(',') }}"
default:
- service: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: "{{ [button_device_id,command,current_time,1] | join(',') }}"
# wait for second click
- delay:
milliseconds: '{{ delay_between_action_repeats - debounce }}'
- choose:
- conditions: '{{ is_repeat }}'
# double press
sequence:
- service: light.turn_on
target: !input 'light'
data:
transition: 1
brightness_pct: 100
# single press - toggle on/off
default:
- service: light.toggle
target: !input 'light'
data:
transition: 0.5
# long click
- conditions:
- "{{ command == 'stop_with_on_off' }}"
sequence:
- service: light.turn_on
target: !input light
data:
brightness_step_pct: -10
transition: 0.5