-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhasp_Display_Weather_Forecast.yaml
331 lines (308 loc) · 15 KB
/
hasp_Display_Weather_Forecast.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
blueprint:
name: "HASP p[x].b[y] displays the weather forecast"
description: |
## Description
A HASP button displays an attribute of a selected weather forecast. You can use this to display tomorrow's condition, or tonight's low temp.
Available forecast conditions will vary by weather provider, check your selected provider's state under `Developer Tools` > `States` to get
a sense of what your selected provider has to offer.
![Preview](https://raw.githubusercontent.com/HASwitchPlate/Blueprints/main/images/hasp_Display_Weather_Forecast.png)
### 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 |
### 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_Weather_Forecast.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) for the forecast. 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 forecast. Refer to the HASP Page and Button reference above."
default: 4
selector:
number:
min: 4
max: 15
mode: slider
weather_provider:
name: "Weather provider"
description: "Select the weather provider to obtain the forecast"
selector:
entity:
domain: weather
forecast_index:
name: "Forecast index"
description: 'Weather forecasts are provided at intervals determined by your weather source. The next time interval will be index "0". Increment this number for future forecasts'
default: 0
selector:
number:
min: 0
max: 10
mode: slider
forecast_attribute:
name: "Enter the desired forecast attribute"
description: 'Type in the name of the desired forecast attribute for your provider. "condition" is a common attribute for many providers.'
default: "condition"
selector:
text:
prefix:
name: "Forecast display prefix"
description: 'Prefix for forecast display, maybe something like "tonight: " or "tomorrow: ". Leave blank for no prefix.'
default: "none"
selector:
text:
font:
name: "Forecast Font"
description: "Select the font for the forecast:"
default: 6
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"
default: false
description: "Enable line-wrapping text if too long to fit in the button."
selector:
boolean:
title_case:
name: "Title Case"
description: "Apply The Title Case Filter To Capitalize The First Character Of Each Word In The Result"
default: true
selector:
boolean:
mode: parallel
max_exceeded: silent
variables:
haspconnected: !input haspconnected
haspname: '{{ haspconnected.split(".")[1].split("_connected")[0] }}'
hasppage: !input hasppage
haspbutton: !input haspbutton
weather_provider: !input weather_provider
forecast_index: !input forecast_index
forecast_attribute: !input forecast_attribute
prefix: !input prefix
font: !input font
xcen: !input xcen
ycen: !input ycen
wrap: !input wrap
title_case: !input title_case
haspobject: '{{ "p[" ~ hasppage ~ "].b[" ~ haspbutton ~ "]" }}'
commandtopic: '{{ "hasp/" ~ haspname ~ "/command/" ~ haspobject }}'
jsoncommandtopic: '{{ "hasp/" ~ haspname ~ "/command/json" }}'
text: '{% if prefix|lower != "none" %}{{prefix}}{% endif %}{% if title_case %}{{state_attr(weather_provider, "forecast")[forecast_index|int].get(forecast_attribute)|title}}{% else %}{{state_attr(weather_provider, "forecast")[forecast_index|int].get(forecast_attribute)}}{% endif %}'
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 weather_provider
- 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 attribute 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 forecast if our weather provider changed state
- conditions:
- condition: template
value_template: '{{ (trigger.platform == "state") and (trigger.entity_id == weather_provider) }}'
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 forecast 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}}\""
]