-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathweather_forecast.yaml
480 lines (456 loc) · 34.7 KB
/
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
# Sensors
template:
- sensor:
- name: Local forecast
state: >
{# -----> Language: 0 = German ; 1 = English ; 2 = Ελληνικά <----- #}
{%set title = ["Lokale Wettervorhersage","12hr Local Weather Forecast","Τοπική πρόγνωση καιρού"]%}
{{title[1]}}
attributes:
language: >
{# -----> Language: 0 = German ; 1 = English ; 2 = Ελληνικά <----- #}
{% set language = 1%}{{language}}
temperature: >
{# -----> set temperature in xx.x°C (only when pressure_sea = 0) <-----#}
{% set temp = states.sensor.weatherstation_temperature.state|float(1)%}
{{temp}}
p0: >
{# -----> pressure sensor in xxxx.xxhPa (needed) <----- #}
{% set pressure = states.sensor.weatherstation_barometer_absolute.state|float(0)%}
{# -----> pressure at sealevel: set to 1 else set to 0 (needed) <-----#}
{% set pressure_sea = 0%}
{# -----> set height above sealevel in meters (only when pressure_sea = 0) <-----#}
{% set height = 370%}
{# Calc pressure at sealevel -> p0 (if necessary)#}
{% set temp = states.sensor.local_forecast.attributes.temperature|float(1)%}
{% set p0 = pressure*pressure_sea-(pressure_sea-1)*pressure*(1-((0.0065*height)/(temp+(0.0065*height)+273.15)))**(-5.257)%}
{{p0|round(1)}}
wind_direction: >
{# -----> set wind direction in degrees (optional, else 0) <----- #}
{% set wind_dir = states.sensor.weatherstation_wind_direction.state|int(0)%}
{# -----> set average wind speed in km/h (optional, else 0) <----- #}
{%set wind_speed = states.sensor.weatherstation_wind_speed.state|float(0)%}
{# ----------------------------------------------- Config end ----------------------------------------------- #}
{# is there even wind? #}
{%if wind_speed < 1%}{#calm#}{%set wind_speed_fak = 0%}
{%else%}{#wind#}{%set wind_speed_fak = 1%}
{%endif%}
{# Calc. wind bearing N or S #}
{% if wind_dir >=135 and wind_dir <=225%}
{% set wind_fak = 2%}{#Wind from south#}
{% elif wind_dir >= 315 or wind_dir <= 45 %}
{% set wind_fak = 0%}{#Wind from west or east#}
{%else%}
{% set wind_fak = 1%}{% set wind_text = "N"%}
{%endif%}
{% set dir = wind_dir|float %}
{% if 11.25 < dir <= 33.75 %}{% set dir_text = "N"%}
{% elif 33.75 < dir <= 56.25 %}{% set dir_text = "NE"%}
{% elif 56.25 < dir <= 78.75 %}{% set dir_text = "ENE"%}
{% elif 78.75 < dir <= 101.25 %}{% set dir_text = "E"%}
{% elif 101.25 < dir <= 123.75 %}{% set dir_text = "ESE"%}
{% elif 123.75 < dir <= 146.25 %}{% set dir_text = "SE"%}
{% elif 146.25 < dir <= 168.75 %}{% set dir_text = "SSE"%}
{% elif 168.75 < dir <= 191.25 %}{% set dir_text = "S"%}
{% elif 191.25 < dir <= 213.75 %}{% set dir_text = "SSW"%}
{% elif 213.75 < dir <= 236.25 %}{% set dir_text = "SW"%}
{% elif 236.25 < dir <= 258.75 %}{% set dir_text = "WSW"%}
{% elif 258.75 < dir <= 281.25 %}{% set dir_text = "W"%}
{% elif 281.25 < dir <= 303.75 %}{% set dir_text = "WNW"%}
{% elif 303.75 < dir <= 326.25 %}{% set dir_text = "NW"%}
{% elif 326.25 < dir <= 348.75 %}{% set dir_text = "NNW"%}
{% else %}{% set dir_text = "N"%}
{% endif %}
{{[wind_fak,dir,dir_text,wind_speed_fak]}}
forecast_short_term: >
{# Calc. current conditions #}
{%set language = states.sensor.local_forecast.attributes.language|int(0)%}
{%set conditions = [('stürmisch','Stormy','θυελλώδης','Tempestoso'),('regnerisch','Rainy','Βροχερός','Piovoso'),('wechselhaft','Mixed','Μεταβλητός','Variabile'),('sonnig','Sunny','Ηλιόλουστος','Soleggiato'),('sehr trocken','Extra Dry','Πολύ ξηρός','Molto Secco')]%}
{%set pressure_system = [('Tiefdruckgebiet','Low Pressure System','σύστημα χαμηλής πίεσης','Bassa Pressione'),('Normal','Normal','φυσιολογικός','Normale'),('Hochdruckgebiet','High Pressure System','σύστημα υψηλής πίεσης','Zona Alta Pressione')]%}
{%set p0 = states.sensor.local_forecast.attributes.p0|float(0)%}
{% if p0<980 %}
{% set current_condtion = [conditions[0][language],pressure_system[0][language]]%}
{% elif p0>=980 and p0<1000 %}
{% set current_condtion = [conditions[1][language],pressure_system[0][language]]%}
{% elif p0>=1000 and p0<1020 %}
{% set current_condtion = [conditions[2][language],pressure_system[1][language]]%}
{% elif p0>=1020 and p0<1040 %}
{% set current_condtion = [conditions[3][language],pressure_system[2][language]]%}
{% elif p0>=1040 %}
{% set current_condtion = [conditions[4][language],pressure_system[2][language]]%}
{%endif%}
{{current_condtion}}
forecast_zambretti: >
{# get specific forecast num based on pressure trend #}
{%set p0 = states.sensor.local_forecast.attributes.p0|float(0)%}
{%set p0change = states.sensor.local_forecast_pressurechange.state|float(0)%}
{%set windfak = states.sensor.local_forecast.attributes.wind_direction[0]|int(0)%}
{%set windfak_speed = states.sensor.local_forecast.attributes.wind_direction[3]|int(0)%}
{%if p0change<=(-1.0) %}{%set trend = '-1'%}{%elif p0change>=(1.0) %}{%set trend = '1'%}{%else%}{%set trend = '0'%}{%endif%}
{# Calc. forecast #}
{%if trend == '-1' %} {# falling pressure#}
{%set z = (127-0.12*p0)|round(0)|int(0)%}
{%elif trend == '0'%} {# steady pressure#}
{%set z = (144-0.13*p0)|round(0)|int(0)%}
{# winter and summer adjustment #}
{%if 2 < now().month < 11%}
{%set z = z%}{#summer#}{%else%}
{%set z = z-1%} {#winter#}{%endif%}
{%elif trend == '1'%} {# rising pressure#}
{%set z = (185-0.16*p0)|round(0)|int(0)%}
{%if 2 < now().month < 11%}
{%set z = z+1%}{#summer#}{%else%}
{%set z = z%} {#winter#}{%endif%}
{%endif%}
{# wind factor #}
{%set z = (z + windfak*windfak_speed) %}
{# generate report #}
{%set language = states.sensor.local_forecast.attributes.language|int(0)%}
{%set t_lang = [('Beständiges Schönwetter!','Settled Fine','Σταθερός καλός καιρός!'),('Schönes Wetter!','Fine','Ωραίος καιρός!'),('Es wird schöner.','Becoming Fine','Θα καλυτερεύσει.'),('Schön, wird wechselhaft.','Fine, Becoming Less Settled','Μεταβλητός.'),('Schön, Regenschauer möglich.','Fine, Possibly showers','Πιθανή βροχή.'),('Heiter bis wolkig, Besserung zu erwarten.','Fairly Fine, Improving','Αίθριος έως νεφελώδης, αναμένεται βελτίωση.'),('Heiter bis wolkig, anfangs evtl. Schauer.','Fairly Fine, Possibly Showers, Early','Αίθριος έως συννεφιασμένος, πιθανώς βροχές στην αρχή.'),('Heiter bis wolkig, später Regen.','Fairly Fine, Showery Later','Αίθριος έως συννεφιασμένος, αργότερα βροχή.'),('Anfangs noch Schauer, dann Besserung.','Showery Early, Improving','Βροχόπτωση στην αρχή και μετά βελτίωση.'),('Wechselhaft mit Schauern','Changeable, Mending','Εναλλαγή με βροχόπτωση.'),('Heiter bis wolkig, vereinzelt Regen.','Fairly Fine , Showers Likely','Αίθριος έως συννεφιασμένος, κατά διαστήματα βροχή.'),('Unbeständig, später Aufklarung.','Rather Unsettled, Clearing Later','Ασταθής, αργότερα καθάρος.'),('Unbeständig, evtl. Besserung.','Unsettled, Probably Improving','Ασταθής, πιθανώς βελτίωση.'),('Regnerisch mit heiteren Phasen.','Showery, Bright Intervals','Καθαρός με διαστήματα βροχής.'),('Regnerisch, wird unbeständiger.','Showery, Becoming More Unsettled','Βροχερό, όλο και πιο ασταθές.'),('Wechselhaft mit etwas Regen.','Changeable, Some Rain','Αλλάζει με λίγη βροχή.'),('Unbeständig mit heiteren Phasen.','Unsettled, Short Fine Intervals','Άστατα, μικρά καθαρά διαστήματα'),('Unbeständig, später Regen.','Unsettled, Rain Later','Άστατη, αργότερα βροχή.'),('Unbeständig mit etwas Regen.','Unsettled, Rain At Times','Άστατος με λίγη βροχή.'),('Wechselhaft und regnerisch','Very Unsettled, Finer At Times','Μεταβλητός και βροχερός.'),('Gelegentlich Regen, Verschlechterung.','Rain At Times, Worse Later','Περιστασιακές βροχές, επιδείνωση.'),('Zuweilen Regen, sehr unbeständig.','Rain At Times, Becoming Very Unsettled','Βροχή κατά περιόδους, πολύ ασταθής.'),('Häufiger Regen.','Rain At Frequent Intervals','Συχνή βροχή.'),('Regen, sehr unbeständig.','Very Unsettled, Rain','Βροχή, πολύ ασταθής.'),('Stürmisch, evtl. Besserung.','Stormy, Possibly Improving','Θυελλώδης, πιθανώς βελτίωση.'),('Stürmisch mit viel Regen.','Stormy, Much Rain','Καταιγίδα με πολλές βροχές.')]%}
{%if z==0 %}{%set type = "none"%}
{%elif z in [1,10,20] %}{%set type = 0%}
{%elif z in [2,11,21] %}{%set type = 1%}
{%elif z in [11] %}{%set type = 2%}
{%elif z in [3] %}{%set type = 3%}
{%elif z in [12] %}{%set type = 4%}
{%elif z in [23] %}{%set type = 5%}
{%elif z in [24] %}{%set type = 6%}
{%elif z in [4] %}{%set type = 7%}
{%elif z in [25] %}{%set type = 8%}
{%elif z in [26] %}{%set type = 9%}
{%elif z in [13] %}{%set type = 10%}
{%elif z in [27] %}{%set type = 11%}
{%elif z in [28] %}{%set type = 12%}
{%elif z in [14] %}{%set type = 13%}
{%elif z in [5] %}{%set type = 14%}
{%elif z in [15] %}{%set type = 15%}
{%elif z in [29] %}{%set type = 16%}
{%elif z in [6] %}{%set type = 17%}
{%elif z in [16] %}{%set type = 18%}
{%elif z in [30] %}{%set type = 19%}
{%elif z in [7] %}{%set type = 20%}
{%elif z in [8] %}{%set type = 21%}
{%elif z in [17] %}{%set type = 22%}
{%elif z in [9,18] %}{%set type = 23%}
{%elif z in [31] %}{%set type = 24%}
{%elif z in [19,32] %}{%set type = 25%}
{%endif%}
{%if z==0 %}{%set type_l = "none"%}
{%elif z in [1,10,20] %}{%set type_l = "A"%}
{%elif z in [2,11,21] %}{%set type_l = "B"%}
{%elif z in [11] %}{%set type_l = "C"%}
{%elif z in [3] %}{%set type_l = "D"%}
{%elif z in [12] %}{%set type_l = "E"%}
{%elif z in [23] %}{%set type_l = "F"%}
{%elif z in [24] %}{%set type_l = "G"%}
{%elif z in [4] %}{%set type_l = "H"%}
{%elif z in [25] %}{%set type_l = "I"%}
{%elif z in [26] %}{%set type_l = "J"%}
{%elif z in [13] %}{%set type_l = "K"%}
{%elif z in [27] %}{%set type_l = "L"%}
{%elif z in [28] %}{%set type_l = "M"%}
{%elif z in [14] %}{%set type_l = "N"%}
{%elif z in [5] %}{%set type_l = "O"%}
{%elif z in [15] %}{%set type_l = "P"%}
{%elif z in [29] %}{%set type_l = "Q"%}
{%elif z in [6] %}{%set type_l = "R"%}
{%elif z in [16] %}{%set type_l = "S"%}
{%elif z in [30] %}{%set type_l = "T"%}
{%elif z in [7] %}{%set type_l = "U"%}
{%elif z in [8] %}{%set type_l = "V"%}
{%elif z in [17] %}{%set type_l = "W"%}
{%elif z in [9,18] %}{%set type_l = "X"%}
{%elif z in [31] %}{%set type_l = "Y"%}
{%elif z in [19,32] %}{%set type_l = "Z"%}
{%endif%}
{{[t_lang[type|int(9)][language],type,type_l]}}{#text,0-25 the higher the worse#}
forecast_neg_zam: >
{##}
{# Negretti and Zambras 'slide rule' algorithm #}
{##}
{# local vars #}
{%set hem = 1%} {#Northern = 1 Southern = 0#}
{%set bar_top = 1050%}
{%set bar_bottom = 950%}
{%set rise_opt = [25,25,25,24,24,19,16,12,11,9,8,6,5,2,1,1,0,0,0,0,0,0]%}
{%set steady_opt = [25,25,25,25,25,25,23,23,22,18,15,13,10,4,1,1,0,0,0,0,0,0]%}
{%set fall_opt = [25,25,25,25,25,25,25,25,23,23,21,20,17,14,7,3,1,1,1,0,0,0]%}
{%set p0 = states.sensor.local_forecast.attributes.p0|float(0)%}
{%set p0change = states.sensor.local_forecast_pressurechange.state|float(0)%}
{%set dir = states.sensor.local_forecast.attributes.wind_direction[1]|int(0) %}
{%set windfak_speed = states.sensor.local_forecast.attributes.wind_direction[3]|int(0)%}
{%set t_lang = [('Beständiges Schönwetter!','Settled Fine','Σταθερός καλός καιρός!'),('Schönes Wetter!','Fine','Ωραίος καιρός!'),('Es wird schöner.','Becoming Fine','Θα καλυτερεύσει.'),('Schön, wird wechselhaft.','Fine, Becoming Less Settled','Μεταβλητός.'),('Schön, Regenschauer möglich.','Fine, Possibly showers','Πιθανή βροχή.'),('Heiter bis wolkig, Besserung zu erwarten.','Fairly Fine, Improving','Αίθριος έως νεφελώδης, αναμένεται βελτίωση.'),('Heiter bis wolkig, anfangs evtl. Schauer.','Fairly Fine, Possibly Showers, Early','Αίθριος έως συννεφιασμένος, πιθανώς βροχές στην αρχή.'),('Heiter bis wolkig, später Regen.','Fairly Fine, Showery Later','Αίθριος έως συννεφιασμένος, αργότερα βροχή.'),('Anfangs noch Schauer, dann Besserung.','Showery Early, Improving','Βροχόπτωση στην αρχή και μετά βελτίωση.'),('Wechselhaft mit Schauern','Changeable, Mending','Εναλλαγή με βροχόπτωση.'),('Heiter bis wolkig, vereinzelt Regen.','Fairly Fine , Showers Likely','Αίθριος έως συννεφιασμένος, κατά διαστήματα βροχή.'),('Unbeständig, später Aufklarung.','Rather Unsettled, Clearing Later','Ασταθής, αργότερα καθάρος.'),('Unbeständig, evtl. Besserung.','Unsettled, Probably Improving','Ασταθής, πιθανώς βελτίωση.'),('Regnerisch mit heiteren Phasen.','Showery, Bright Intervals','Καθαρός με διαστήματα βροχής.'),('Regnerisch, wird unbeständiger.','Showery, Becoming More Unsettled','Βροχερό, όλο και πιο ασταθές.'),('Wechselhaft mit etwas Regen.','Changeable, Some Rain','Αλλάζει με λίγη βροχή.'),('Unbeständig mit heiteren Phasen.','Unsettled, Short Fine Intervals','Άστατα, μικρά καθαρά διαστήματα'),('Unbeständig, später Regen.','Unsettled, Rain Later','Άστατη, αργότερα βροχή.'),('Unbeständig mit etwas Regen.','Unsettled, Rain At Times','Άστατος με λίγη βροχή.'),('Wechselhaft und regnerisch','Very Unsettled, Finer At Times','Μεταβλητός και βροχερός.'),('Gelegentlich Regen, Verschlechterung.','Rain At Times, Worse Later','Περιστασιακές βροχές, επιδείνωση.'),('Zuweilen Regen, sehr unbeständig.','Rain At Times, Becoming Very Unsettled','Βροχή κατά περιόδους, πολύ ασταθής.'),('Häufiger Regen.','Rain At Frequent Intervals','Συχνή βροχή.'),('Regen, sehr unbeständig.','Very Unsettled, Rain','Βροχή, πολύ ασταθής.'),('Stürmisch, evtl. Besserung.','Stormy, Possibly Improving','Θυελλώδης, πιθανώς βελτίωση.'),('Stürmisch mit viel Regen.','Stormy, Much Rain','Καταιγίδα με πολλές βροχές.')]%}
{%set t_lang_exceptional = ['außergewöhnliches Wetter, ','Exceptional Weather, ']%}
{%set language = states.sensor.local_forecast.attributes.language|int(0)%}
{##}
{# calculations #}
{##}
{%set bar_range = bar_top-bar_bottom%}
{%set constant = (bar_range/22)|round(3)%} {# calc range of pressure to options#}
{%if 2 < now().month < 11%}{%set season = 1%}{#summer#}{%else%}{%set season = 0%}{#winter#}{%endif%}
{%if p0change<=(-1.6) %}{%set trend = '-1'%}{%elif p0change>=(1.6) %}{%set trend = '1'%}{%else%}{%set trend = '0'%}{%endif%}
{#northern hemisphere#}
{%set z_hp = p0%}
{%if hem == 1 %}
{% if 11.25 < dir <= 33.75 and windfak_speed|int == 1%}{%set z_hp = z_hp+5/100*bar_range%} {# NNE #}
{% elif 33.75 < dir <= 56.25 and windfak_speed|int == 1%}{%set z_hp = z_hp+4+6/100*bar_range%} {# NE #}
{% elif 56.25 < dir <= 78.75 and windfak_speed|int == 1%}{%set z_hp = z_hp+2/100*bar_range%} {# ENE #}
{% elif 78.75 < dir <= 101.25 and windfak_speed|int == 1%}{%set z_hp = z_hp-0.5/100*bar_range%} {# E #}
{% elif 101.25 < dir <= 123.75 and windfak_speed|int == 1%}{%set z_hp = z_hp-3-2/100*bar_range%} {# ESE #}
{% elif 123.75 < dir <= 146.25 and windfak_speed|int == 1%}{%set z_hp = z_hp-5/100*bar_range%} {# SE #}
{% elif 146.25 < dir <= 168.75 and windfak_speed|int == 1%}{%set z_hp = z_hp-8.5/100*bar_range%} {# SSE #}
{% elif 168.75 < dir <= 191.25 and windfak_speed|int == 1%}{%set z_hp = z_hp-11-12/100*bar_range%} {# S #}
{% elif 191.25 < dir <= 213.75 and windfak_speed|int == 1%}{%set z_hp = z_hp-10/100*bar_range%} {# SSW #}
{% elif 213.75 < dir <= 236.25 and windfak_speed|int == 1%}{%set z_hp = z_hp-6/100*bar_range%} {# SW #}
{% elif 236.25 < dir <= 258.75 and windfak_speed|int == 1%}{%set z_hp = z_hp-4.5/100*bar_range%} {# WSW #}
{% elif 258.75 < dir <= 281.25 and windfak_speed|int == 1%}{%set z_hp = z_hp-3/100*bar_range%} {# W #}
{% elif 281.25 < dir <= 303.75 and windfak_speed|int == 1%}{%set z_hp = z_hp-0.5/100*bar_range%} {# WNW #}
{% elif 303.75 < dir <= 326.25 and windfak_speed|int == 1%}{%set z_hp = z_hp+1.5/100*bar_range%} {# NW #}
{% elif 326.25 < dir <= 348.75 and windfak_speed|int == 1%}{%set z_hp = z_hp+3/100*bar_range%} {# NNW #}
{% elif dir > 348.75 and windfak_speed|int == 1%}{%set z_hp = z_hp+6/100*bar_range%} {# N #}
{%endif%}
{%if season|int == 1%}
{%if trend|int == 1%}{%set z_hp = z_hp+7/100*bar_range%}
{%elif trend|int == -1%}{%set z_hp = z_hp-7/100*bar_range%}
{%endif%}
{%endif%}
{# for southern hemisphere all directions are inverted #}
{%endif%}
{%if z_hp|float == bar_top|float%}
{%set z_hp = bar_top-1 %}
{%endif%}
{# calculate options for weather #}
{%set z_option = ((z_hp-bar_bottom)/constant)|round(0,'floor')%}
{%set z_out = ""%}
{%if z_option < 0%}
{%set z_option = 0%}
{%set z_out = t_lang_exceptional[language]%}
{%elif z_option > 21%}
{%set z_option = 21%}
{%set z_out = t_lang_exceptional[language]%}
{%endif%}
{# look at pressure and generate results #}
{%if trend|int == 1%}{#rising pressure#}
{%set z_out = z_out + t_lang[rise_opt[z_option]][language]%}
{%set z_num = rise_opt[z_option]%}
{%elif trend|int == -1%}{#rising pressure#}
{%set z_out = z_out + t_lang[fall_opt[z_option]][language]%}
{%set z_num = fall_opt[z_option]%}
{%else%}
{%set z_out = z_out + t_lang[steady_opt[z_option]][language]%}
{%set z_num = steady_opt[z_option]%}
{%endif%}
{%set z = z_num%}
{%if z==0 %}{%set type_l = "none"%}
{%elif z in [1,10,20] %}{%set type_l = "A"%}
{%elif z in [2,11,21] %}{%set type_l = "B"%}
{%elif z in [11] %}{%set type_l = "C"%}
{%elif z in [3] %}{%set type_l = "D"%}
{%elif z in [12] %}{%set type_l = "E"%}
{%elif z in [23] %}{%set type_l = "F"%}
{%elif z in [24] %}{%set type_l = "G"%}
{%elif z in [4] %}{%set type_l = "H"%}
{%elif z in [25] %}{%set type_l = "I"%}
{%elif z in [26] %}{%set type_l = "J"%}
{%elif z in [13] %}{%set type_l = "K"%}
{%elif z in [27] %}{%set type_l = "L"%}
{%elif z in [28] %}{%set type_l = "M"%}
{%elif z in [14] %}{%set type_l = "N"%}
{%elif z in [5] %}{%set type_l = "O"%}
{%elif z in [15] %}{%set type_l = "P"%}
{%elif z in [29] %}{%set type_l = "Q"%}
{%elif z in [6] %}{%set type_l = "R"%}
{%elif z in [16] %}{%set type_l = "S"%}
{%elif z in [30] %}{%set type_l = "T"%}
{%elif z in [7] %}{%set type_l = "U"%}
{%elif z in [8] %}{%set type_l = "V"%}
{%elif z in [17] %}{%set type_l = "W"%}
{%elif z in [9,18] %}{%set type_l = "X"%}
{%elif z in [31] %}{%set type_l = "Y"%}
{%elif z in [19,32] %}{%set type_l = "Z"%}
{%endif%}
{{z_out,z_num,type_l}}
forecast_pressure_trend: >
{%set p0change = states.sensor.local_forecast_pressurechange.state|float(0)%}
{%set language = states.sensor.local_forecast.attributes.language|int(0)%}
{%set p0 = states.sensor.local_forecast.attributes.p0|float(0)%}
{%set trend_lang=[('fallend','Falling','πέφτοντας'),('steigend','Rising','αυξανόμενη'),('stabil','Steady','σταθερή')]%}
{%if p0change<=(-1.6) %}{%set trend = '0'%}{%elif p0change>=(1.6) %}{%set trend = '1'%}{%else%}{%set trend = '2'%}{%endif%}
{{[trend_lang[trend|int][language],trend]}}
forecast_temp_short: >
{# ultra short term temperature prognosis #}
{% set temp = states.sensor.local_forecast.attributes.temperature|float(0)%}
{%set temp_change = states.sensor.local_forecast_temperaturechange.state|float(0)%}
{%set first_time = states.sensor.local_forecast_zambretti_detail.attributes.first_time[1]|float(0)%}
{%set second_time = states.sensor.local_forecast_zambretti_detail.attributes.second_time[1]|float(0)%}
{%if first_time>0%}{%set t_forecast = ((temp_change/60*first_time)+temp)|round(1)%}{%set interval = 0%}
{%elif second_time>0%}{%set t_forecast = ((temp_change/60*second_time)+temp)|round(1)%}{%set interval = 1%}
{%else%}{%set t_forecast = "unavailable"%}{%set interval = -1%}{%endif%}
{{[t_forecast,interval]}}
- sensor:
- name: Local forecast zambretti detail
state: >
{{"More details on zambretti forecast",states.sensor.local_forecast.attributes.forecast_zambretti[1]|int(0)+1}}
attributes:
forecast: >
{% set z = states.sensor.local_forecast.attributes.forecast_zambretti[1]|int(0)+1%}
{# translate zambretti number to forecast icons: [next 6 h, next 12 h]#}
{# [State][day/night], available states: sunny (0), partlycloudy(1), partlycloudyrain(2), cloudy(3), rainy(4), pouring(5), lightning-rainy(6) #}
{%if z == 1%}{%set forecast = [0,0]%}
{%elif z == 2%}{%set forecast = [1,1]%}
{%elif z == 3%}{%set forecast = [2,1]%}
{%elif z == 4%}{%set forecast = [1,2]%}
{%elif z == 5%}{%set forecast = [1,1]%}
{%elif z == 6%}{%set forecast = [1,0]%}
{%elif z == 7%}{%set forecast = [2,1]%}
{%elif z == 8%}{%set forecast = [1,4]%}
{%elif z == 9%}{%set forecast = [4,2]%}
{%elif z == 10%}{%set forecast = [4,4]%}
{%elif z == 11%}{%set forecast = [1,1]%}
{%elif z == 12%}{%set forecast = [3,1]%}
{%elif z == 13%}{%set forecast = [3,3]%}
{%elif z == 14%}{%set forecast = [2,2]%}
{%elif z == 15%}{%set forecast = [4,5]%}
{%elif z == 16%}{%set forecast = [4,4]%}
{%elif z == 17%}{%set forecast = [2,2]%}
{%elif z == 18%}{%set forecast = [2,4]%}
{%elif z == 19%}{%set forecast = [2,2]%}
{%elif z == 20%}{%set forecast = [5,5]%}
{%elif z == 21%}{%set forecast = [2,4]%}
{%elif z == 22%}{%set forecast = [4,4]%}
{%elif z == 23%}{%set forecast = [4,4]%}
{%elif z == 24%}{%set forecast = [6,4]%}
{%elif z == 25%}{%set forecast = [6,6]%}
{%endif%}
{{forecast}}
rain_prob: >
{# give approx. values for rain probability #}
{%set forecast = states.sensor.local_forecast_zambretti_detail.attributes.forecast%}
{%if forecast[0]==0 and forecast[1]==0 %}{%set rain_prob = [0,0]%}
{%elif forecast[0]==2 and forecast[1]==1 %}{%set rain_prob = [60,10]%}
{%elif forecast[0]==1 and forecast[1]==1 %}{%set rain_prob = [30,30]%}
{%elif forecast[0]==1 and forecast[1]==0 %}{%set rain_prob = [10,0]%}
{%elif forecast[0]==1 and forecast[1]>=2 %}{%set rain_prob = [20,60]%}
{%elif forecast[0]==2 and forecast[1]==2 %}{%set rain_prob = [50,50]%}
{%elif forecast[0]==2 and forecast[1]>2 %}{%set rain_prob = [50,70]%}
{%elif forecast[0]>=2 and forecast[1]<2 %}{%set rain_prob = [50,10]%}
{%else%}{%set rain_prob = [90,90]%}{%endif%}
{{rain_prob}}
icons: >
{%set forecast = states.sensor.local_forecast_zambretti_detail.attributes.forecast%}
{%set conditions = [('mdi:weather-sunny','mdi:weather-night'),('mdi:weather-partly-cloudy', 'mdi:weather-night-partly-cloudy'),('mdi:weather-partly-rainy','mdi:weather-partly-rainy'),('mdi:weather-cloudy','mdi:weather-cloudy'),('mdi:weather-rainy','mdi:weather-rainy'),('mdi:weather-pouring','mdi:weather-pouring'),('mdi:weather-lightning-rainy','mdi:weather-lightning-rainy')]%}
{# [State][day/night], available states: sunny (0), partlycloudy(1), partlycloudyrain(2), cloudy(3), rainy(4), pouring(5), lightning-rainy(6) #}
{%if is_state('sun.sun', 'below_horizon')==true%}{%set daynight=1%}{%else%}{%set daynight=0%}{%endif%}
{%set now = conditions[forecast[0]|int(0)][daynight|int(0)]%}
{%set later = conditions[forecast[1]|int(0)][daynight|int(0)]%}
{{(now,later)}}
first_time: >
{# figure out if forecast is old; if yes add 6h -> next interval #}
{%set halftime = 6*60-(as_timestamp(now()) - as_timestamp(states.sensor.local_forecast_zambretti_detail.last_changed))/60%}
{%if halftime<0%}{%set correction = 6+((halftime/60)|float(0))%}{%else%}{%set correction = 0%}{%endif%}
{%set time_offset_first = 3+correction%}{#time from last forecast update to the first forecast state #}
{%set time_to = time_offset_first*60-(as_timestamp(now()) - as_timestamp(states.sensor.local_forecast_zambretti_detail.last_changed))/60%}
{{[(as_timestamp(now())+time_to*60)| timestamp_custom('%H:%M'), time_to|round(2)]}}{# [time of first state, minutes to first state] #}
second_time: >
{# figure out if forecast is old; if yes add 6h -> next interval #}
{%set halftime = 6*60-(as_timestamp(now()) - as_timestamp(states.sensor.local_forecast_zambretti_detail.last_changed))/60%}
{%if halftime<0%}{%set correction = 6+((halftime/60)|float(0))%}{%else%}{%set correction = 0%}{%endif%}
{%set time_offset_second = 9+correction%}{#time from last forecast update to the first forecast state #}
{%set time_to = time_offset_second*60-(as_timestamp(now()) - as_timestamp(states.sensor.local_forecast_zambretti_detail.last_changed))/60%}
{{[(as_timestamp(now())+time_to*60)| timestamp_custom('%H:%M'), time_to|round(2)]}}{# [time of first state, minutes to first state] #}
- name: Local forecast neg_zam detail
state: >
{{"More details on neg_zam forecast", states.sensor.local_forecast.attributes.forecast_neg_zam[1]|int(0)+1}}
attributes:
forecast: >
{% set z = states.sensor.local_forecast.attributes.forecast_neg_zam[1]|int(0)+1%}
{# translate zambretti number to forecast icons: [next 6 h, next 12 h] #}
{%if z == 1%}{%set forecast = [0,0]%}
{%elif z == 2%}{%set forecast = [1,1]%}
{%elif z == 3%}{%set forecast = [2,1]%}
{%elif z == 4%}{%set forecast = [1,2]%}
{%elif z == 5%}{%set forecast = [2,2]%}
{%elif z == 6%}{%set forecast = [2,1]%}
{%elif z == 7%}{%set forecast = [2,1]%}
{%elif z == 8%}{%set forecast = [1,4]%}
{%elif z == 9%}{%set forecast = [4,2]%}
{%elif z == 10%}{%set forecast = [4,4]%}
{%elif z == 11%}{%set forecast = [2,2]%}
{%elif z == 12%}{%set forecast = [3,1]%}
{%elif z == 13%}{%set forecast = [3,3]%}
{%elif z == 14%}{%set forecast = [2,2]%}
{%elif z == 15%}{%set forecast = [4,5]%}
{%elif z == 16%}{%set forecast = [4,4]%}
{%elif z == 17%}{%set forecast = [2,2]%}
{%elif z == 18%}{%set forecast = [2,4]%}
{%elif z == 19%}{%set forecast = [2,2]%}
{%elif z == 20%}{%set forecast = [5,5]%}
{%elif z == 21%}{%set forecast = [2,4]%}
{%elif z == 22%}{%set forecast = [4,4]%}
{%elif z == 23%}{%set forecast = [4,4]%}
{%elif z == 24%}{%set forecast = [6,4]%}
{%elif z == 25%}{%set forecast = [6,6]%}
{%endif%}
{{forecast}}
rain_prob: >
{# give approx. values for rain probability #}
{%set forecast = states.sensor.local_forecast_neg_zam_detail.attributes.forecast%}
{%if forecast[0]<2 and forecast[1]<2 %}{%set rain_prob = [0,0]%}
{%elif forecast[0]==1 and forecast[1]>=2 %}{%set rain_prob = [20,60]%}
{%elif forecast[0]==2 and forecast[1]==2 %}{%set rain_prob = [50,50]%}
{%elif forecast[0]==2 and forecast[1]>2 %}{%set rain_prob = [50,70]%}
{%else%}{%set rain_prob = [90,90]%}{%endif%}
{{rain_prob}}
icons: >
{%set forecast = states.sensor.local_forecast_neg_zam_detail.attributes.forecast%}
{%set conditions = [('mdi:weather-sunny','mdi:weather-night'),('mdi:weather-partly-cloudy', 'mdi:weather-night-partly-cloudy'),('mdi:weather-partly-rainy','mdi:weather-partly-rainy'),('mdi:weather-cloudy','mdi:weather-cloudy'),('mdi:weather-rainy','mdi:weather-rainy'),('mdi:weather-pouring','mdi:weather-pouring'),('mdi:weather-lightning-rainy','mdi:weather-lightning-rainy')]%}
{# [State][day/night], available states: sunny (0), partlycloudy(1), partlycloudyrain(2), cloudy(3), rainy(4), pouring(5), lightning-rainy(6) #}
{%if is_state('sun.sun', 'below_horizon')==true%}{%set daynight=1%}{%else%}{%set daynight=0%}{%endif%}
{%set now = conditions[forecast[0]|int(0)][daynight|int(0)]%}
{%set later = conditions[forecast[1]|int(0)][daynight|int(0)]%}
{{(now,later)}}
first_time: >
{# figure out if forecast is old; if yes add 6h -> next interval #}
{%set halftime = 6*60-(as_timestamp(now()) - as_timestamp(states.sensor.local_forecast_neg_zam_detail.last_changed))/60%}
{%if halftime<0%}{%set correction = 6+((halftime/60)|float(0))%}{%else%}{%set correction = 0%}{%endif%}
{%set time_offset_first = 3+correction%}{#time from last forecast update to the first forecast state #}
{%set time_to = time_offset_first*60-(as_timestamp(now()) - as_timestamp(states.sensor.local_forecast_neg_zam_detail.last_changed))/60%}
{{[(as_timestamp(now())+time_to*60)| timestamp_custom('%H:%M'), time_to|round(2)]}}{# [time of first state, minutes to first state] #}
second_time: >
{# figure out if forecast is old; if yes add 6h -> next interval #}
{%set halftime = 6*60-(as_timestamp(now()) - as_timestamp(states.sensor.local_forecast_neg_zam_detail.last_changed))/60%}
{%if halftime<0%}{%set correction = 6+((halftime/60)|float(0))%}{%else%}{%set correction = 0%}{%endif%}
{%set time_offset_second = 9+correction%}{#time from last forecast update to the first forecast state #}
{%set time_to = time_offset_second*60-(as_timestamp(now()) - as_timestamp(states.sensor.local_forecast_neg_zam_detail.last_changed))/60%}
{{[(as_timestamp(now())+time_to*60)| timestamp_custom('%H:%M'), time_to|round(2)]}}{# [time of first state, minutes to first state] #}
# (un)availibility has to be set to avoid Home Assistant attempting to do math with empty strings on startup
- sensor:
- name: Local forecast Pressure
unit_of_measurement: "hPa"
device_class: 'atmospheric_pressure'
availability: "{{ states.sensor.local_forecast.attributes.p0 | is_number }}"
state: >
{{ states.sensor.local_forecast.attributes.p0|float(states.sensor.local_forecast_pressure.state) }}
- name: Local forecast temperature
unit_of_measurement: "°C"
device_class: 'temperature'
availability: "{{ states.sensor.local_forecast.attributes.temperature | is_number }}"
state: >
{{ states.sensor.local_forecast.attributes.temperature|float(states.sensor.local_forecast_temperature.state) }}
# The sampling_size values should add up to slightly less than the amount of sensor updates in the max_age time to work around Home Assistant's statistics integration
# e.g. a pressure sensor that updates every ~5 seconds in 180 minutes is 2160 updates, -12.5%, gives 1890 samples
sensor:
- platform: statistics
name: Local forecast PressureChange
entity_id: sensor.local_forecast_pressure
state_characteristic: change
max_age:
minutes: 180
sampling_size: 1890
- platform: statistics
name: Local forecast TemperatureChange
entity_id: sensor.local_forecast_temperature
state_characteristic: change
max_age:
minutes: 60
sampling_size: 140