-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhasp_Display_Calendar_with_Icon.yaml
286 lines (271 loc) · 13.9 KB
/
hasp_Display_Calendar_with_Icon.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
blueprint:
name: "HASP p[x].b[y] displays the month + date with a calendar icon"
description: |
# Description
A HASP button displays month + date on the right with a calendar icon on the left.
![Preview](https://raw.githubusercontent.com/HASwitchPlate/Blueprints/main/images/hasp_Display_Calendar_with_Icon.png)
## HASP Page and Button reference
<details>
This automation is designed to work with the full-width buttons found on pages 1-3
| Pages 1-3 |
|-----------|
| ![Pages 1-3](https://raw.githubusercontent.com/HASwitchPlate/Blueprints/main/images/NextionUI_p1-p3_4buttons.png) |
</details>
source_url: "https://github.com/HASwitchPlate/Blueprints/blob/main/hasp_Display_Calendar_with_Icon.yaml"
domain: automation
input:
haspconnected:
name: "HASP Device"
description: "Select the HASP device"
selector:
entity:
integration: mqtt
domain: binary_sensor
device_class: connectivity
hasppage:
name: "HASP Page"
description: "Select the HASP page (1-3) for the calendar. Refer to the HASP Page and Button reference above."
default: 1
selector:
number:
min: 1
max: 3
mode: slider
haspbutton:
name: "HASP Button"
description: "Select the HASP button (4-7) for the calendar. Refer to the HASP Page and Button reference above."
default: 4
selector:
number:
min: 4
max: 7
mode: slider
mode: parallel
max_exceeded: silent
variables:
haspconnected: !input haspconnected
haspname: '{{ haspconnected.split(".")[1].split("_connected")[0] }}'
hasppage: !input hasppage
haspbutton: !input haspbutton
haspobject: '{{ "p[" ~ hasppage ~ "].b[" ~ haspbutton ~ "]" }}'
commandtopic: '{{ "hasp/" ~ haspname ~ "/command/" ~ haspobject }}'
jsontopic: '{{ "hasp/" ~ haspname ~ "/state/json" }}'
jsoncommandtopic: '{{ "hasp/" ~ haspname ~ "/command/json" }}'
selectedforegroundcolortopic: '{{ "hasp/" ~ haspname ~ "/light/selectedforegroundcolor/rgb" }}'
selectedbackgroundcolortopic: '{{ "hasp/" ~ haspname ~ "/light/selectedbackgroundcolor/rgb" }}'
unselectedforegroundcolortopic: '{{ "hasp/" ~ haspname ~ "/light/unselectedforegroundcolor/rgb" }}'
unselectedbackgroundcolortopic: '{{ "hasp/" ~ haspname ~ "/light/unselectedbackgroundcolor/rgb" }}'
activepage: '{% set activepage_entity = "number." ~ haspname ~ "_active_page" %}{% if states(activepage_entity)|lower == "none" %}-1{% else %}{{ states(activepage_entity) | int }}{% endif %}'
selectedfg: >-
{%- set colorsource="light." ~ haspname ~ "_selected_foreground_color" -%}
{%- set brightness = state_attr(colorsource, "brightness")|int / 255 -%}
{%- set red=(state_attr(colorsource, "rgb_color")[0] * brightness)|int -%}
{%- set green=(state_attr(colorsource, "rgb_color")[1] * brightness)|int -%}
{%- set blue=(state_attr(colorsource, "rgb_color")[2] * brightness)|int -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
selectedbg: >-
{%- set colorsource="light." ~ haspname ~ "_selected_background_color" -%}
{%- set brightness = state_attr(colorsource, "brightness")|int / 255 -%}
{%- set red=(state_attr(colorsource, "rgb_color")[0] * brightness)|int -%}
{%- set green=(state_attr(colorsource, "rgb_color")[1] * brightness)|int -%}
{%- set blue=(state_attr(colorsource, "rgb_color")[2] * brightness)|int -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
unselectedfg: >-
{%- set colorsource="light." ~ haspname ~ "_unselected_foreground_color" -%}
{%- set brightness = state_attr(colorsource, "brightness")|int / 255 -%}
{%- set red=(state_attr(colorsource, "rgb_color")[0] * brightness)|int -%}
{%- set green=(state_attr(colorsource, "rgb_color")[1] * brightness)|int -%}
{%- set blue=(state_attr(colorsource, "rgb_color")[2] * brightness)|int -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
unselectedbg: >-
{%- set colorsource="light." ~ haspname ~ "_unselected_background_color" -%}
{%- set brightness = state_attr(colorsource, "brightness")|int / 255 -%}
{%- set red=(state_attr(colorsource, "rgb_color")[0] * brightness)|int -%}
{%- set green=(state_attr(colorsource, "rgb_color")[1] * brightness)|int -%}
{%- set blue=(state_attr(colorsource, "rgb_color")[2] * brightness)|int -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
text: '{{(now().strftime("%b "))~now().day}}'
font: 9
ypos: "{{(haspbutton|int - 4) * 67 + 2}}" # calculate the top pixel position based on the selected button
xpos: 0
icon: ""
iconwidth: 50
iconheight: 65
iconfont: 8
trigger:
- platform: state
entity_id: !input haspconnected
to: "on"
- platform: homeassistant
event: start
- platform: time
at: "00:00:00"
- platform: mqtt
topic: "hasp/+/state/json"
- platform: mqtt
topic: "hasp/+/light/selectedforegroundcolor/rgb"
- platform: mqtt
topic: "hasp/+/light/selectedbackgroundcolor/rgb"
- platform: mqtt
topic: "hasp/+/light/unselectedforegroundcolor/rgb"
- platform: mqtt
topic: "hasp/+/light/unselectedbackgroundcolor/rgb"
condition:
- condition: state
entity_id: !input haspconnected
state: "on"
action:
- choose:
#########################################################################
# Apply text and style when "EXECUTE" is pressed by the user
- conditions:
- condition: template
value_template: "{{ trigger is not defined }}"
sequence:
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: >-
["{{haspobject}}.font={{font}}",
"{{haspobject}}.xcen=2",
"{{haspobject}}.ycen=1",
"{{haspobject}}.pco={{selectedfg}}",
"{{haspobject}}.bco={{selectedbg}}",
"{{haspobject}}.pco2={{unselectedfg}}",
"{{haspobject}}.bco2={{unselectedbg}}",
"{{haspobject}}.txt=\"{{text}} \""
{%- if activepage|int == hasppage|int -%}
,"delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""
{%- endif -%}]
#########################################################################
# Update the calendar text every day at midnight. If the selected page is currently active, also place the icon.
- conditions: #
- condition: template
value_template: '{{ trigger.platform == "time" }}'
sequence:
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: >-
["{{haspobject}}.txt=\"{{text}} \""
{%- if activepage|int == hasppage|int -%}
,"delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""
{%- endif -%}]
#########################################################################
# Catch MQTT events
- conditions:
- condition: template
value_template: '{{ trigger.platform == "mqtt" }}'
sequence:
- choose:
#########################################################################
# Catch incoming JSON messages
- conditions:
- condition: template
value_template: "{{ (trigger.topic == jsontopic) and trigger.payload_json is defined }}"
sequence:
- choose:
#########################################################################
# Icon overlay
- conditions: # Somebody pressed our button which hides the overlaid icon. Put it back.
- condition: template
value_template: '{{ (trigger.topic == jsontopic ) and (trigger.payload_json.event == haspobject ) and (trigger.payload_json.value == "OFF") }}'
sequence:
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""]'
- conditions: # Page changed to our page, so place the icon on the screen.
- condition: template
value_template: '{{ (trigger.topic == jsontopic ) and (trigger.payload_json.event == "page" ) and (trigger.payload_json.value == hasppage|int) }}'
sequence:
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""]'
#########################################################################
# Theme: Apply selected foreground color when it changes.
# Any change to the button will remove the overlaid icon.
- conditions:
- condition: template
value_template: "{{ trigger.topic == selectedforegroundcolortopic }}"
sequence:
- service: mqtt.publish
data:
topic: "{{commandtopic}}.pco"
payload: "{{trigger.payload}}"
- condition: template
value_template: "{{ activepage|int == hasppage|int }}"
- delay: "00:00:00.5"
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{trigger.payload}},0,1,1,3,\"{{icon}}\""]'
#########################################################################
# Theme: Apply selected background color on change
- conditions:
- condition: template
value_template: "{{ trigger.topic == selectedbackgroundcolortopic }}"
sequence:
- service: mqtt.publish
data:
topic: "{{commandtopic}}.bco"
payload: "{{trigger.payload}}"
- condition: template
value_template: "{{ activepage|int == hasppage|int }}"
- delay: "00:00:00.5"
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""]'
#########################################################################
# Theme: Apply unselected foreground color on change
- conditions:
- condition: template
value_template: "{{ trigger.topic == unselectedforegroundcolortopic }}"
sequence:
- service: mqtt.publish
data:
topic: "{{commandtopic}}.pco2"
payload: "{{trigger.payload}}"
- condition: template
value_template: "{{ activepage|int == hasppage|int }}"
- delay: "00:00:00.5"
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""]'
#########################################################################
# Theme: Apply unselected background color on change
- conditions:
- condition: template
value_template: "{{ trigger.topic == unselectedbackgroundcolortopic }}"
sequence:
- service: mqtt.publish
data:
topic: "{{commandtopic}}.bco2"
payload: "{{trigger.payload}}"
- condition: template
value_template: "{{ activepage|int == hasppage|int }}"
- delay: "00:00:00.5"
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""]'
# Catch any other trigger conditions, apply styles, place text, and then place icon if our target page is currently active
default:
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: >-
["{{haspobject}}.font={{font}}",
"{{haspobject}}.xcen=2",
"{{haspobject}}.ycen=1",
"{{haspobject}}.pco={{selectedfg}}",
"{{haspobject}}.bco={{selectedbg}}",
"{{haspobject}}.pco2={{unselectedfg}}",
"{{haspobject}}.bco2={{unselectedbg}}",
"{{haspobject}}.txt=\"{{text}} \""
{%- if activepage|int == hasppage|int -%}
,"delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""
{%- endif -%}]