/
hasp_plate01_p3_toggles.yaml
executable file
·322 lines (310 loc) · 12.6 KB
/
hasp_plate01_p3_toggles.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
##############################################################################
# Automations for handling toggle state buttons on page 3
automation:
# Set font and text for toggle buttons on device connection
- alias: hasp_plate01_p3_ToggleInit
trigger:
- platform: state
entity_id: "binary_sensor.plate01_connected"
to: "on"
- platform: homeassistant
event: start
action:
# Set font and justification for the 4 buttons (b4-b7)
- service: mqtt.publish
data:
topic: "hasp/plate01/command/json"
payload: '["p[3].b[4].font=8","p[3].b[5].font=8","p[3].b[6].font=8","p[3].b[7].font=7","p[3].b[4].xcen=2","p[3].b[5].xcen=2","p[3].b[6].xcen=2","p[3].b[7].xcen=1"]'
# Set text labels for the top 3 buttons (b4-b6)
- service: mqtt.publish
data:
topic: "hasp/plate01/command/json"
payload: '["p[3].b[4].txt=\"Light 1 \"","p[3].b[5].txt=\"Light 2 \"","p[3].b[6].txt=\"Light 3 \""]'
# Toggle light1 when p[3].b[4] pressed
- alias: hasp_plate01_p3_ToggleLight1
trigger:
- platform: mqtt
topic: "hasp/plate01/state/p[3].b[4]"
payload: "ON"
action:
- service: homeassistant.toggle
entity_id: light.light_1
# Toggle light2 when p[3].b[5] pressed
- alias: hasp_plate01_p3_ToggleLight2
trigger:
- platform: mqtt
topic: "hasp/plate01/state/p[3].b[5]"
payload: "ON"
action:
- service: homeassistant.toggle
entity_id: light.light_2
# Toggle light3 when p[3].b[6] pressed
- alias: hasp_plate01_p3_ToggleLight3
trigger:
- platform: mqtt
topic: "hasp/plate01/state/p[3].b[6]"
payload: "ON"
action:
- service: homeassistant.toggle
entity_id: light.light_3
# Toggle all light_toggle_group when p[3].b[7] pressed
- alias: hasp_plate01_p3_ToggleAll
trigger:
- platform: mqtt
topic: "hasp/plate01/state/p[3].b[7]"
payload: "ON"
action:
- service_template: >
{% if states('group.light_toggle_group') == "on" -%}
homeassistant.turn_off
{%- else -%}
homeassistant.turn_on
{%- endif %}
entity_id: group.light_toggle_group
# Toggle colors on p[3].b[4] when light1 changes
- alias: hasp_plate01_p3_ToggleColor1
trigger:
- platform: state
entity_id: light.light_1
- platform: state
entity_id: "binary_sensor.plate01_connected"
to: "on"
- platform: homeassistant
event: start
- platform: state
entity_id: input_number.hasp_plate01_selectedbackgroundcolor
- platform: state
entity_id: input_number.hasp_plate01_unselectedbackgroundcolor
- platform: state
entity_id: input_number.hasp_plate01_selectedforegroundcolor
- platform: state
entity_id: input_number.hasp_plate01_unselectedforegroundcolor
action:
- service: mqtt.publish
data:
topic: "hasp/plate01/command/json"
payload_template: >-
[{% if states('light.light_1') == "on" -%}
"p[3].b[4].bco={{ states('input_number.hasp_plate01_selectedbackgroundcolor') | int }}","p[3].b[4].pco={{ states('input_number.hasp_plate01_selectedforegroundcolor') | int }}"
{%- else -%}
"p[3].b[4].bco={{ states('input_number.hasp_plate01_unselectedbackgroundcolor') | int }}","p[3].b[4].pco={{ states('input_number.hasp_plate01_unselectedforegroundcolor') | int }}"
{%- endif %}]
# Toggle colors on p[3].b[5] when light2 changes
- alias: hasp_plate01_p3_ToggleColor2
trigger:
- platform: state
entity_id: light.light_2
- platform: state
entity_id: "binary_sensor.plate01_connected"
to: "on"
- platform: homeassistant
event: start
- platform: state
entity_id: input_number.hasp_plate01_selectedbackgroundcolor
- platform: state
entity_id: input_number.hasp_plate01_unselectedbackgroundcolor
- platform: state
entity_id: input_number.hasp_plate01_selectedforegroundcolor
- platform: state
entity_id: input_number.hasp_plate01_unselectedforegroundcolor
action:
- service: mqtt.publish
data:
topic: "hasp/plate01/command/json"
payload_template: >-
[{% if states('light.light_2') == "on" -%}
"p[3].b[5].bco={{ states('input_number.hasp_plate01_selectedbackgroundcolor') | int }}","p[3].b[5].pco={{ states('input_number.hasp_plate01_selectedforegroundcolor') | int }}"
{%- else -%}
"p[3].b[5].bco={{ states('input_number.hasp_plate01_unselectedbackgroundcolor') | int }}","p[3].b[5].pco={{ states('input_number.hasp_plate01_unselectedforegroundcolor') | int }}"
{%- endif %}]
# Toggle colors on p[3].b[6] when light3 changes
- alias: hasp_plate01_p3_ToggleColor3
trigger:
- platform: state
entity_id: light.light_3
- platform: state
entity_id: "binary_sensor.plate01_connected"
to: "on"
- platform: homeassistant
event: start
- platform: state
entity_id: input_number.hasp_plate01_selectedbackgroundcolor
- platform: state
entity_id: input_number.hasp_plate01_unselectedbackgroundcolor
- platform: state
entity_id: input_number.hasp_plate01_selectedforegroundcolor
- platform: state
entity_id: input_number.hasp_plate01_unselectedforegroundcolor
action:
- service: mqtt.publish
data:
topic: "hasp/plate01/command/json"
payload_template: >-
[{% if states('light.light_3') == "on" -%}
"p[3].b[6].bco={{ states('input_number.hasp_plate01_selectedbackgroundcolor') | int }}","p[3].b[6].pco={{ states('input_number.hasp_plate01_selectedforegroundcolor') | int }}"
{%- else -%}
"p[3].b[6].bco={{ states('input_number.hasp_plate01_unselectedbackgroundcolor') | int }}","p[3].b[6].pco={{ states('input_number.hasp_plate01_unselectedforegroundcolor') | int }}"
{%- endif %}]
# Set button 4 to "All Lights Off" if any lights are on, otherwise set to "All Lights On"
- alias: hasp_plate01_p3_ToggleColorAll
trigger:
- platform: state
entity_id: group.light_toggle_group
- platform: state
entity_id: "binary_sensor.plate01_connected"
to: "on"
- platform: homeassistant
event: start
- platform: state
entity_id: input_number.hasp_plate01_selectedbackgroundcolor
- platform: state
entity_id: input_number.hasp_plate01_unselectedbackgroundcolor
- platform: state
entity_id: input_number.hasp_plate01_selectedforegroundcolor
- platform: state
entity_id: input_number.hasp_plate01_unselectedforegroundcolor
action:
- service: mqtt.publish
data:
topic: "hasp/plate01/command/json"
payload_template: >-
[{% if states('group.light_toggle_group') == "on" -%}
"p[3].b[7].txt=\"All Lights Off\"","p[3].b[7].bco={{ states('input_number.hasp_plate01_unselectedbackgroundcolor') | int }}","p[3].b[7].pco={{ states('input_number.hasp_plate01_unselectedforegroundcolor') | int }}"
{%- else -%}
"p[3].b[7].txt=\"All Lights On\"","p[3].b[7].bco={{ states('input_number.hasp_plate01_selectedbackgroundcolor') | int }}","p[3].b[7].pco={{ states('input_number.hasp_plate01_selectedforegroundcolor') | int }}"
{%- endif %}]
##############################################################################
# Automations to overlay icons on HASP Page 3
#
# See notes on hasp_plate01_p2_status for details here. To recap:
# * Icons placed w/ `xstr` only apply to the current page, so only attempt
# this while Page 3 is active.
# * Any button interaction (press, release, new text, new color, etc)
# overwrites the icon, so we need to catch these events and put the icon
# back on top.
# * The events we capture take time for the Nextion to process, so insert a
# 1 msec delay command which will allow the Nextion to fully process the
# prior event.
# Overlay a light icon on the left side of p[3].b[4]
- alias: hasp_plate01_p3_Light1Icon
trigger:
- platform: state
entity_id: "binary_sensor.plate01_connected"
to: "on"
- platform: homeassistant
event: start
- platform: mqtt
topic: "hasp/plate01/command/page"
payload: "3"
- platform: state
entity_id: light.light_1
- platform: mqtt
topic: "hasp/plate01/state/p[3].b[4]"
payload: "OFF"
- platform: mqtt
topic: "hasp/plate01/command/p[3].b[4].txt"
- platform: state
entity_id: input_number.hasp_plate01_selectedbackgroundcolor
- platform: state
entity_id: input_number.hasp_plate01_unselectedbackgroundcolor
- platform: state
entity_id: input_number.hasp_plate01_selectedforegroundcolor
- platform: state
entity_id: input_number.hasp_plate01_unselectedforegroundcolor
condition:
condition: and
conditions:
- condition: template
value_template: "{{ (states('input_number.hasp_plate01_activepage')|int) == 3 }}"
action:
- service: mqtt.publish
data:
topic: "hasp/plate01/command/json"
payload_template: >-
[{% if states('light.light_1') == "on" -%}
"delay=1","xstr 0,2,50,65,8,65280,65535,1,1,3,\"\""
{%- else -%}
"delay=1","xstr 0,2,50,65,8,{{ states('input_number.hasp_plate01_unselectedforegroundcolor')|int }},0,1,1,3,\"\""
{%- endif %}]
# Overlay a light icon on the left side of p[3].b[5]
- alias: hasp_plate01_p3_Light2Icon
trigger:
- platform: state
entity_id: "binary_sensor.plate01_connected"
to: "on"
- platform: homeassistant
event: start
- platform: mqtt
topic: "hasp/plate01/command/page"
payload: "3"
- platform: state
entity_id: light.light_2
- platform: mqtt
topic: "hasp/plate01/state/p[3].b[5]"
payload: "OFF"
- platform: mqtt
topic: "hasp/plate01/command/p[3].b[5].txt"
- platform: state
entity_id: input_number.hasp_plate01_selectedbackgroundcolor
- platform: state
entity_id: input_number.hasp_plate01_unselectedbackgroundcolor
- platform: state
entity_id: input_number.hasp_plate01_selectedforegroundcolor
- platform: state
entity_id: input_number.hasp_plate01_unselectedforegroundcolor
condition:
condition: and
conditions:
- condition: template
value_template: "{{ (states('input_number.hasp_plate01_activepage')|int) == 3 }}"
action:
- service: mqtt.publish
data:
topic: "hasp/plate01/command/json"
payload_template: >-
[{% if states('light.light_2') == "on" -%}
"delay=1","xstr 0,69,50,65,8,65280,0,1,1,3,\"\""
{%- else -%}
"delay=1","xstr 0,69,50,65,8,{{ states('input_number.hasp_plate01_unselectedforegroundcolor')|int }},0,1,1,3,\"\""
{%- endif %}]
# Overlay a light icon on the left side of p[3].b[6]
- alias: hasp_plate01_p3_Light3Icon
trigger:
- platform: state
entity_id: "binary_sensor.plate01_connected"
to: "on"
- platform: homeassistant
event: start
- platform: mqtt
topic: "hasp/plate01/command/page"
payload: "3"
- platform: state
entity_id: light.light_3
- platform: mqtt
topic: "hasp/plate01/state/p[3].b[6]"
payload: "OFF"
- platform: mqtt
topic: "hasp/plate01/command/p[3].b[6].txt"
- platform: state
entity_id: input_number.hasp_plate01_selectedbackgroundcolor
- platform: state
entity_id: input_number.hasp_plate01_unselectedbackgroundcolor
- platform: state
entity_id: input_number.hasp_plate01_selectedforegroundcolor
- platform: state
entity_id: input_number.hasp_plate01_unselectedforegroundcolor
condition:
condition: and
conditions:
- condition: template
value_template: "{{ (states('input_number.hasp_plate01_activepage')|int) == 3 }}"
action:
- service: mqtt.publish
data:
topic: "hasp/plate01/command/json"
payload_template: >-
[{% if states('light.light_3') == "on" -%}
"delay=1","xstr 0,136,50,65,8,65280,0,1,1,3,\"\""
{%- else -%}
"delay=1","xstr 0,136,50,65,8,{{ states('input_number.hasp_plate01_unselectedforegroundcolor')|int }},0,1,1,3,\"\""
{%- endif %}]