-
Notifications
You must be signed in to change notification settings - Fork 37
/
bom-weather-card.js
1298 lines (1163 loc) · 69.6 KB
/
bom-weather-card.js
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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import {
LitElement,
html,
} from "https://unpkg.com/[email protected]/lit-element.js?module";
// #### Add card info to console
console.info(
`%cGENERIC-WEATHER-CARD\n%cVersion 1.1.4 `,
"color: #043ff6; font-weight: bold; background: white",
"color: white; font-weight: bold; background: #043ff6"
);
// #### Add to Custom-Card Picker
window.customCards = window.customCards || [];
window.customCards.push({
type: "bom-weather-card",
name: "Generic Animated Weather Card",
preview: false, // Optional - defaults to false
description: "A custom card made by @DavidFW1960" // Optional
});
// #####
// ##### Custom Card Definition begins
// #####
class BOMWeatherCard extends LitElement {
// #####
// ##### Define Render Template
// #####
render() {
if (!this.config || !this._hass) return html``;
// Handle Configuration Flags
// var icons = this.config.static_icons ? "static" : "animated";
var currentText = this.config.entity_current_text ? html`<span class="currentText" id="current-text">${this._hass.states[this.config.entity_current_text] !== undefined ? this._hass.states[this.config.entity_current_text].state : "Config Error"}</span>` : ``;
var apparentTemp = this.config.entity_apparent_temp ? html`<span class="apparent">${this.localeText.feelsLike} <span id="apparent-text">${this.currentApparent}</span>${this.getUOM("temperature")}</span>` : ``;
var biggerIcon = this.currentConditions !== undefined ? html`<span class="icon bigger" id="icon-bigger" style="background: none, url(${this._hass.hassUrl("/local/icons/weather_icons/" + (this.config.static_icons ? "static" : "animated") + "/" + this.weatherIcons[this.currentConditions] + ".svg")}) no-repeat; background-size: contain;">${this.currentConditions}</span>` : html`<div class="eicon"><ha-icon style="top: 50%; margin: 0; -ms-transform: translateY(-50%); transform: translateY(-50%);" icon="mdi:alert"></ha-icon></div>`;
var summary = this.config.entity_daily_summary ? html`${this._hass.states[this.config.entity_daily_summary] !== undefined ? this._hass.states[this.config.entity_daily_summary].state : "Config Error"}` : ``;
var separator = this.config.show_separator ? html`<hr class=line>` : ``;
var uv_alert = this.config.entity_uv_alert ? html`${this._hass.states[this.config.entity_uv_alert] !== undefined ? this._hass.states[this.config.entity_uv_alert].state : "UV: Config Error"}` : ``;
var fire_danger = this.config.entity_fire_danger ? html`${this._hass.states[this.config.entity_fire_danger] !== undefined ? this._hass.states[this.config.entity_fire_danger].state !== "Fire Danger: unknown" ? this._hass.states[this.config.entity_fire_danger].state : "" : "Fire Danger: Config Error"}` : ``;
var slot_section = (this.config.use_old_column_format === true) ? html`<ul class="variations-ugly"><li>${this.getSlot().l1}${this.getSlot().l2}${this.getSlot().l3}${this.getSlot().l4}${this.getSlot().l5}</li><li>${this.getSlot().r1}${this.getSlot().r2}${this.getSlot().r3}${this.getSlot().r4}${this.getSlot().r5}</li></ul>` : html`<ul class="variations"><li class="slotlist">${this.getSlot().l1}${this.getSlot().l2}${this.getSlot().l3}${this.getSlot().l4}${this.getSlot().l5}</li><li class="slotlist">${this.getSlot().r1}${this.getSlot().r2}${this.getSlot().r3}${this.getSlot().r4}${this.getSlot().r5}</li></ul>`;
// Build HTML
return html`
<style>
${this.style()}
</style>
<ha-card class = "card">
<div>
${biggerIcon}
<span class="temp" id="temperature-text">${this.currentTemperature}</span><span class="tempc">${this.getUOM('temperature')}</span>
${currentText}
${apparentTemp}
</div>
${separator}
<span>${slot_section}</span>
<div class="forecast clear">
${this.forecast.map(daily => html`
<div class="day fcasttooltip">
<span class="dayname" id="fcast-dayName-${daily.dayIndex}">${(daily.date).toLocaleDateString(this.config.locale,{weekday: 'short'})}</span>
<br>${this._hass.states[daily.condition] !== undefined
?
html`<i class="icon" id="fcast-icon-${daily.dayIndex}" style="background: none, url(${this._hass.hassUrl("/local/icons/weather_icons/" + (this.config.static_icons ? "static" : "animated") + "/" + this.weatherIcons[this._hass.states[daily.condition].state] + ".svg").replace("-night", "-day")}) no-repeat; background-size: contain;"></i><br>`
:
html `<div class="eicon"><ha-icon style="top: 50%; margin: 0; -ms-transform: translateY(-50%); transform: translateY(-50%);" icon="mdi:alert"></ha-icon></div>`}
${this.config.old_daily_format
?
html`<span class="highTemp" id="fcast-high-${daily.dayIndex}">${this._hass.states[daily.temphigh] !== undefined ? Math.round(this._hass.states[daily.temphigh].state)+this.getUOM("temperature") : 'Err'}</span><br><span class="lowTemp" id="fcast-low-${daily.dayIndex}">${this._hass.states[daily.templow] !== undefined ? Math.round(this._hass.states[daily.templow].state)+this.getUOM("temperature") : 'Err'}</span>`
:
this.config.tempformat ==="highlow"
?
html`<span class="highTemp" id="fcast-high-${daily.dayIndex}">${this._hass.states[daily.temphigh] !== undefined ? Math.round(this._hass.states[daily.temphigh].state) : "Err"}</span> / <span class="lowTemp" id="fcast-low-${daily.dayIndex}">${this._hass.states[daily.templow] !== undefined ? Math.round(this._hass.states[daily.templow].state) : "Err"}${this.getUOM("temperature")}</span>`
:
html`<span class="lowTemp" id="fcast-low-${daily.dayIndex}">${this._hass.states[daily.templow] !== undefined ? Math.round(this._hass.states[daily.templow].state) : "Err"}</span> / <span class="highTemp" id="fcast-high-${daily.dayIndex}">${this._hass.states[daily.temphigh] !== undefined ? Math.round(this._hass.states[daily.temphigh].state) : "Err"}${this.getUOM("temperature")}</span>`}
${this.config.entity_pop_1 && this.config.entity_pop_2 && this.config.entity_pop_3 && this.config.entity_pop_4 && this.config.entity_pop_5 ? html`<br><span class="pop" id="fcast-pop-${daily.dayIndex}">${this._hass.states[daily.pop] ? Math.round(this._hass.states[daily.pop].state) : "Err"}%</span>` : ``}
${this.config.entity_pos_1 && this.config.entity_pos_2 && this.config.entity_pos_3 && this.config.entity_pos_4 && this.config.entity_pos_5 ? html`<br><span class="pos" id="fcast-pos-${daily.dayIndex}">${this._hass.states[daily.pos] !== undefined ? this._hass.states[daily.pos].state : "Err"}</span><span class="unit">${this.getUOM('precipitation')}</span>` : ``}
<div class="fcasttooltiptext" id="fcast-summary-${daily.dayIndex}">${ this.config.tooltips ? this._hass.states[daily.summary] !== undefined ? this._hass.states[daily.summary].state : "Config Error" : ""}</div>
</div>`)}
</div>
<div class="summary clear" id="daily-summary-text">
${summary} ${uv_alert} ${fire_danger}
</div>
</ha-card>
`;
}
// #####
// ##### slots - returns the value to be displyed in a specific current condition slot
// #####
getSlot() {
return {
'r1' : this.slotValue('r1',this.config.slot_r1),
'r2' : this.slotValue('r2',this.config.slot_r2),
'r3' : this.slotValue('r3',this.config.slot_r3),
'r4' : this.slotValue('r4',this.config.slot_r4),
'r5' : this.slotValue('r5',this.config.slot_r5),
'l1' : this.slotValue('l1',this.config.slot_l1),
'l2' : this.slotValue('l2',this.config.slot_l2),
'l3' : this.slotValue('l3',this.config.slot_l3),
'l4' : this.slotValue('l4',this.config.slot_l4),
'l5' : this.slotValue('l5',this.config.slot_l5),
}
}
// #####
// ##### slots - calculates the specific slot value
// #####
slotValue(slot,value) {
switch (value) {
case 'pop': return this.pop;
case 'popforecast': return this.popforecast;
case 'possible_today': return this.possibleToday;
case 'possible_tomorrow': return this.possibleTomorrow;
case 'rainfall' : return this.rainToday;
case 'humidity': return this.humidity;
case 'pressure': return this.pressure;
case 'daytime_high': return this.daytimeHigh;
case 'daytime_low': return this.daytimeLow;
case 'temp_next': return this.tempNext;
case 'temp_following': return this.tempFollowing;
case 'uv_summary' : return this.uvSummary;
case 'fire_summary' : return this.fireSummary;
case 'wind': return this.wind;
case 'wind_kt': return this.windKt;
case 'visibility': return this.visibility;
case 'sun_next': return this.sunNext;
case 'sun_following': return this.sunFollowing;
case 'custom1': return this.custom1;
case 'custom2': return this.custom2;
case 'empty': return html` `;
case 'remove': return ``;
}
// If no value can be matched pass back a default for the slot
switch (slot) {
case 'l1': return this.daytimeHigh;
case 'l2': return this.daytimeLow;
case 'l3': return this.wind;
case 'l4': return this.pressure;
case 'l5': return this.sunNext;
case 'r1': return this.pop;
case 'r2': return this.humidity;
case 'r3': return this.uvSummary;
case 'r4': return this.fireSummary;
case 'r5': return this.sunFollowing;
}
}
get pop() {
try {
var intensity = this.config.entity_pop_intensity && !this.config.entity_pop_intensity_rate ? html`<span id="intensity-text"> - ${(Number(this._hass.states[this.config.entity_pop_intensity].state)).toLocaleString()}</span><span class="unit">${this.getUOM('precipitation')}</span>` : this.config.entity_pop_intensity_rate && !this.config.entity_pop_intensity ? html`<span id="intensity-text"> - ${(Number(this._hass.states[this.config.entity_pop_intensity_rate].state)).toLocaleString()}</span><span class="unit">${this.getUOM('intensity')}</span>` : ` Config Error`;
if (this.config.alt_pop) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-rainy"></ha-icon></span><span id="alt-pop">${this._hass.states[this.config.alt_pop].state}</span></li>`;
} else {
return this.config.entity_pop ? html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-rainy"></ha-icon></span><span id="pop-text">${this._hass.states[this.config.entity_pop] !== undefined ? Math.round(this._hass.states[this.config.entity_pop].state) : "Config Error"}</span><span class="unit">%</span><span>${intensity}</span></li>` : ``;
}
} catch (e) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-rainy"></ha-icon></span><span id="pop-text">Config Error</span></li>`;
}
}
get popforecast() {
try {
if (this.config.alt_pop) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-rainy"></ha-icon></span><span id="alt-pop">${this._hass.states[this.config.alt_pop].state}</span></li>`;
} else {
return this.config.entity_pop && this.config.entity_possible_today ? html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-rainy"></ha-icon></span><span id="pop-text">${Math.round(this._hass.states[this.config.entity_pop].state)}</span><span class="unit">%</span><span> - <span id="pop-text-today">${this._hass.states[this.config.entity_possible_today].state}</span></span><span class="unit">${this.getUOM('precipitation')}</span></li>` : ``;
}
} catch (e) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-rainy"></ha-icon></span><span id="pop-text">Config Error</span></li>`;
}
}
get possibleToday() {
try {
return this.config.entity_possible_today ? html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-rainy"></ha-icon></span>${this.localeText.posToday} <span id="possible_today-text">${this._hass.states[this.config.entity_possible_today].state}</span><span class="unit">${this.getUOM('precipitation')}</span></li>` : ``;
} catch (e) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-rainy"></ha-icon></span><span id="possible_today-text">Config Error</span></li>`;
}
}
get possibleTomorrow() {
try {
return this.config.entity_pos_1 ? html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-rainy"></ha-icon></span>${this.localeText.posTomorrow} <span id="possible_tomorrow-text">${this._hass.states[this.config.entity_pos_1].state}</span><span class="unit">${this.getUOM('precipitation')}</span></li>` : ``;
} catch (e) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-rainy"></ha-icon></span><span id="possible_tomorrow-text">Config Error</span></li>`;
}
}
get rainToday() {
try {
return this.config.entity_rain_today ? html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-rainy"></ha-icon></span><span id="rain-today-text">${this._hass.states[this.config.entity_rain_today].state}</span><span class="unit">${this.getUOM('precipitation')}</span></li>` : ``;
} catch (e) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-rainy"></ha-icon></span><span id="rain-today-text">Config Error</span></li>`;
}
}
get humidity() {
try {
if (this.config.alt_humidity) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:water-percent"></ha-icon></span><span id="alt-humidity">${this._hass.states[this.config.alt_humidity].state}</span></li>`;
} else {
return this.config.entity_humidity ? html`<li><span class="ha-icon"><ha-icon icon="mdi:water-percent"></ha-icon></span><span id="humidity-text">${this.currentHumidity}</span><span class="unit">%</span></li>` : ``;
}
} catch (e) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:water-percent"></ha-icon></span><span id="humidity-text">Config Error</span></li>`;
}
}
get pressure() {
try {
if (this.config.alt_pressure) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:gauge"></ha-icon></span><span id="alt-pressure">${this._hass.states[this.config.alt_pressure].state}</span></li>`;
} else {
return this.config.entity_pressure ? html`<li><span class="ha-icon"><ha-icon icon="mdi:gauge"></ha-icon></span><span id="pressure-text">${this.currentPressure}</span><span class="unit">${this.config.pressure_units ? this.config.pressure_units : this.getUOM('air_pressure')}</span></li>` : ``;
}
} catch (e) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:gauge"></ha-icon></span><span id="pressure-text">Config Error</span></li>`;
}
}
get daytimeHigh() {
try {
if (this.config.alt_daytime_high) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:thermometer-high"></ha-icon></span><span id="alt-daytime-high">${this._hass.states[this.config.alt_daytime_high].state}</span></li>`;
} else {
return this.config.entity_daytime_high && this.config.show_decimals_today ? html`<li><span class="ha-icon"><ha-icon icon="mdi:thermometer-high"></ha-icon></span>${this.localeText.maxToday} <span id="daytime-high-text">${(Number(this._hass.states[this.config.entity_daytime_high].state)).toLocaleString(undefined, {minimumFractionDigits: 1, maximumFractionDigits: 1})}</span><span>${this.getUOM('temperature')}</span></li>` : this.config.entity_daytime_high && !this.config.show_decimals_today ?html`<li><span class="ha-icon"><ha-icon icon="mdi:thermometer-high"></ha-icon></span>${this.localeText.maxToday} <span id="daytime-high-text">${(Number(this._hass.states[this.config.entity_daytime_high].state).toFixed(0)).toLocaleString()}</span><span>${this.getUOM('temperature')}</span></li>` : ``;
}
} catch (e) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:thermometer-high"></ha-icon></span><span id="daytime-high-text">Config Error</span></li>`;
}
}
get daytimeLow() {
try {
if (this.config.alt_daytime_low) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:thermometer-low"></ha-icon></span><span id="alt-daytime-low">${this._hass.states[this.config.alt_daytime_low].state}</span></li>`;
} else {
return this.config.entity_daytime_low && this.config.show_decimals_today ? html`<li><span class="ha-icon"><ha-icon icon="mdi:thermometer-low"></ha-icon></span>${this.localeText.minToday} <span id="daytime-low-text">${(Number(this._hass.states[this.config.entity_daytime_low].state)).toLocaleString(undefined, {minimumFractionDigits: 1, maximumFractionDigits: 1})}</span><span>${this.getUOM('temperature')}</span></li>` : this.config.entity_daytime_low && !this.config.show_decimals_today ?html`<li><span class="ha-icon"><ha-icon icon="mdi:thermometer-low"></ha-icon></span>${this.localeText.minToday} <span id="daytime-low-text">${(Number(this._hass.states[this.config.entity_daytime_low].state).toFixed(0)).toLocaleString()}</span><span> ${this.getUOM('temperature')}</span></li>` : ``;
}
} catch (e) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:thermometer-low"></ha-icon></span><span id="daytime-low-text">Config Error</span></li>`;
}
}
get tempNext() {
try {
return this.config.entity_temp_next && this.config.entity_temp_next_label ? html`<li><span class="ha-icon"><ha-icon id="temp-next-icon" icon="${this.tempNextIcon}"></ha-icon></span><span id="temp-next-text">${this.tempNextText}</span><span>${this.getUOM('temperature')}</span></li>` : ``;
} catch (e) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:thermometer"></ha-icon></span><span id="temp-next-text">Config Error</span></li>`;
}
}
get tempNextIcon() {
return this._hass.states[this.config.entity_temp_next_label].state.includes("Min") ? "mdi:thermometer-low" : "mdi:thermometer-high";
}
get tempNextText() {
return this.config.entity_temp_next && this.config.entity_temp_next_label ? `${this._hass.states[this.config.entity_temp_next_label].state} ${this._hass.states[this.config.entity_temp_next].state}` : ``;
}
get tempFollowing() {
try {
return this.config.entity_temp_following && this.config.entity_temp_following_label ? html`<li><span class="ha-icon"><ha-icon id="temp-following-icon" icon="${this.tempFollowingIcon}"></ha-icon></span><span id="temp-following-text">${this.tempFollowingText}</span><span>${this.getUOM('temperature')}</span></li>` : ``;
} catch (e) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:thermometer"></ha-icon></span><span id="temp-following-text">Config Error</span></li>`;
}
}
get tempFollowingIcon() {
return this._hass.states[this.config.entity_temp_following_label].state.includes("Min") ? "mdi:thermometer-low" : "mdi:thermometer-high";
}
get tempFollowingText() {
return this.config.entity_temp_following && this.config.entity_temp_following_label ? `${this._hass.states[this.config.entity_temp_following_label].state} ${this._hass.states[this.config.entity_temp_following].state}` : ``;
}
get uvSummary() {
try {
return this.config.entity_uv_alert_summary ? html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-sunny"></ha-icon></span>${this.localeText.uvRating} <span id="daytime-uv-text">${this._hass.states[this.config.entity_uv_alert_summary].state}</span></li>` : ``;
} catch (e) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-sunny"></ha-icon></span><span id="daytime-uv-text">Config Error</span></li>`;
}
}
get fireSummary() {
try {
return this.config.entity_fire_danger_summary ? html`<li><span class="ha-icon"><ha-icon icon="mdi:fire"></ha-icon></span>${this.localeText.fireDanger} <span id="daytime-firedanger-text">${this._hass.states[this.config.entity_fire_danger_summary].state !== 'unknown' ? this._hass.states[this.config.entity_fire_danger_summary].state : 'N/A'}</span></li>` : ``;
} catch (e) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:fire"></ha-icon></span><span id="daytime-firedanger-text">Config Error</span></li>`;
}
}
get wind() {
try {
var windBearing = this.config.entity_wind_bearing ? html`<span id="wind-bearing-text">${this.currentWindBearing}</span>` : ``;
var beaufortRating = this.config.entity_wind_speed ? html`<span id="beaufort-text">${this.currentBeaufort}</span>` : ``;
return this.config.alt_wind ? html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-windy"></ha-icon></span><span id="alt-wind">${this._hass.states[this.config.alt_wind].state}</span></li>` : this.config.entity_wind_bearing && this.config.entity_wind_speed && this.config.entity_wind_gust ? html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-windy"></ha-icon></span><span>${beaufortRating}</span><span>${windBearing}</span><span id="wind-speed-text"> ${this.currentWindSpeed}</span><span class="unit">${this.getUOM('length')}/h</span><span id="wind-gust-text"> (Gust ${this.currentWindGust}</span><span class="unit">${this.getUOM('length')}/h)</span></li>` : this.config.entity_wind_bearing && this.config.entity_wind_speed ? html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-windy"></ha-icon></span><span>${beaufortRating}</span><span>${windBearing}</span><span id="wind-speed-text"> ${this.currentWindSpeed}</span><span class="unit"> ${this.getUOM('length')}/h</span></li>` : ``;
} catch (e) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-windy"></ha-icon></span><span id="wind-error-text">Config Error</span></li>`;
}
}
get windKt() {
try {
var windBearing = this.config.entity_wind_bearing ? html`<span id="wind-bearing-kt-text">${this.currentWindBearing}</span>` : ``;
var beaufortRatingKt = this.config.entity_wind_speed_kt ? html`<span id="beaufort-kt-text">${this.currentBeaufortkt}</span>` : ``;
return this.config.entity_wind_bearing && this.config.entity_wind_speed_kt && this.config.entity_wind_gust_kt ? html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-windy"></ha-icon></span><span>${beaufortRatingKt}</span><span>${windBearing}</span><span id="wind-speed-kt-text"> ${this.currentWindSpeedKt}</span><span class="unit">kt</span><span id="wind-gust-kt-text"> (Gust ${this.currentWindGustKt}</span><span class="unit">kt)</span></li>` : this.config.entity_wind_bearing && this.config.entity_wind_speed_kt ? html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-windy"></ha-icon></span><span>${beaufortRatingKt}</span><span>${windBearing}</span><span id="wind-speed-kt-text">${this.currentWindSpeedKt}</span><span class="unit">kt</span></li>` : ``;
} catch (e) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-windy"></ha-icon></span><span id="wind-error-text">Config Error</span></li>`;
}
}
get visibility() {
try {
return this.config.alt_visibility ? html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-fog"></ha-icon></span><span id="alt-visibility">${this._hass.states[this.config.alt_visibility].state}</span></li>` : this.config.entity_visibility ? html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-fog"></ha-icon></span><span id="visibility-text">${this.currentVisibility}</span><span class="unit"> ${this.getUOM('length')}</span></li>` : ``;
} catch (e) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-fog"></ha-icon></span><span id="visibility-text">Config Error</span></li>`;
}
}
get sunNext() {
try {
if (this.config.alt_sun_next) {
return html`<li><span id="alt-sun-next">${this._hass.states[this.config.alt_sun_next].state}</span></li>`;
} else {
return this.config.entity_sun ? this.sunSet.next : "";
}
} catch (e) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-sunset"></ha-icon></span><span id="sun-next-text">Config Error</span></li>`;
}
}
get sunFollowing() {
try {
if (this.config.alt_sun_following) {
return html`<li><span id="alt-sun-following">${this._hass.states[this.config.alt_sun_following].state}</span></li>`;
} else {
return this.config.entity_sun ? this.sunSet.following : "";
}
} catch (e) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:weather-sunset"></ha-icon></span><span id="sun-following-text">Config Error</span></li>`;
}
}
get custom1() {
try {
var icon = this.config.custom1_icon ? this.config.custom1_icon : 'mdi:help-box';
var value = this.config.custom1_value ? this._hass.states[this.config.custom1_value].state : 'unknown';
var unit = this.config.custom1_units ? this.config.custom1_units : '';
return html`<li><span class="ha-icon"><ha-icon icon=${icon}></ha-icon></span><span id="custom-1-text">${value}</span><span class="unit">${unit}</span></li>`;
} catch (e) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:help-box"></ha-icon></span><span id="custom-1-text">Config Error</span></li>`;
}
}
get custom2() {
try {
var icon = this.config.custom2_icon ? this.config.custom2_icon : 'mdi:help-box';
var value = this.config.custom2_value ? this._hass.states[this.config.custom2_value].state : 'unknown';
var unit = this.config.custom2_units ? this.config.custom2_units : '';
return html`<li><span class="ha-icon"><ha-icon icon=${icon}></ha-icon></span><span id="custom-2-text">${value}</span><span class="unit">${unit}</span></li>`;
} catch (e) {
return html`<li><span class="ha-icon"><ha-icon icon="mdi:help-box"></ha-icon></span><span id="custom-2-text">Config Error</span></li>`;
}
}
// #####
// ##### windDirections - returns set of possible wind directions by specified language
// #####
get windDirections() {
const windDirections_en = ['N','NNE','NE','ENE','E','ESE','SE','SSE','S','SSW','SW','WSW','W','WNW','NW','NNW','N'];
const windDirections_fr = ['N','NNE','NE','ENE','E','ESE','SE','SSE','S','SSO','SO','OSO','O','ONO','NO','NNO','N'];
const windDirections_de = ['N','NNO','NO','ONO','O','OSO','SO','SSO','S','SSW','SW','WSW','W','WNW','NW','NNW','N'];
const windDirections_nl = ['N','NNO','NO','ONO','O','OZO','ZO','ZZO','Z','ZZW','ZW','WZW','W','WNW','NW','NNW','N'];
const windDirections_he = ['צפון','צ-צ-מז','צפון מזרח','מז-צ-מז','מזרח','מז-ד-מז','דרום מזרח','ד-ד-מז','דרום','ד-ד-מע','דרום מערב','מע-ד-מע','מערב','מע-צ-מע','צפון מערב','צ-צ-מע','צפון'];
const windDirections_da = ['N','NNØ','NØ','ØNØ','Ø','ØSØ','SØ','SSØ','S','SSV','SV','VSV','V','VNV','NV','NNV','N'];
const windDirections_ru = ['С','ССВ','СВ','ВСВ','В','ВЮВ','ЮВ','ЮЮВ','Ю','ЮЮЗ','ЮЗ','ЗЮЗ','З','ЗСЗ','СЗ','ССЗ','С'];
const windDirections_hu = ['É','ÉÉK','ÉK','KÉK','K','KDK','DK','DDK','D','DDNY','DNY','NYDNY','NY','NYÉNY','ÉNY','ÉÉNY','É'];
switch (this.config.locale) {
case "it" :
case "fr" :
return windDirections_fr;
case "de" :
return windDirections_de;
case "nl" :
return windDirections_nl;
case "he" :
return windDirections_he;
case "ru" :
return windDirections_ru;
case "da" :
return windDirections_da;
case "hu" :
return windDirections_hu;
default :
return windDirections_en;
}
}
// #####
// ##### feelsLikeText returns set of possible "Feels Like" text by specified language
// #####
get localeText() {
switch (this.config.locale) {
case "it" :
return {
feelsLike: "Percepito",
maxToday: "Max oggi:",
}
case "fr" :
return {
feelsLike: "Ressenti:",
maxToday: "Max aujourd'hui:",
}
case "de" :
return {
feelsLike: "Gefühlt",
maxToday: "Max heute:",
minToday: "Min heute:",
}
case "nl" :
return {
feelsLike: "Voelt als",
maxToday: "Max vandaag:",
minToday: "Min vandaag:",
posToday: "Prognose",
posTomorrow: "Prog. Morgen",
uvRating: "UV",
fireDanger: "Brand"
}
case "pl" :
return {
feelsLike: "Odczuwalne",
maxToday: "Najwyższa dziś:",
minToday: "Najniższa dziś:",
posToday: "Prognoza",
posTomorrow: "Prog. jutro",
fireDanger: "Ogień"
}
case "he" :
return {
feelsLike: "מרגיש כמו:",
maxToday: "מקסימלי היום:",
}
case "da" :
return {
feelsLike: "Føles som",
maxToday: "Højeste i dag"
}
case "ru" :
return {
feelsLike: "Ощущается как:",
maxToday: "Макс. сегодня"
}
case "ua" :
return {
feelsLike: "Відчувається як",
maxToday: "Максимально сьогодні"
}
case "hu" :
return {
feelsLike: "Hőérzet",
maxToday: "Mai maximum",
minToday: "Mai minimum",
posToday: "Előrejelzés",
posTomorrow: "Holnapi",
uvRating: "UV",
fireDanger: "Tűz"
}
default :
return {
feelsLike: "Feels like",
maxToday: "Today's High",
minToday: "Today's Low",
posToday: "Forecast",
posTomorrow: "Fore Tom",
uvRating: "UV",
fireDanger: "Fire"
}
}
}
// #####
// ##### dayOrNight : returns day or night depending on the position of the sun.
// #####
get dayOrNight() {
const transformDayNight = { "below_horizon": "night", "above_horizon": "day", };
return this.config.entity_sun && this._hass.states[this.config.entity_sun] !== undefined ? transformDayNight[this._hass.states[this.config.entity_sun].state] : 'day';
}
// #####
// ##### weatherIcons: returns icon names based on current conditions text
// #####
get weatherIcons() {
var iconStyle = (this.config.old_icon ==="hybrid") ? `hybrid` : (this.config.old_icon ==="false") ? `false` : `true`;
var sunny_icon = (iconStyle ==="true") ? `${this.dayOrNight}` : (iconStyle ==="hybrid") ? `sunny-${this.dayOrNight}` : `sunny-${this.dayOrNight}`;
var clear_icon = (iconStyle ==="true") ? `${this.dayOrNight}` : (iconStyle ==="hybrid") ? `sunny-${this.dayOrNight}` : `clear-${this.dayOrNight}`;
var mostly_sunny_icon = (iconStyle ==="true") ? `fair-${this.dayOrNight}` : (iconStyle ==="hybrid") ? `fair-${this.dayOrNight}` : `fair-${this.dayOrNight}`;
var partly_cloudy_icon = (iconStyle ==="true") ? `cloudy-${this.dayOrNight}-3` : (iconStyle ==="hybrid") ? `cloudy-${this.dayOrNight}-3` : `partly-cloudy-${this.dayOrNight}`;
var cloudy_icon = (iconStyle ==="true") ? `cloudy-original` : (iconStyle ==="hybrid") ? `cloudy-original` : `cloudy`;
var hazy_icon = (iconStyle ==="true") ? `cloudy-${this.dayOrNight}-1` : (iconStyle ==="hybrid") ? `haze` : `haze`;
var frost_icon = (iconStyle ==="true") ? `cloudy-${this.dayOrNight}-1` : (iconStyle ==="hybrid") ? `cloudy-${this.dayOrNight}-1` : `cloudy-${this.dayOrNight}-1`;
var light_rain_icon = (iconStyle ==="true") ? `rainy-1` : (iconStyle ==="hybrid") ? `rainy-1-${this.dayOrNight}` : `rainy-1-${this.dayOrNight}` ;
var windy_icon = (iconStyle ==="true") ? `cloudy-original` : (iconStyle ==="hybrid") ? `wind` : `wind`;
var fog_icon = (iconStyle ==="true") ? `cloudy-original` : (iconStyle ==="hybrid") ? `fog` : `fog`;
var showers_icon = (iconStyle ==="true") ? `rainy-1` : (iconStyle ==="hybrid") ? `rainy-1-${this.dayOrNight}` : `rainy-1-${this.dayOrNight}`;
var rain_icon = (iconStyle ==="true") ? `rainy-5` : (iconStyle ==="hybrid") ? `rainy-5` : `rain`;
var dust_icon = (iconStyle ==="true") ? `cloudy-${this.dayOrNight}-1` : (iconStyle ==="hybrid") ? `haze` : `haze`;
var snow_icon = (iconStyle ==="true") ? `snowy-6` : (iconStyle ==="hybrid") ? `snowy-6` : `snow`;
var snow_rain_icon = (iconStyle ==="true") ? `snowy-6` : (iconStyle ==="hybrid") ? `rain-and-snow-mix` : `rain-and-snow-mix`;
var storm_icon = (iconStyle ==="true") ? `scattered-thunderstorms` : (iconStyle ==="hybrid") ? `scattered-thunderstorms` : `scattered-thunderstorms`;
var light_showers_icon = (iconStyle ==="true") ? `rainy-2` : (iconStyle ==="hybrid") ? `rainy-2` : `rainy-2`;
var heavy_showers_icon = (iconStyle ==="true") ? `rainy-6` : (iconStyle ==="hybrid") ? `rainy-6` : `rainy-6`;
var cyclone_icon = (iconStyle ==="true") ? `tornado` : (iconStyle ==="hybrid") ? `tornado` : `tornado`;
var clear_day_icon = (iconStyle ==="true") ? `day` : (iconStyle ==="hybrid") ? `day` : `clear-day`;
var clear_night_icon = (iconStyle ==="true") ? `night` : (iconStyle ==="hybrid") ? `night` : `clear-night`;
var sleet_icon = (iconStyle ==="true") ? `rainy-2` : (iconStyle ==="hybrid") ? `rain-and-sleet-mix` : `rain-and-sleet-mix`;
var partly_cloudy_day_icon = (iconStyle ==="true") ? `cloudy-day-3` : (iconStyle ==="hybrid") ? `cloudy-day-3` : `partly-cloudy-day`;
var partly_cloudy_night_icon = (iconStyle ==="true") ? `cloudy-night-3` : (iconStyle ==="hybrid") ? `cloudy-night-3` : `partly-cloudy-night`;
var hail_icon = (iconStyle ==="true") ? `rainy-7` : (iconStyle ==="hybrid") ? `rainy-7` : `rainy-7`;
var lightning_icon = (iconStyle ==="true") ? `thunder` : (iconStyle ==="hybrid") ? `thunder` : `thunder`;
var windy_variant_icon = (iconStyle ==="true") ? `cloudy-${this.dayOrNight}-3` : (iconStyle ==="hybrid") ? `cloudy-${this.dayOrNight}-3` : `cloudy-${this.dayOrNight}-3`;
return {
'sunny': sunny_icon,
'clear': clear_icon,
'mostly-sunny': mostly_sunny_icon,
'partly-cloudy': partly_cloudy_icon,
'mostly_sunny': mostly_sunny_icon,
'partly_cloudy': partly_cloudy_icon,
'partlycloudy': partly_cloudy_icon,
'cloudy': cloudy_icon,
'hazy': hazy_icon,
'hazey': hazy_icon,
'haze': hazy_icon,
'frost': frost_icon,
'light-rain': light_rain_icon,
'light_rain': light_rain_icon,
'wind': windy_icon,
'windy': windy_icon,
'fog': fog_icon,
'foggy': fog_icon,
'showers': showers_icon,
'shower': showers_icon,
'rain': rain_icon,
'rainy': rain_icon,
'dust': dust_icon,
'dusty': dust_icon,
'snow': snow_icon,
'snowy': snow_icon,
'snowy-rainy': snow_rain_icon,
'snowy_rainy': snow_rain_icon,
'snowyrainy': snow_rain_icon,
'storm': storm_icon,
'stormy': storm_icon,
'light-showers': light_showers_icon,
'light-shower': light_showers_icon,
'heavy-showers': heavy_showers_icon,
'heavy-shower': heavy_showers_icon,
'light_showers': light_showers_icon,
'light_shower': light_showers_icon,
'heavy_showers': heavy_showers_icon,
'heavy_shower': heavy_showers_icon,
'pouring': heavy_showers_icon,
'tropical-cyclone': cyclone_icon,
'tropical_cyclone': cyclone_icon,
'tropicalcyclone': cyclone_icon,
'clear-day': clear_day_icon,
'clear-night': clear_night_icon,
'clear_day': clear_day_icon,
'clear_night': clear_night_icon,
'sleet': sleet_icon,
'partly-cloudy-day': partly_cloudy_day_icon,
'partly-cloudy-night': partly_cloudy_night_icon,
'partly_cloudy_day': partly_cloudy_day_icon,
'partly_cloudy_night': partly_cloudy_night_icon,
'hail': hail_icon,
'lightning': lightning_icon,
'lightning-rainy': lightning_icon,
'lightning_rainy': lightning_icon,
'thunderstorm': lightning_icon,
'windy-variant': windy_variant_icon,
'windy_variant': windy_variant_icon,
'exceptional': '!!',
}
}
// #####
// ##### forecast : returns forcasted weather information for the next 5 days
// #####
get forecast() {
var forecastDate1 = new Date();
forecastDate1.setDate(forecastDate1.getDate()+1);
var forecastDate2 = new Date();
forecastDate2.setDate(forecastDate2.getDate()+2);
var forecastDate3 = new Date();
forecastDate3.setDate(forecastDate3.getDate()+3);
var forecastDate4 = new Date();
forecastDate4.setDate(forecastDate4.getDate()+4);
var forecastDate5 = new Date();
forecastDate5.setDate(forecastDate5.getDate()+5);
const forecast1 = { date: forecastDate1,
dayIndex: '1',
condition: this.config.entity_forecast_icon_1,
temphigh: this.config.entity_forecast_high_temp_1,
templow: this.config.entity_forecast_low_temp_1,
pop: this.config.entity_pop_1,
pos: this.config.entity_pos_1,
summary: this.config.entity_summary_1, };
const forecast2 = { date: forecastDate2,
dayIndex: '2',
condition: this.config.entity_forecast_icon_2,
temphigh: this.config.entity_forecast_high_temp_2,
templow: this.config.entity_forecast_low_temp_2,
pop: this.config.entity_pop_2,
pos: this.config.entity_pos_2,
summary: this.config.entity_summary_2, };
const forecast3 = { date: forecastDate3,
dayIndex: '3',
condition: this.config.entity_forecast_icon_3,
temphigh: this.config.entity_forecast_high_temp_3,
templow: this.config.entity_forecast_low_temp_3,
pop: this.config.entity_pop_3,
pos: this.config.entity_pos_3,
summary: this.config.entity_summary_3, };
const forecast4 = { date: forecastDate4,
dayIndex: '4',
condition: this.config.entity_forecast_icon_4,
temphigh: this.config.entity_forecast_high_temp_4,
templow: this.config.entity_forecast_low_temp_4,
pop: this.config.entity_pop_4,
pos: this.config.entity_pos_4,
summary: this.config.entity_summary_4, };
const forecast5 = { date: forecastDate5,
dayIndex: '5',
condition: this.config.entity_forecast_icon_5,
temphigh: this.config.entity_forecast_high_temp_5,
templow: this.config.entity_forecast_low_temp_5,
pop: this.config.entity_pop_5,
pos: this.config.entity_pos_5,
summary: this.config.entity_summary_5, };
return [forecast1, forecast2, forecast3, forecast4, forecast5];
}
// #####
// ##### current : Returns current weather information
// #####
get currentConditions() {
try {
return this._hass.states[this.config.entity_current_conditions].state;
} catch (e) {
return undefined;
}
}
get currentHumidity() {
return this.config.entity_humidity ? (Number(this._hass.states[this.config.entity_humidity].state)).toLocaleString() : 0;
}
get currentPressure() {
var places = this.config.show_decimals_pressure ? Math.max(Math.min(this.config.show_decimals_pressure, 3) ,0) : 0;
return this.config.entity_pressure ? (Number(this._hass.states[this.config.entity_pressure].state)).toLocaleString(undefined, {minimumFractionDigits: places, maximumFractionDigits: places}) : 0;
}
get currentTemperature() {
try {
var places = this.config.show_decimals ? 1 : 0;
return Number(this._hass.states[this.config.entity_temperature].state).toLocaleString(undefined, {minimumFractionDigits: places, maximumFractionDigits: places});
} catch (e) {
return "Config Error";
}
}
get currentVisibility() {
return this.config.entity_visibility ? (Number(this._hass.states[this.config.entity_visibility].state)).toLocaleString() : 0;
}
get currentWindBearing() {
return this.config.entity_wind_bearing ? isNaN(this._hass.states[this.config.entity_wind_bearing].state) ? this._hass.states[this.config.entity_wind_bearing].state : this.windDirections[(Math.round((this._hass.states[this.config.entity_wind_bearing].state / 360) * 16))] : 0;
}
get currentWindSpeed() {
return this.config.entity_wind_speed ? Math.round(this._hass.states[this.config.entity_wind_speed].state) : 0;
}
get currentWindGust() {
return this.config.entity_wind_gust ? Math.round(this._hass.states[this.config.entity_wind_gust].state) : 0;
}
get currentWindSpeedKt() {
return this.config.entity_wind_speed_kt ? Math.round(this._hass.states[this.config.entity_wind_speed_kt].state) : 0;
}
get currentWindGustKt() {
return this.config.entity_wind_gust_kt ? Math.round(this._hass.states[this.config.entity_wind_gust_kt].state) : 0;
}
get currentApparent() {
try {
var places = this.config.show_decimals ? 1 : 0;
return this.config.entity_apparent_temp ? Number(this._hass.states[this.config.entity_apparent_temp].state).toLocaleString(undefined, {minimumFractionDigits: places, maximumFractionDigits: places}) : 0;
} catch (e) {
return "Config Error";
}
}
get currentBeaufort() {
return this.config.show_beaufort ? html`Bft: ${this.beaufortWind} - ` : ``;
}
get currentBeaufortkt() {
return this.config.show_beaufort ? html`Bft: ${this.beaufortWindKt} - ` : ``;
}
// #####
// ##### sunSetAndRise: returns set and rise information
// #####
get sunSet() {
var nextSunSet;
var nextSunRise;
if (this.is12Hour) {
nextSunSet = new Date(this._hass.states[this.config.entity_sun].attributes.next_setting).toLocaleTimeString(this.config.locale, {hour: 'numeric', minute: '2-digit', hour12: true});
nextSunRise = new Date(this._hass.states[this.config.entity_sun].attributes.next_rising).toLocaleTimeString(this.config.locale, {hour: 'numeric', minute: '2-digit', hour12: true});
} else {
nextSunSet = new Date(this._hass.states[this.config.entity_sun].attributes.next_setting).toLocaleTimeString(this.config.locale, {hour: '2-digit', minute: '2-digit', hour12: false});
nextSunRise = new Date(this._hass.states[this.config.entity_sun].attributes.next_rising).toLocaleTimeString(this.config.locale, {hour: '2-digit', minute: '2-digit', hour12: false});
}
var nextDate = new Date();
nextDate.setDate(nextDate.getDate() + 1);
if (this._hass.states[this.config.entity_sun].state == "above_horizon" ) {
nextSunRise = nextDate.toLocaleDateString(this.config.locale,{weekday: 'short'}) + " " + nextSunRise;
return {
'next': html`<li><span class="ha-icon"><ha-icon id="sun-next-icon" icon="mdi:weather-sunset-down"></ha-icon></span><span id="sun-next-text">${nextSunSet}</span></li>`,
'following': html`<li><span class="ha-icon"><ha-icon id="sun-following-icon" icon="mdi:weather-sunset-up"></ha-icon></span><span id="sun-following-text">${nextSunRise}</span></li>`,
'nextText': nextSunSet,
'followingText': nextSunRise,
'nextIcon': "mdi:weather-sunset-down",
'followingIcon': "mdi:weather-sunset-up",
};
} else {
if (new Date().getDate() != new Date(this._hass.states[this.config.entity_sun].attributes.next_rising).getDate()) {
nextSunRise = nextDate.toLocaleDateString(this.config.locale,{weekday: 'short'}) + " " + nextSunRise;
nextSunSet = nextDate.toLocaleDateString(this.config.locale,{weekday: 'short'}) + " " + nextSunSet;
}
return {
'next': html`<li><span class="ha-icon"><ha-icon id="sun-next-icon" icon="mdi:weather-sunset-up"></ha-icon></span><span id="sun-next-text">${nextSunRise}</span></li>`,
'following': html`<li><span class="ha-icon"><ha-icon id="sun-following-icon" icon="mdi:weather-sunset-down"></ha-icon></span><span id="sun-following-text">${nextSunSet}</span></li>`,
'nextText': nextSunRise,
'followingText': nextSunSet,
'nextIcon': "mdi:weather-sunset-up",
'followingIcon': "mdi:weather-sunset-down",
};
}
}
// #####
// ##### beaufortWind - returns the wind speed on the beaufort scale
// ##### reference https://en.wikipedia.org/wiki/Beaufort_scale
// #####
get beaufortWind() {
if (this.config.entity_wind_speed) {
switch (this._hass.states[this.config.entity_wind_speed].attributes.unit_of_measurement) {
case 'mph':
if (this._hass.states[this.config.entity_wind_speed].state >= 73) return 12;
if (this._hass.states[this.config.entity_wind_speed].state >= 64) return 11;
if (this._hass.states[this.config.entity_wind_speed].state >= 55) return 10;
if (this._hass.states[this.config.entity_wind_speed].state >= 47) return 9;
if (this._hass.states[this.config.entity_wind_speed].state >= 39) return 8;
if (this._hass.states[this.config.entity_wind_speed].state >= 32) return 7;
if (this._hass.states[this.config.entity_wind_speed].state >= 25) return 6;
if (this._hass.states[this.config.entity_wind_speed].state >= 19) return 5;
if (this._hass.states[this.config.entity_wind_speed].state >= 13) return 4;
if (this._hass.states[this.config.entity_wind_speed].state >= 8) return 3;
if (this._hass.states[this.config.entity_wind_speed].state >= 4) return 2;
if (this._hass.states[this.config.entity_wind_speed].state >= 1) return 1;
case 'm/s':
if (this._hass.states[this.config.entity_wind_speed].state >= 32.7) return 12;
if (this._hass.states[this.config.entity_wind_speed].state >= 28.5) return 11;
if (this._hass.states[this.config.entity_wind_speed].state >= 24.5) return 10;
if (this._hass.states[this.config.entity_wind_speed].state >= 20.8) return 9;
if (this._hass.states[this.config.entity_wind_speed].state >= 17.2) return 8;
if (this._hass.states[this.config.entity_wind_speed].state >= 13.9) return 7;
if (this._hass.states[this.config.entity_wind_speed].state >= 10.8) return 6;
if (this._hass.states[this.config.entity_wind_speed].state >= 8) return 5;
if (this._hass.states[this.config.entity_wind_speed].state >= 5.5) return 4;
if (this._hass.states[this.config.entity_wind_speed].state >= 3.4) return 3;
if (this._hass.states[this.config.entity_wind_speed].state >= 1.6) return 2;
if (this._hass.states[this.config.entity_wind_speed].state >= 0.5) return 1;
default: // Assume km/h
if (this._hass.states[this.config.entity_wind_speed].state >= 118) return 12;
if (this._hass.states[this.config.entity_wind_speed].state >= 103) return 11;
if (this._hass.states[this.config.entity_wind_speed].state >= 89) return 10;
if (this._hass.states[this.config.entity_wind_speed].state >= 75) return 9;
if (this._hass.states[this.config.entity_wind_speed].state >= 62) return 8;
if (this._hass.states[this.config.entity_wind_speed].state >= 50) return 7;
if (this._hass.states[this.config.entity_wind_speed].state >= 39) return 6;
if (this._hass.states[this.config.entity_wind_speed].state >= 29) return 5;
if (this._hass.states[this.config.entity_wind_speed].state >= 20) return 4;
if (this._hass.states[this.config.entity_wind_speed].state >= 12) return 3;
if (this._hass.states[this.config.entity_wind_speed].state >= 6) return 2;
if (this._hass.states[this.config.entity_wind_speed].state >= 2) return 1;
}
}
return 0;
}
get beaufortWindKt() {
if (this.config.entity_wind_speed_kt) {
if (this._hass.states[this.config.entity_wind_speed_kt].state >= 64) return 12;
if (this._hass.states[this.config.entity_wind_speed_kt].state >= 56) return 11;
if (this._hass.states[this.config.entity_wind_speed_kt].state >= 48) return 10;
if (this._hass.states[this.config.entity_wind_speed_kt].state >= 41) return 9;
if (this._hass.states[this.config.entity_wind_speed_kt].state >= 34) return 8;
if (this._hass.states[this.config.entity_wind_speed_kt].state >= 28) return 7;
if (this._hass.states[this.config.entity_wind_speed_kt].state >= 22) return 6;
if (this._hass.states[this.config.entity_wind_speed_kt].state >= 17) return 5;
if (this._hass.states[this.config.entity_wind_speed_kt].state >= 11) return 4;
if (this._hass.states[this.config.entity_wind_speed_kt].state >= 7) return 3;
if (this._hass.states[this.config.entity_wind_speed_kt].state >= 4) return 2;
if (this._hass.states[this.config.entity_wind_speed_kt].state >= 1) return 1;
}
return 0;
}
// #####
// ##### is12Hour - returns true if 12 hour clock or false if 24
// #####
get is12Hour() {
var hourFormat= this.config.time_format ? this.config.time_format : 12
switch (hourFormat) {
case 24:
return false;
default:
return true;
}
}
// #####
// ##### style: returns the CSS style classes for the card
// ####
style() {
// Get config flags or set defaults if not configured
var tooltipBGColor = this.config.tooltip_bg_color || "rgb( 75,155,239)";
var tooltipFGColor = this.config.tooltip_fg_color || "#fff";
var tooltipBorderColor = this.config.tooltip_border_color || "rgb(255,161,0)";
var tooltipBorderWidth = this.config.tooltip_border_width || "1";
var tooltipCaretSize = this.config.tooltip_caret_size || "5";
var tooltipWidth = this.config.tooltip_width || "110";
var tooltipLeftOffset = this.config.tooltip_left_offset || "-12";
var tooltipVisible = this.config.tooltips ? "visible" : "hidden";
var tempTopMargin = this.config.temp_top_margin || "0px";
var tempFontWeight = this.config.temp_font_weight || "300";
var tempFontSize = this.config.temp_font_size || "4em";
var tempRightPos = this.config.temp_right_pos || "0.85em";
var tempUOMTopMargin = this.config.temp_uom_top_margin || "-12px";
var tempUOMRightMargin = this.config.temp_uom_right_margin || "4px";
var apparentTopMargin = this.config.apparent_top_margin || "45px";
var apparentRightPos = this.config.apparent_right_pos || "1em";
var apparentRightMargin = this.config.apparent_right_margin || "1em";
var currentTextTopMargin = this.config.current_text_top_margin || "4.5em";
var currentTextLeftPos = this.config.current_text_left_pos || "0px";
var currentTextFontSize = this.config.current_text_font_size || "1.5em";
var currentTextWidth = this.config.current_text_width || "100%";
var currentTextAlignment = this.config.current_text_alignment || "center";
var largeIconTopMargin = this.config.large_icon_top_margin || "-3.2em";
var largeIconLeftPos = this.config.large_icon_left_pos || "0px";
var currentDataTopMargin = this.config.current_data_top_margin ? this.config.current_data_top_margin : this.config.show_separator ? "1em" : "10em";
var separatorTopMargin = this.config.separator_top_margin || "6em";
var summaryTopPadding = this.config.summary_top_padding || "2em";
var summaryFontSize = this.config.summary_font_size || "0.8em";
return html`
.clear {
clear: both;
line-height:1.2;
}
.card {
margin: auto;
padding-top: 2em;
padding-bottom: 1em;
padding-left: 1em;
padding-right: 1em;
position: relative;
}
.ha-icon {
height: 18px;
margin-right: 5px;
color: var(--paper-item-icon-color);
}
.ha-icon2 {
height: 50px;
margin-right: 5px;
color: var(--paper-item-icon-color);
}
.line {
margin-top: ${separatorTopMargin};
margin-left: 1em;
margin-right: 1em;
}
.temp {
font-weight: ${tempFontWeight};
font-size: ${tempFontSize};
color: var(--primary-text-color);
position: absolute;
right: ${tempRightPos};
margin-top: ${tempTopMargin} !important;
}
.tempc {
font-weight: ${tempFontWeight};
font-size: 1.5em;
vertical-align: super;
color: var(--primary-text-color);
position: absolute;
right: 1em;
margin-top: ${tempUOMTopMargin} !important;
margin-right: ${tempUOMRightMargin} !important;
}
.apparent {
color: var(--primary-text-color);
position: absolute;
right: ${apparentRightPos};
margin-top: ${apparentTopMargin};
margin-right: ${apparentRightMargin};
}
.currentText {
font-size: ${currentTextFontSize};
color: var(--secondary-text-color);
position: absolute;
overflow: hidden;
white-space: nowrap;
left: ${currentTextLeftPos};
margin-top: ${currentTextTopMargin};
text-align: ${currentTextAlignment};
width: ${currentTextWidth};
padding-bottom: 0.2em;
}
.pop {
font-weight: 400;
color: var(--primary-text-color);
}
.pos {
font-weight: 400;
color: var(--primary-text-color);
}
.variations {
display: flex;
flex-flow: row wrap;
justify-content: space-between;
font-weight: 300;
color: var(--primary-text-color);
list-style: none;
padding: 0.2em;
margin-top: ${currentDataTopMargin};
}
.slotlist {
flex-grow: 1;
}
.variations-ugly {
display: flex;
flex-flow: row wrap;
justify-content: space-between;
font-weight: 300;
color: var(--primary-text-color);