-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhasp_Display_Template.yaml
320 lines (289 loc) · 14.4 KB
/
hasp_Display_Template.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
blueprint:
name: "HASP p[x].b[y] displays the output of a template"
description: |
# Description
A button on the HASP will display the output of a template. The template is updated when the state of a selected entity updates.
![Preview](https://raw.githubusercontent.com/HASwitchPlate/Blueprints/main/images/hasp_Display_Template.png)
## Examples
<details>
### Show tomorrow's high/low temperature from Met.no
**Trigger entity:** The default Met.no provider from Home Assistant. If you left your location named "Home", the entity should be `weather.home`
**Template:** `Tomorrow\\rHigh: {{state_attr(trigger_entity, "forecast")[0].temperature|int}} Low: {{state_attr(trigger_entity, "forecast")[0].templow|int}}`
**Font:** `6`
</details>
## HASP Page and Button reference
<details>
| Page 0 | Pages 1-3 | Pages 4-5 |
|--------|-----------|-----------|
| ![Page 0](https://raw.githubusercontent.com/HASwitchPlate/Blueprints/main/images/NextionUI_p0_Init_Screen.png) | ![Pages 1-3](https://raw.githubusercontent.com/HASwitchPlate/Blueprints/main/images/NextionUI_p1-p3_4buttons.png) | ![Pages 4-5](https://raw.githubusercontent.com/HASwitchPlate/Blueprints/main/images/NextionUI_p4-p5_3sliders.png) |
| Page 6 | Page 7 | Page 8 |
|--------|--------|--------|
| ![Page 6](https://raw.githubusercontent.com/HASwitchPlate/Blueprints/main/images/NextionUI_p6_8buttons.png) | ![Page 7](https://raw.githubusercontent.com/HASwitchPlate/Blueprints/main/images/NextionUI_p7_12buttons.png) | ![Page 8](https://raw.githubusercontent.com/HASwitchPlate/Blueprints/main/images/NextionUI_p8_5buttons+1slider.png) |
| Page 9 | Page 10 | Page 11 |
|--------|---------|---------|
| ![Page 9](https://raw.githubusercontent.com/HASwitchPlate/Blueprints/main/images/NextionUI_p9_9buttons.png) | ![Page 10](https://raw.githubusercontent.com/HASwitchPlate/Blueprints/main/images/NextionUI_p10_5buttons.png) | ![Page 11](https://raw.githubusercontent.com/HASwitchPlate/Blueprints/main/images/NextionUI_p11_1button.png)
</details>
## HASP Font reference
<details>
The Nextion display supports monospaced and proportional fonts. For monospace fonts, the HASP project includes [Consolas](https://docs.microsoft.com/en-us/typography/font-list/consolas) in 4 sizes and [Webdings](https://en.wikipedia.org/wiki/Webdings#Character_set) in 1 size.
| Number | Font | Characters per line | Lines per button |
|--------|-------------------|---------------------|------------------|
| 0 | Consolas 24 point | 20 characters | 2 lines |
| 1 | Consolas 32 point | 15 characters | 2 lines |
| 2 | Consolas 48 point | 10 characters | 1 lines |
| 3 | Consolas 80 point | 6 characters | 1 lines |
| 4 | Webdings 56 point | 8 characters | 1 lines |
The HASP also includes [Google's "Noto Sans"](https://github.com/googlefonts/noto-fonts) proportional font in 5 sizes.
| Number | Font |
|--------|----------------------------|
| 5 | Noto Sans Regular 24 point |
| 6 | Noto Sans Regular 32 point |
| 7 | Noto Sans Regular 48 point |
| 8 | Noto Sans Regular 64 point |
| 9 | Noto Sans Regular 80 point |
| 10 | Noto Sans Bold 80 point |
### Icons
Fonts 5-10 also include [1400+ icons which you can copy and paste from here](https://htmlpreview.github.io/?https://github.com/aderusha/HASwitchPlate/blob/master/Documentation/Images/hasp-fontawesome5.html)
### Font examples
![HASP Fonts 0-3](https://raw.githubusercontent.com/HASwitchPlate/Blueprints/main/images/NextionUI_Fonts_0-3.png) ![HASP Fonts 4-7](https://raw.githubusercontent.com/HASwitchPlate/Blueprints/main/images/NextionUI_Fonts_4-7.png) ![HASP Fonts 8-10](https://raw.githubusercontent.com/HASwitchPlate/Blueprints/main/images/NextionUI_Fonts_8-10.png)
</details>
source_url: "https://github.com/HASwitchPlate/Blueprints/blob/main/hasp_Display_Template.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-11). Refer to the HASP Page and Button reference above."
default: 1
selector:
number:
min: 1
max: 11
mode: slider
haspbutton:
name: "HASP Button"
description: "Select the HASP button (4-15) for the template display. Refer to the HASP Page and Button reference above."
default: 4
selector:
number:
min: 4
max: 15
mode: slider
trigger_entity:
name: "Select an entity to trigger template update"
description: "Update the displayed template when the state or attributes of the selected entity update."
selector:
entity:
template:
name: "Template to output"
description: "Enter a well-formed Home Assistant template string"
default: 'Forecast: {{state_attr("weather.home", "forecast")[0].condition|title}}'
selector:
text:
font:
name: "Font"
description: "Select the font for the displayed text. Refer to the HASP Font reference above.:"
default: 7
selector:
number:
min: 0
max: 10
mode: slider
xcen:
name: "Text horizontal alignment"
description: "Horizontal text alignment: 0=Left 1=Center 2=Right"
default: 1
selector:
number:
min: 0
max: 2
mode: slider
ycen:
name: "Text vertical alignment"
description: "Vertical text alignment: 0=Top 1=Center 2=Bottom"
default: 1
selector:
number:
min: 0
max: 2
mode: slider
wrap:
name: "Text wrap"
description: "Enable line-wrapping text if too long to fit in the button."
default: false
selector:
boolean:
mode: parallel
max_exceeded: silent
variables:
haspconnected: !input haspconnected
haspname: '{{ haspconnected.split(".")[1].split("_connected")[0] }}'
hasppage: !input hasppage
haspbutton: !input haspbutton
trigger_entity: !input trigger_entity
text: !input template
font: !input font
xcen: !input xcen
ycen: !input ycen
wrap: !input wrap
haspobject: '{{ "p[" ~ hasppage ~ "].b[" ~ haspbutton ~ "]" }}'
commandtopic: '{{ "hasp/" ~ haspname ~ "/command/" ~ haspobject }}'
jsoncommandtopic: '{{ "hasp/" ~ haspname ~ "/command/json" }}'
isbr: "{% if wrap == true %}1{% else %}0{% endif %}"
selectedforegroundcolortopic: '{{ "hasp/" ~ haspname ~ "/light/selectedforegroundcolor/rgb" }}'
selectedbackgroundcolortopic: '{{ "hasp/" ~ haspname ~ "/light/selectedbackgroundcolor/rgb" }}'
unselectedforegroundcolortopic: '{{ "hasp/" ~ haspname ~ "/light/unselectedforegroundcolor/rgb" }}'
unselectedbackgroundcolortopic: '{{ "hasp/" ~ haspname ~ "/light/unselectedbackgroundcolor/rgb" }}'
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 }}
trigger:
- platform: state
entity_id: !input haspconnected
to: "on"
- platform: homeassistant
event: start
- platform: state
entity_id: !input trigger_entity
- 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:
#########################################################################
# Display template and apply text 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={{xcen}}",
"{{haspobject}}.ycen={{ycen}}",
"{{haspobject}}.isbr={{isbr}}",
"{{haspobject}}.pco={{selectedfg}}",
"{{haspobject}}.bco={{selectedbg}}",
"{{haspobject}}.pco2={{unselectedfg}}",
"{{haspobject}}.bco2={{unselectedbg}}",
"{{haspobject}}.txt=\"{{text}}\""
]
#########################################################################
# Update display if our entity has changed state
- conditions: # Update display if our entity has changed state
- condition: template
value_template: '{{ (trigger.platform == "state") and (trigger.entity_id == trigger_entity) }}'
sequence:
- service: mqtt.publish
data:
topic: "{{commandtopic}}.txt"
payload: '"{{text}}"'
#########################################################################
# Catch triggers fired by incoming MQTT messages
- conditions:
- condition: template
value_template: '{{ trigger.platform == "mqtt" }}'
sequence:
- choose:
#########################################################################
# Theme: Apply selected foreground color on change
- conditions:
- condition: template
value_template: "{{ trigger.topic == selectedforegroundcolortopic }}"
sequence:
- service: mqtt.publish
data:
topic: "{{commandtopic}}.pco"
payload: "{{trigger.payload}}"
#########################################################################
# 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}}"
#########################################################################
# 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}}"
#########################################################################
# 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}}"
#########################################################################
# Catch remaining triggers to display template and apply text style
default:
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: >-
[
"{{haspobject}}.font={{font}}",
"{{haspobject}}.xcen={{xcen}}",
"{{haspobject}}.ycen={{ycen}}",
"{{haspobject}}.isbr={{isbr}}",
"{{haspobject}}.pco={{selectedfg}}",
"{{haspobject}}.bco={{selectedbg}}",
"{{haspobject}}.pco2={{unselectedfg}}",
"{{haspobject}}.bco2={{unselectedbg}}",
"{{haspobject}}.txt=\"{{text}}\""
]