forked from lgkahn/hubitat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
darksky.groovy
1630 lines (1531 loc) · 97.5 KB
/
darksky.groovy
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
/*
DarkSky.net Weather Driver
Import URL: https://raw.githubusercontent.com/HubitatCommunity/DarkSky.net-Weather-Driver/master/DarkSky.net%20Weather%20Driver.groovy
Copyright 2020 @Matthew (Scottma61)
Many people contributed to the creation of this driver. Significant contributors include:
- @Cobra who adapted it from @mattw01's work and I thank them for that!
- @bangali for his original APIXU.COM base code that much of the early versions of this driver was
adapted from.
- @bangali for his the Sunrise-Sunset.org code used to calculate illuminance/lux and the more
recent adaptations of that code from @csteele in his continuation driver 'wx-ApiXU'.
- @csteele (and prior versions from @bangali) for the attribute selection code.
- @csteele for his examples on how to convert to asyncHttp calls to reduce Hub resource utilization.
- @bangali also contributed the icon work from
https://github.com/jebbett for new cooler 'Alternative' weather icons with icons courtesy
of https://www.deviantart.com/vclouds/art/VClouds-Weather-Icons-179152045.
- @storageanarchy for his Dark Sky Icon mapping and some new icons to compliment the Vclouds set.
- @nh.schottfam for lots of code clean up and optimizations.
In addition to all the cloned code from the Hubitat community, I have heavily modified/created new
code myself @Matthew (Scottma61) with lots of help from the Hubitat community. If you believe you
should have been acknowledged or received attribution for a code contribution, I will happily do so.
While I compiled and orchestrated the driver, very little is actually original work of mine.
This driver is free to use. I do not accept donations. Please feel free to contribute to those
mentioned here if you like this work, as it would not have been possible without them.
This driver is intended to pull weather data from DarkSky.net (http://darksky.net). You will need your
DarkSky API key to use the data from that site.
You can select to use a base set of condition icons from the forecast source, or an 'alternative'
(fancier) set. The base 'Standard' icon set will be from WeatherUnderground. You may choose the
fancier 'Alternative' icon set if you use the Dark Sky.
The driver exposes both metric and imperial measurements for you to select from.
Licensed under the Apache License, Version 2.0 (the 'License'); you may not use this file except
in compliance with the License. You may obtain a copy of the License at:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
for the specific language governing permissions and limitations under the License.
Last Update 04/20/2020
{ Left room below to document version changes...}
V1.4.1 Refactored much of the code and added compatitibility with Hubitat Package Manager- 04/20/2020
V1.4.0 Code clean up and ptimization (Thanks @nh.schottfam), better logging - 04/19/2020
V1.3.9 More checks of coordinates to prevent/warn of null values - 03/26/2020
V1.3.8 Added some debugging helpers and code to remove any spaces in location coordinates- 03/22/2020
V1.3.7 Allow location override. Corrected forecastHigh/Low to 'number' from 'string' - 03/20/2020
V1.3.6 Changed links for they Open in new tabs/windows. - 03/01/2020
V1.3.5 Enhancements to myTile and threedayfcstTile, NEW alterTile - 02/28/2020
V1.3.4 Changed forecasts to use temperatureMax/Min instead of temperatureHigh/Low - 02/27/2020
from the Dark Sky API to match their website presentation.
V1.3.3 Updated (reduced) logging and the behavior of 'refresh' (use 'pollData' instead - 02/26/2020
to force a polling of data.
V1.3.2 Further bug squashing - 02/24/2020 8:20 PM EDT
V1.3.1 Corrected bug from 1.3.0 that made some attrubutes strings instead of numbers - 02/24/2020
V1.3.0 Added ability to select displayed decimals - 02/23/2020
V1.2.9 Fixed pressured definition to avoid excess events - 12/15/2019
V1.2.8 Exposed 'feelsLike' so it gets updated - 11/11/2019
V1.2.7 Force three day forcast icons to be 'daytime' (instead of 'nighttime') - 10/23/2019
V1.2.6 Changed 'pressure' to a number from a string, added 'pressured' as a string. - 10/22/2019
V1.2.5 Added three day forecast tile - 10/22/2019
V1.2.4 added meters per second ('m/s') for wind and hectopascals for pressure - 10/14/2019
V1.2.3 forecastIcon & weatherIcon fix. Tuned Lux for 'fully nighttime' - 10/13/2019
V1.2.2 Bug fix for is_day/is_light - 10/02/2019
V1.2.1 Added ability to show 'knots' for wind/gust speeds - 10/01/2019
V1.2.0 Eliminated 'Std' Icons. Reworked condition_code/condition_text. - 09/30/2019
V1.1.9 myTile format tweaking - 09/29/2019
V1.1.8 Bug fixes, optimizations, Added 'wind' and lux jitter control - 09/28/2019
V1.1.7 More myTile 'display:inline' corrections - 09/28/2019
V1.1.6 myTile 'display:inline' correction - 09/27/2019
V1.1.5 myTile enhancement for excessive length - 09/27/2019
V1.1.4 Prevent myTile from exceeding 1,024 characters - 09/26/2019
V1.1.3 Corrected myTile for 'alert' condition - 09/26/2019
V1.1.2 - Added 'wind_cardinal', more code optimization and cleanup - 09/25/2019
V1.1.1 - Corrected MoonPhase, optimized lux updates and code optimizations re-organized - 09/24/2019
preference order and some goupings of 'optional' attributes.
V1.1.0 - Randomized schedule start times, Added 'Powered by DarkSky' attribution - 09/18/2019
V1.0.9 - Default to 'TinyURL' for icon location, added log when changeing schedule - 09/16/2019
V1.0.8 - Changed icon location to prevent duplication - Please update icon file location - 09/16/2019
V1.0.7 - Moved driver to the HubitatCommunity github, added 'Nighttime' schedule option - 09/16/2019
added upDateCheck() to show if driver is current (thanks @csteele)
V1.0.6 - Another optional attribute bug fix. - 09/15/2019
V1.0.5 - Tweaking and bug fixes. - 09/14/2019
V1.0.4 - Added 'weatherIcons' used for OWM icons/dashboard - 09/14/2019
V1.0.3 - Added windSpeed and windDirection, required for some dashboards. - 09/14/2019
V1.0.2 - Attribute now dislplayed for dashboards ** Read caution below ** - 09/14/2019
V1.0.1 - Bug fixes. - 09/13/2019
V1.0.0 - Initial release of driver with ApiXU.com completely removed. - 09/13/2019
=========================================================================================================
**ATTRIBUTES CAUTION**
The way the 'optional' attributes work:
- Initially, only the optional attributes selected will show under 'Current States' and will be available
in dashboards.
- Once an attribute has been selected it too will show under 'Current States' and be available in dashboards.
<*** HOWEVER ***> If you ever de-select the optional attribute, it will still show under 'Current States'
and will still show as an attribute for dashboards **BUT IT'S DATA WILL NO LONGER BE REFRESHED WITH DATA
POLLS**. This means what is shown on the 'Current States' and dashboard tiles for de-selected attributes
may not be current valid data.
- To my knowledge, the only way to remove the de-selected attribute from 'Current States' and not show it as
available in the dashboard is to delete the virtual device and create a new one AND DO NOT SELECT the
attribute you do not want to show.
*/
public static String version() { return '1.4.1' }
import groovy.transform.Field
metadata {
definition (name: 'DarkSky.net Weather Driver',
namespace: 'Matthew',
author: 'Scottma61',
importUrl: 'https://raw.githubusercontent.com/HubitatCommunity/DarkSky.net-Weather-Driver/master/DarkSky.net%20Weather%20Driver.groovy') {
capability 'Sensor'
capability 'Temperature Measurement'
capability 'Illuminance Measurement'
capability 'Relative Humidity Measurement'
capability 'Pressure Measurement'
capability 'Ultraviolet Index'
capability 'Refresh'
attributesMap.each {
k, v -> if (v.typeof) attribute k , v.typeof
}
// The following attributes may be needed for dashboards that require these attributes,
// so they are alway available and shown by default.
attribute 'city', 'string' //Hubitat OpenWeather SharpTool.io SmartTiles
attribute 'feelsLike', 'number' //SharpTool.io SmartTiles
attribute 'forecastIcon', 'string' //SharpTool.io
attribute 'localSunrise', 'string' //SharpTool.io SmartTiles
attribute 'localSunset', 'string' //SharpTool.io SmartTiles
attribute 'percentPrecip', 'number' //SharpTool.io SmartTiles
attribute 'pressured', 'string' //UNSURE SharpTool.io SmartTiles
attribute 'weather', 'string' //SharpTool.io SmartTiles
attribute 'weatherIcon', 'string' //SharpTool.io SmartTiles
attribute 'weatherIcons', 'string' //Hubitat openWeather
attribute 'wind', 'number' //SharpTool.io
attribute 'windDirection', 'number' //Hubitat OpenWeather
attribute 'windSpeed', 'number' //Hubitat OpenWeather
// The attributes below are sub-groups of optional attributes. They need to be listed here to be available
//alert
attribute 'alert', 'string'
attribute 'alertTile', 'string'
//threedayTile
attribute 'threedayfcstTile', 'string'
//DSAttribution
attribute 'dsIcondarktext', 'string'
attribute 'dsIconlighttext', 'string'
//fcstHighLow
attribute 'forecastHigh', 'number'
attribute 'forecastLow', 'number'
// controlled with localSunrise
attribute 'tw_begin', 'string'
attribute 'sunriseTime', 'string'
attribute 'noonTime', 'string'
attribute 'sunsetTime', 'string'
attribute 'tw_end', 'string'
//obspoll these are the same value...
attribute 'last_poll_Forecast', 'string'
attribute 'last_observation_Forecast', 'string'
//precipExtended
attribute 'rainDayAfterTomorrow', 'number'
attribute 'rainTomorrow', 'number'
//nearestStorm
attribute 'nearestStormBearing', 'string'
attribute 'nearestStormCardinal', 'string'
attribute 'nearestStormDirection', 'string'
attribute 'nearestStormDistance', 'number'
command 'pollData'
}
def settingDescr = settingEnable ? '<br><i>Hide many of the optional attributes to reduce the clutter, if needed, by turning OFF this toggle.</i><br>' : '<br><i>Many optional attributes are available to you, if needed, by turning ON this toggle.</i><br>'
def logDescr = '<br><i>Extended logging will turn off automatically after 30 minutes.</i><br>'
preferences() {
section('Query Inputs'){
input 'apiKey', 'text', required: true, title: 'Type DarkSky.net API Key Here', defaultValue: null
input 'city', 'text', required: true, defaultValue: 'City or Location name forecast area', title: 'City name'
input 'pollIntervalForecast', 'enum', title: 'External Source Poll Interval (daytime)', required: true, defaultValue: '3 Hours', options: ['Manual Poll Only', '2 Minutes', '5 Minutes', '10 Minutes', '15 Minutes', '30 Minutes', '1 Hour', '3 Hours']
input 'pollIntervalForecastnight', 'enum', title: 'External Source Poll Interval (nighttime)', required: true, defaultValue: '3 Hours', options: ['Manual Poll Only', '2 Minutes', '5 Minutes', '10 Minutes', '15 Minutes', '30 Minutes', '1 Hour', '3 Hours']
input 'logSet', 'bool', title: 'Enable extended Logging', description: '<i>Extended logging will turn off automatically after 30 minutes.</i>', required: true, defaultValue: false
input 'tempFormat', 'enum', required: true, defaultValue: 'Fahrenheit (°F)', title: 'Display Unit - Temperature: Fahrenheit (°F) or Celsius (°C)', options: ['Fahrenheit (°F)', 'Celsius (°C)']
input 'TWDDecimals', 'enum', required: true, defaultValue: '0', title: 'Display decimals for Temperature & Wind Speed', options: [0:'0', 1:'1', 2:'2', 3:'3', 4:'4']
input 'PDecimals', 'enum', required: true, defaultValue: '0', title: 'Display decimals for Pressure', options: [0:'0', 1:'1', 2:'2', 3:'3', 4:'4']
input 'datetimeFormat', 'enum', required: true, defaultValue: '1', title: 'Display Unit - Date-Time Format', options: [1:'m/d/yyyy 12 hour (am|pm)', 2:'m/d/yyyy 24 hour', 3:'mm/dd/yyyy 12 hour (am|pm)', 4:'mm/dd/yyyy 24 hour', 5:'d/m/yyyy 12 hour (am|pm)', 6:'d/m/yyyy 24 hour', 7:'dd/mm/yyyy 12 hour (am|pm)', 8:'dd/mm/yyyy 24 hour', 9:'yyyy/mm/dd 24 hour']
input 'distanceFormat', 'enum', required: true, defaultValue: 'Miles (mph)', title: 'Display Unit - Distance/Speed: Miles, Kilometers, knots or meters', options: ['Miles (mph)', 'Kilometers (kph)', 'knots', 'meters (m/s)']
input 'pressureFormat', 'enum', required: true, defaultValue: 'Inches', title: 'Display Unit - Pressure: Inches or Millibar/Hectopascal', options: ['Inches', 'Millibar', 'Hectopascal']
input 'rainFormat', 'enum', required: true, defaultValue: 'Inches', title: 'Display Unit - Precipitation: Inches or Millimeters', options: ['Inches', 'Millimeters']
input 'luxjitter', 'bool', title: 'Use lux jitter control (rounding)?', required: true, defaultValue: false
input 'iconLocation', 'text', required: true, defaultValue: 'https://tinyurl.com/y6xrbhpf/', title: 'Alternative Icon Location:'
input 'iconType', 'bool', title: 'Condition Icon: On = Current - Off = Forecast', required: true, defaultValue: false
input 'dsIconbackgrounddark', 'bool', required: true, defaultValue: false, title: 'DarkSky logo text color for myTile/weatherSummary: On = Dark - Off = Light'
input 'altCoord', 'bool', required: true, defaultValue: false, title: 'Override Hub\'s location coordinates'
if (altCoord) {
input 'altLat', 'string', title: 'Override location Latitude', required: true, defaultValue: location.latitude.toString(), description: '<br>Enter location Latitude<br>'
input 'altLon', 'string', title: 'Override location Longitude', required: true, defaultValue: location.longitude.toString(), description: '<br>Enter location Longitude<br>'
}
input 'settingEnable', 'bool', title: '<b>Display All Optional Attributes</b>', description: settingDescr, defaultValue: true
// build a Selector for each mapped Attribute or group of attributes
attributesMap.each {
keyname, attribute ->
if (settingEnable) {
input keyname+'Publish', 'bool', title: attribute.title, required: true, defaultValue: attribute.default, description: '<br>' + attribute.descr + '<br>'
if(keyname == 'weatherSummary') input 'summaryType', 'bool', title: 'Full Weather Summary', description: '<br>Full: ON or short: OFF summary?<br>', required: true, defaultValue: false
}
}
if (settingEnable) {
input 'windPublish', 'bool', title: 'Wind Speed', required: true, defaultValue: 'false', description: '<br>Display \'wind\' speed<br>'
}
}
}
}
// <<<<<<<<<< Begin Sunrise-Sunset Poll Routines >>>>>>>>>>
void pollSunRiseSet() {
currDate = new Date().format('yyyy-MM-dd', TimeZone.getDefault())
LOGINFO('Polling Sunrise-Sunset.org')
def requestParams = [ uri: 'https://api.sunrise-sunset.org/json?lat=' + altLat + '&lng=' + altLon + '&formatted=0' ]
if (currDate) {requestParams = [ uri: 'https://api.sunrise-sunset.org/json?lat=' + altLat + '&lng=' + altLon + '&formatted=0&date=' + currDate ]}
LOGINFO('Poll Sunrise-Sunset: ' + requestParams)
asynchttpGet('sunRiseSetHandler', requestParams)
}
void sunRiseSetHandler(resp, data) {
if(resp.getStatus() == 200 || resp.getStatus() == 207) {
sunRiseSet = resp.getJson().results
updateDataValue('sunRiseSet', resp.data)
LOGINFO('Sunrise-Sunset Data: ' + sunRiseSet)
setDateTimeFormats(datetimeFormat)
updateDataValue('riseTime', new Date().parse('yyyy-MM-dd\'T\'HH:mm:ssXXX', sunRiseSet.sunrise).format('HH:mm', TimeZone.getDefault()))
updateDataValue('noonTime', new Date().parse('yyyy-MM-dd\'T\'HH:mm:ssXXX', sunRiseSet.solar_noon).format('HH:mm', TimeZone.getDefault()))
updateDataValue('setTime', new Date().parse('yyyy-MM-dd\'T\'HH:mm:ssXXX', sunRiseSet.sunset).format('HH:mm', TimeZone.getDefault()))
updateDataValue('tw_begin', new Date().parse('yyyy-MM-dd\'T\'HH:mm:ssXXX', sunRiseSet.civil_twilight_begin).format('HH:mm', TimeZone.getDefault()))
updateDataValue('tw_end', new Date().parse('yyyy-MM-dd\'T\'HH:mm:ssXXX', sunRiseSet.civil_twilight_end).format('HH:mm', TimeZone.getDefault()))
updateDataValue('localSunset',new Date().parse('yyyy-MM-dd\'T\'HH:mm:ssXXX', sunRiseSet.sunset).format(timeFormat, TimeZone.getDefault()))
updateDataValue('localSunrise', new Date().parse('yyyy-MM-dd\'T\'HH:mm:ssXXX', sunRiseSet.sunrise).format(timeFormat, TimeZone.getDefault()))
updateDataValue('riseTime1', new Date().parse('yyyy-MM-dd\'T\'HH:mm:ssXXX', sunRiseSet.sunrise + 86400000).format('HH:mm', TimeZone.getDefault()))
updateDataValue('riseTime2', new Date().parse('yyyy-MM-dd\'T\'HH:mm:ssXXX', sunRiseSet.sunrise + 86400000 + 86400000).format('HH:mm', TimeZone.getDefault()))
updateDataValue('setTime1', new Date().parse('yyyy-MM-dd\'T\'HH:mm:ssXXX', sunRiseSet.sunset + 86400000).format('HH:mm', TimeZone.getDefault()))
updateDataValue('setTime2', new Date().parse('yyyy-MM-dd\'T\'HH:mm:ssXXX', sunRiseSet.sunset + 86400000 + 86400000).format('HH:mm', TimeZone.getDefault()))
} else {
log.warn 'DarkSky.net Weather Driver WARNING: Sunrise-Sunset api did not return data.'
}
}
// >>>>>>>>>> End Sunrise-Sunset Poll Routines <<<<<<<<<<
// <<<<<<<<<< Begin DarkSky Poll Routines >>>>>>>>>>
void pollDS() {
if( apiKey == null ) {
log.warn 'DarkSky.net Weather Driver WARNING: DarkSky API Key not found. Please configure in preferences.'
return
}
def ParamsDS = [ uri: 'https://api.darksky.net/forecast/' + apiKey + '/' + altLat + ',' + altLon + '?units=us&exclude=minutely,hourly,flags' ]
LOGINFO('Poll DarkSky: ' + ParamsDS)
asynchttpGet('pollDSHandler', ParamsDS)
return
}
void pollDSHandler(resp, data) {
if(resp.getStatus() == 200 || resp.getStatus() == 207) {
def ds = parseJson(resp.data)
LOGINFO('DarkSkey.net Data: ' + ds)
doPollDS(ds) // parse the data returned by DarkSky
} else {
log.warn 'DarkSky.net Weather Driver WARNING: Calling https://api.darksky.net/forecast/' + apiKey + '/' + altLat + ',' + altLon + '?units=us&exclude=minutely,hourly,flags'
log.warn 'DarkSky.net Weather Driver WARNING: DarkSky weather api did not return data. ' + resp.getStatus() + ':' + resp.getErrorMessage()
}
return
}
void doPollDS(Map ds) {
// <<<<<<<<<< Begin Setup Global Variables >>>>>>>>>>
setDateTimeFormats(datetimeFormat)
setMeasurementMetrics(distanceFormat, pressureFormat, rainFormat, tempFormat)
setDisplayDecimals(TWDDecimals, PDecimals)
updateDataValue('currDate', new Date().format('yyyy-MM-dd', TimeZone.getDefault()))
updateDataValue('currTime', new Date().format('HH:mm', TimeZone.getDefault()))
if(getDataValue('riseTime') <= getDataValue('currTime') && getDataValue('setTime') >= getDataValue('currTime')) {
updateDataValue('is_day', 'true')
} else {
updateDataValue('is_day', 'false')
}
if(getDataValue('currTime') < getDataValue('tw_begin') || getDataValue('currTime') > getDataValue('tw_end')) {
updateDataValue('is_light', 'false')
} else {
updateDataValue('is_light', 'true')
}
if(getDataValue('is_light') != getDataValue('is_lightOld')) {
if(getDataValue('is_light')=='true') {
log.info('DarkSky.net Weather Driver - INFO: Switching to Daytime schedule.')
}else{
log.info('DarkSky.net Weather Driver - INFO: Switching to Nighttime schedule.')
}
initialize_poll()
updateDataValue('is_lightOld', getDataValue('is_light'))
}
// >>>>>>>>>> End Setup Global Variables <<<<<<<<<<
// <<<<<<<<<< Begin Setup Forecast Variables >>>>>>>>>>
fotime = new Date(ds.currently.time * 1000L)
updateDataValue('fotime', fotime.toString())
futime = new Date()
updateDataValue('futime', futime.toString())
// <<<<<<<<<< Begin Process Standard Weather-Station Variables (Regardless of Forecast Selection) >>>>>>>>>>
BigDecimal t_dew
if(tMetric == '°F') {
t_dew = Math.round(ds.currently.dewPoint.toBigDecimal() * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()
} else {
t_dew = Math.round((ds.currently.dewPoint.toBigDecimal() - 32) / 1.8 * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()
}
updateDataValue('dewpoint', t_dew.toString())
updateDataValue('humidity', (Math.round(ds.currently.humidity.toBigDecimal() * 1000) / 10).toString())
BigDecimal t_press
if(pMetric == 'inHg') {
t_press = Math.round(ds.currently.pressure.toBigDecimal() * 0.029529983071445 * getDataValue('mult_p').toInteger()) / getDataValue('mult_p').toInteger()
} else {
t_press = Math.round(ds.currently.pressure.toBigDecimal() * getDataValue('mult_p').toInteger()) / getDataValue('mult_p').toInteger()
}
updateDataValue('pressure', t_press.toString())
BigDecimal t_temp
if(tMetric == '°F') {
t_temp = Math.round(ds.currently.temperature.toBigDecimal() * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()
} else {
t_temp = Math.round((ds.currently.temperature.toBigDecimal() - 32) / 1.8 * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()
}
updateDataValue('temperature', t_temp.toString())
String w_string_bft
String w_bft_icon
BigDecimal t_ws = ds.currently.windSpeed.toBigDecimal()
if(t_ws < 1.0) {
w_string_bft = 'Calm'; w_bft_icon = 'wb0.png'
}else if(t_ws < 4.0) {
w_string_bft = 'Light air'; w_bft_icon = 'wb1.png'
}else if(t_ws < 8.0) {
w_string_bft = 'Light breeze'; w_bft_icon = 'wb2.png'
}else if(t_ws < 13.0) {
w_string_bft = 'Gentle breeze'; w_bft_icon = 'wb3.png'
}else if(t_ws < 19.0) {
w_string_bft = 'Moderate breeze'; w_bft_icon = 'wb4.png'
}else if(t_ws < 25.0) {
w_string_bft = 'Fresh breeze'; w_bft_icon = 'wb5.png'
}else if(t_ws < 32.0) {
w_string_bft = 'Strong breeze'; w_bft_icon = 'wb6.png'
}else if(t_ws < 39.0) {
w_string_bft = 'High wind, moderate gale, near gale'; w_bft_icon = 'wb7.png'
}else if(t_ws < 47.0) {
w_string_bft = 'Gale, fresh gale'; w_bft_icon = 'wb8.png'
}else if(t_ws < 55.0) {
w_string_bft = 'Strong/severe gale'; w_bft_icon = 'wb9.png'
}else if(t_ws < 64.0) {
w_string_bft = 'Storm, whole gale'; w_bft_icon = 'wb10.png'
}else if(t_ws < 73.0) {
w_string_bft = 'Violent storm'; w_bft_icon = 'wb11.png'
}else if(t_ws >= 73.0) {
w_string_bft = 'Hurricane force'; w_bft_icon = 'wb12.png'
}
updateDataValue('wind_string_bft', w_string_bft)
updateDataValue('wind_bft_icon', w_bft_icon)
BigDecimal t_wd
BigDecimal t_wg
if(dMetric == 'MPH') {
t_wd = Math.round(ds.currently.windSpeed.toBigDecimal() * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()
t_wg = Math.round(ds.currently.windGust.toBigDecimal() * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()
} else if(dMetric == 'KPH') {
t_wd = Math.round(ds.currently.windSpeed.toBigDecimal() * 1.609344 * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()
t_wg = Math.round(ds.currently.windGust.toBigDecimal() * 1.609344 * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()
} else if(dMetric == 'knots') {
t_wd = Math.round(ds.currently.windSpeed.toBigDecimal() * 0.868976 * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()
t_wg = Math.round(ds.currently.windGust.toBigDecimal() * 0.868976 * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()
} else { // this leave only m/s
t_wd = Math.round(ds.currently.windSpeed.toBigDecimal() * 0.44704 * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()
t_wg = Math.round(ds.currently.windGust.toBigDecimal() * 0.44704 * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()
}
updateDataValue('wind', t_wd.toString())
updateDataValue('wind_gust', t_wg.toString())
updateDataValue('wind_degree', ds.currently.windBearing.toInteger().toString())
String w_cardinal
String w_direction
BigDecimal twb = ds.currently.windBearing.toBigDecimal()
if(twb < 11.25) {
w_cardinal = 'N'; w_direction = 'North'
}else if(twb < 33.75) {
w_cardinal = 'NNE'; w_direction = 'North-Northeast'
}else if(twb < 56.25) {
w_cardinal = 'NE'; w_direction = 'Northeast'
}else if(twb < 56.25) {
w_cardinal = 'ENE'; w_direction = 'East-Northeast'
}else if(twb < 101.25) {
w_cardinal = 'E'; w_direction = 'East'
}else if(twb < 123.75) {
w_cardinal = 'ESE'; w_direction = 'East-Southeast'
}else if(twb < 146.25) {
w_cardinal = 'SE'; w_direction = 'Southeast'
}else if(twb < 168.75) {
w_cardinal = 'SSE'; w_direction = 'South-Southeast'
}else if(twb < 191.25) {
w_cardinal = 'S'; w_direction = 'South'
}else if(twb < 213.75) {
w_cardinal = 'SSW'; w_direction = 'South-Southwest'
}else if(twb < 236.25) {
w_cardinal = 'SW'; w_direction = 'Southwest'
}else if(twb < 258.75) {
w_cardinal = 'WSW'; w_direction = 'West-Southwest'
}else if(twb < 281.25) {
w_cardinal = 'W'; w_direction = 'West'
}else if(twb < 303.75) {
w_cardinal = 'WNW'; w_direction = 'West-Northwest'
}else if(twb < 326.25) {
w_cardinal = 'NW'; w_direction = 'Northwest'
}else if(twb < 348.75) {
w_cardinal = 'NNW'; w_direction = 'North-Northwest'
}else if(twb >= 348.75) {
w_cardinal = 'N'; w_direction = 'North'
}
updateDataValue('wind_direction', w_direction)
updateDataValue('wind_cardinal', w_cardinal)
updateDataValue('wind_string', w_string_bft + ' from the ' + getDataValue('wind_direction') + (getDataValue('wind').toBigDecimal() < 1.0 ? '': ' at ' + String.format(ddisp_twd, getDataValue('wind').toBigDecimal()) + ' ' + dMetric))
String s_cardinal
String s_direction
if(!ds.currently.nearestStormBearing){
updateDataValue('nearestStormBearing', '360')
s_cardinal = 'U'
s_direction = 'Unknown'
}else{
updateDataValue('nearestStormBearing', (Math.round(ds.currently.nearestStormBearing * 100) / 100).toString())
BigDecimal tnsb = ds.currently.nearestStormBearing.toBigDecimal()
if(tnsb < 11.25) {
s_cardinal = 'N'; s_direction = 'North'
}else if(tnsb < 33.75) {
s_cardinal = 'NNE'; s_direction = 'North-Northeast'
}else if(tnsb < 56.25) {
s_cardinal = 'NE'; s_direction = 'Northeast'
}else if(tnsb < 78.75) {
s_cardinal = 'ENE'; s_direction = 'East-Northeast'
}else if(tnsb < 101.25) {
s_cardinal = 'E'; s_direction = 'East'
}else if(tnsb < 123.75) {
s_cardinal = 'ESE'; s_direction = 'East-Southeast'
}else if(tnsb < 146.25) {
s_cardinal = 'SE'; s_direction = 'Southeast'
}else if(tnsb < 168.75) {
s_cardinal = 'SSE'; s_direction = 'South-Southeast'
}else if(tnsb < 191.25) {
s_cardinal = 'S'; s_direction = 'South'
}else if(tnsb < 213.75) {
s_cardinal = 'SSW'; s_direction = 'South-Southwest'
}else if(tnsb < 236.25) {
s_cardinal = 'SW'; s_direction = 'Southwest'
}else if(tnsb < 258.75) {
s_cardinal = 'WSW'; s_direction = 'West-Southwest'
}else if(tnsb < 281.25) {
s_cardinal = 'W'; s_direction = 'West'
}else if(tnsb < 303.75) {
s_cardinal = 'WNW'; s_direction = 'West-Northwest'
}else if(tnsb < 326.26) {
s_cardinal = 'NW'; s_direction = 'Northwest'
}else if(tnsb < 348.75) {
s_cardinal = 'NNW'; s_direction = 'North-Northwest'
}else if(tnsb >= 348.75) {
s_cardinal = 'N'; s_direction = 'North'
}
}
updateDataValue('nearestStormCardinal', s_cardinal)
updateDataValue('nearestStormDirection', s_direction)
BigDecimal t_nsd
if(!ds.currently.nearestStormDistance) {
t_nsd = 9999.9
} else if(dMetric == 'MPH') {
t_nsd = Math.round(ds.currently.nearestStormDistance.toBigDecimal() * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()
} else {
t_nsd = Math.round(ds.currently.nearestStormDistance.toBigDecimal() * 1.609344 * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()
}
updateDataValue('nearestStormDistance', t_nsd.toString())
updateDataValue('ozone', (Math.round(ds.currently.ozone.toBigDecimal() * 10 ) / 10).toString())
String mPhase
BigDecimal tmnp = ds.daily.data[0].moonPhase.toBigDecimal() * 100
if (tmnp < 6.25) {mPhase = 'New Moon'}
else if (tmnp < 18.75) {mPhase = 'Waxing Crescent'}
else if (tmnp < 31.25) {mPhase = 'First Quarter'}
else if (tmnp < 43.75) {mPhase = 'Waxing Gibbous'}
else if (tmnp < 56.25) {mPhase = 'Full Moon'}
else if (tmnp < 68.75) {mPhase = 'Waning Gibbous'}
else if (tmnp < 81.25) {mPhase = 'Last Quarter'}
else if (tmnp < 93.75) {mPhase = 'Waxing Gibbous'}
else if (tmnp >= 93.75) {mPhase = 'New Moon'}
updateDataValue('moonPhase', mPhase)
// >>>>>>>>>> End Process Standard Weather-Station Variables (Regardless of Forecast Selection) <<<<<<<<<<
Integer cloudCover = 1
if (!ds.currently.cloudCover) {
cloudCover = 1
} else {
cloudCover = (ds.currently.cloudCover.toBigDecimal() <= 0.01) ? 1 : (ds.currently.cloudCover.toBigDecimal() * 100)
}
updateDataValue('cloud', cloudCover.toString())
updateDataValue('vis', (dMetric!='MPH' ? Math.round(ds.currently.visibility.toBigDecimal() * 1.60934 * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger() : Math.round(ds.currently.visibility.toBigDecimal() * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()).toString())
updateDataValue('percentPrecip', !ds.daily.data[0].precipProbability ? '1' : (ds.daily.data[0].precipProbability.toBigDecimal() * 100).toInteger().toString())
String c_code = getdsIconCode(ds.currently.icon, ds.currently.summary, getDataValue('is_day'))
updateDataValue('condition_code', c_code)
updateDataValue('condition_text', getcondText(c_code))
String f_code = getdsIconCode(ds.daily.data[0].icon, ds.daily.data[0].summary, getDataValue('is_day'))
updateDataValue('forecast_code', f_code)
updateDataValue('forecast_text', getcondText(f_code))
if (!ds.alerts){
updateDataValue('alert', 'No current weather alerts for this area')
updateDataValue('alertTileLink', '<a href="https://darksky.net/forecast/' + altLat + ',' + altLon + '" target="_blank">No current weather alerts for this area.</a>')
updateDataValue('alertLink', '<a>' + getDataValue('condition_text') + '</a>')
updateDataValue('alertLink2', '<a>' + getDataValue('condition_text') + '</a>')
updateDataValue('alertLink3', '<a>' + getDataValue('condition_text') + '</a>')
updateDataValue('possAlert', 'false')
} else {
updateDataValue('alertTileLink', '<a style="font-style:italic;color:red;" href="'+ds.alerts[0].uri+'" target="_blank">'+ds.alerts.title.toString().replaceAll('[{}\\[\\]]', '').split(/,/)[0]+'</a>')
updateDataValue('alertLink', '<a style="font-style:italic;color:red;" href="'+ds.alerts[0].uri+'" target="_blank">'+ds.alerts.title.toString().replaceAll('[{}\\[\\]]', '').split(/,/)[0]+'</a>')
def String al2 = '<a style="font-style:italic;color:red;" href="https://darksky.net/forecast/' + altLat + ',' + altLon + '" target="_blank">'
updateDataValue('alertLink2', al2+ds.alerts.title.toString().replaceAll('[{}\\[\\]]', '').split(/,/)[0]+'</a>')
updateDataValue('alertLink3', '<a style="font-style:italic;color:red;" target="_blank">'+ds.alerts.title.toString().replaceAll('[{}\\[\\]]', '').split(/,/)[0]+'</a>')
updateDataValue('alert', ds.alerts.title.toString().replaceAll('[{}\\[\\]]', '').split(/,/)[0])
updateDataValue('possAlert', 'true')
/* code to test weather alerts
href=''+'https://alerts.weather.gov/cap/wwacapget.php?x=NJ125F3B5DE240.WindAdvisory.125F3B5E5130NJ.PHINPWPHI.4c81e473f52888dec2cb0723d0145f0b'+''>'+'Wind Advisory'+'</a>')
updateDataValue('alertLink', '<a style='font-style:italic;color:red;' href=''+'https://alerts.weather.gov/cap/wwacapget.php?x=NJ125F3B5DE240.WindAdvisory.125F3B5E5130NJ.PHINPWPHI.4c81e473f52888dec2cb0723d0145f0b'+''>'+'Wind Advisory'+'</a>')
updateDataValue('alertLink2', '<a style='font-style:italic;color:red;' href='https://darksky.net/forecast/' + altLat + ',' + altLon + '' target=\'_blank\'>' + '12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'>'+'Wind Advisory'+'</a>')
updateDataValue('alertLink3', '<a style='font-style:italic;color:red;'>'+'Wind Advisory'+'</a>')
updateDataValue('alert', 'Wind Advisory')
updateDataValue('possAlert', 'true')
*/
}
if(threedayTilePublish) {
updateDataValue('day1', new Date(ds.daily.data[1].time * 1000L).format('EEEE'))
updateDataValue('day2', new Date(ds.daily.data[2].time * 1000L).format('EEEE'))
updateDataValue('is_day1', 'true')
updateDataValue('is_day2', 'true')
String f_code1 = getdsIconCode(ds.daily.data[1].icon, ds.daily.data[1].summary, getDataValue('is_day1'))
updateDataValue('forecast_code1', f_code1)
updateDataValue('forecast_text1', getcondText(f_code1))
String f_code2 = getdsIconCode(ds.daily.data[2].icon, ds.daily.data[2].summary, getDataValue('is_day2'))
updateDataValue('forecast_code2', f_code2)
updateDataValue('forecast_text2', getcondText(f_code2))
updateDataValue('forecastHigh1', (tMetric=='°F' ? (Math.round(ds.daily.data[1].temperatureMax.toBigDecimal() * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()) : (Math.round((ds.daily.data[1].temperatureMax.toBigDecimal() - 32) / 1.8 * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger())).toString())
updateDataValue('forecastHigh2', (tMetric=='°F' ? (Math.round(ds.daily.data[2].temperatureMax.toBigDecimal() * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()) : (Math.round((ds.daily.data[2].temperatureMax.toBigDecimal() - 32) / 1.8 * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger())).toString())
updateDataValue('forecastLow1', (tMetric=='°F' ? (Math.round(ds.daily.data[1].temperatureMin.toBigDecimal() * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()) : (Math.round((ds.daily.data[1].temperatureMin.toBigDecimal() - 32) / 1.8 * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger())).toString())
updateDataValue('forecastLow2', (tMetric=='°F' ? (Math.round(ds.daily.data[2].temperatureMin.toBigDecimal() * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()) : (Math.round((ds.daily.data[2].temperatureMin.toBigDecimal() - 32) / 1.8 * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger())).toString())
updateDataValue('imgName0', '<img class=\'centerImage\' src=' + getImgName(getDataValue('forecast_code')) + '>')
updateDataValue('imgName1', '<img class=\'centerImage\' src=' + getImgName(getDataValue('forecast_code1')) + '>')
updateDataValue('imgName2', '<img class=\'centerImage\' src=' + getImgName(getDataValue('forecast_code2')) + '>')
updateDataValue('PoP', (!ds.daily.data[0].precipProbability ? 0 : (ds.daily.data[0].precipProbability.toBigDecimal() * 100).toInteger()).toString())
updateDataValue('PoP1', (!ds.daily.data[1].precipProbability ? 0 : (ds.daily.data[1].precipProbability.toBigDecimal() * 100).toInteger()).toString())
updateDataValue('PoP2', (!ds.daily.data[2].precipProbability ? 0 : (ds.daily.data[2].precipProbability.toBigDecimal() * 100).toInteger()).toString())
}
updateDataValue('forecastHigh', (tMetric=='°F' ? (Math.round(ds.daily.data[0].temperatureMax.toBigDecimal() * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()) : (Math.round((ds.daily.data[0].temperatureMax.toBigDecimal() - 32) / 1.8 * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger())).toString())
updateDataValue('forecastLow', (tMetric=='°F' ? (Math.round(ds.daily.data[0].temperatureMin.toBigDecimal() * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()) : (Math.round((ds.daily.data[0].temperatureMin.toBigDecimal() - 32) / 1.8 * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger())).toString())
if(precipExtendedPublish){
updateDataValue('rainTomorrow', (ds.daily.data[1].precipProbability.toBigDecimal() * 100).toInteger().toString())
updateDataValue('rainDayAfterTomorrow', (ds.daily.data[2].precipProbability.toBigDecimal() * 100).toInteger().toString())
}
updateLux(false)
updateDataValue('ultravioletIndex', ds.currently.uvIndex.toBigDecimal().toString())
BigDecimal t_fl
if(tMetric == '°F') {
t_fl = Math.round(ds.currently.apparentTemperature.toBigDecimal() * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()
} else {
t_fl = Math.round((ds.currently.apparentTemperature.toBigDecimal() - 32) / 1.8 * getDataValue('mult_twd').toInteger()) / getDataValue('mult_twd').toInteger()
}
updateDataValue('feelsLike', t_fl.toString())
// >>>>>>>>>> End Setup Forecast Variables <<<<<<<<<<
// <<<<<<<<<< Begin Icon Processing >>>>>>>>>>
String imgName = (getDataValue('iconType')== 'true' ? getImgName(getDataValue('condition_code')) : getImgName(getDataValue('forecast_code')))
sendEventPublish(name: 'condition_icon', value: '<img src=' + imgName + '>')
sendEventPublish(name: 'condition_iconWithText', value: '<img src=' + imgName + '><br>' + (getDataValue('iconType')== 'true' ? getDataValue('condition_text') : getDataValue('forecast_text')))
sendEventPublish(name: 'condition_icon_url', value: imgName)
updateDataValue('condition_icon_url', imgName)
sendEventPublish(name: 'condition_icon_only', value: imgName.split('/')[-1].replaceFirst('\\?raw=true',''))
// >>>>>>>>>> End Icon Processing <<<<<<<<<<
PostPoll()
return
}
// >>>>>>>>>> End DarkSky Poll Routines <<<<<<<<<<
// >>>>>>>>>> Begin Lux Processing <<<<<<<<<<
void updateLux(Boolean pollAgain=true) {
LOGINFO('UpdateLux ' + pollAgain)
if(pollAgain) {
String curTime = new Date().format('HH:mm', TimeZone.getDefault())
String newLight
if(curTime < getDataValue('tw_begin') || curTime > getDataValue('tw_end')) {
newLight = 'false'
} else {
newLight = 'true'
}
if(newLight != getDataValue('is_lightOld')) {
pollDS()
return
}
}
def (lux, bwn) = estimateLux(getDataValue('condition_code'), getDataValue('cloud').toInteger())
updateDataValue('illuminance', !lux ? '0' : lux.toString())
updateDataValue('illuminated', String.format('%,4d', !lux ? 0 : lux).toString())
updateDataValue('bwn', bwn)
if(pollAgain) PostPoll()
return
}
// >>>>>>>>>> End Lux Processing <<<<<<<<<<
// <<<<<<<<<< Begin Icon and condition_code, condition_text processing >>>>>>>>>>
String getdsIconCode(String icon='unknown', String dcs='unknown', String isDay='true') {
switch(icon) {
case 'rain':
// rain=[Possible Light Rain, Light Rain, Rain, Heavy Rain, Drizzle, Light Rain and Breezy, Light Rain and Windy,
// Rain and Breezy, Rain and Windy, Heavy Rain and Breezy, Rain and Dangerously Windy, Light Rain and Dangerously Windy],
if (dcs == 'Drizzle') {
icon = 'drizzle'
} else if (dcs.startsWith('Light Rain')) {
icon = 'lightrain'
if (dcs.contains('Breezy')) icon += 'breezy'
else if (dcs.contains('Windy')) icon += 'windy'
} else if (dcs.startsWith('Heavy Rain')) {
icon = 'heavyrain'
if (dcs.contains('Breezy')) icon += 'breezy'
else if (dcs.contains('Windy')) icon += 'windy'
} else if (dcs == 'Possible Light Rain') {
icon = 'chancelightrain'
} else if (dcs.startsWith('Possible')) {
icon = 'chancerain'
} else if (dcs.startsWith('Rain')) {
if (dcs.contains('Breezy')) icon += 'breezy'
else if (dcs.contains('Windy')) icon += 'windy'
}
break;
case 'snow':
if (dcs == 'Light Snow') icon = 'lightsnow'
else if (dcs == 'Flurries') icon = 'flurries'
else if (dcs == 'Possible Light Snow') icon = 'chancelightsnow'
else if (dcs.startsWith('Possible Light Snow')) {
if (dcs.contains('Breezy')) icon = 'chancelightsnowbreezy'
else if (dcs.contains('Windy')) icon = 'chancelightsnowwindy'
} else if (dcs.startsWith('Possible')) icon = 'chancesnow'
break;
case 'sleet':
if (dcs.startsWith('Possible')) icon = 'chancesleet'
else if (dcs.startsWith('Light')) icon = 'lightsleet'
break;
case 'thunderstorm':
if (dcs.startsWith('Possible')) icon = 'chancetstorms'
break;
case 'partly-cloudy-night':
if (dcs.contains('Mostly Cloudy')) icon = 'mostlycloudy'
else icon = 'partlycloudy'
break;
case 'partly-cloudy-day':
if (dcs.contains('Mostly Cloudy')) icon = 'mostlycloudy'
else icon = 'partlycloudy'
break;
case 'cloudy-night':
icon = 'cloudy'
break;
case 'cloudy':
case 'cloudy-day':
icon = 'cloudy'
break;
case 'clear-night':
icon = 'clear'
break;
case 'clear':
case 'clear-day':
icon = 'clear'
break;
case 'fog':
case 'wind':
// wind=[Windy and Overcast, Windy and Mostly Cloudy, Windy and Partly Cloudy, Breezy and Mostly Cloudy, Breezy and Partly Cloudy,
// Breezy and Overcast, Breezy, Windy, Dangerously Windy and Overcast, Windy and Foggy, Dangerously Windy and Partly Cloudy, Breezy and Foggy]}
if (dcs.contains('Windy')) {
// icon = 'wind'
if (dcs.contains('Overcast')) icon = 'windovercast'
else if (dcs.contains('Mostly Cloudy')) icon = 'windmostlycloudy'
else if (dcs.contains('Partly Cloudy')) icon = 'windpartlycloudy'
else if (dcs.contains('Foggy')) icon = 'windfoggy'
} else if (dcs.contains('Breezy')) {
icon = 'breezy'
if (dcs.contains('Overcast')) icon = 'breezyovercast'
else if (dcs.summary.contains('Mostly Cloudy')) icon = 'breezymostlycloudy'
else if (dcs.contains('Partly Cloudy')) icon = 'breezypartlycloudy'
else if (dcs.contains('Foggy')) icon = 'breezyfoggy'
}
break;
case '':
icon = 'unknown'
break;
default:
icon = 'unknown'
}
if(isDay == 'false') icon = 'nt_' + icon
return icon
}
// >>>>>>>>>> End Icon and condition_code, condition_text processing <<<<<<<<<<
// <<<<<<<<<< Begin Post-Poll Routines >>>>>>>>>>
void PostPoll() {
def sunRiseSet = parseJson(getDataValue('sunRiseSet')).results
setDateTimeFormats(datetimeFormat)
setMeasurementMetrics(distanceFormat, pressureFormat, rainFormat, tempFormat)
setDisplayDecimals(TWDDecimals, PDecimals)
/* SunriseSunset Data Eements */
if(localSunrisePublish){ // don't bother setting these values if it's not enabled
sendEvent(name: 'tw_begin', value: new Date().parse('yyyy-MM-dd\'T\'HH:mm:ssXXX', sunRiseSet.civil_twilight_begin).format(timeFormat, TimeZone.getDefault()))
sendEvent(name: 'sunriseTime', value: new Date().parse('yyyy-MM-dd\'T\'HH:mm:ssXXX', sunRiseSet.sunrise).format(timeFormat, TimeZone.getDefault()))
sendEvent(name: 'noonTime', value: new Date().parse('yyyy-MM-dd\'T\'HH:mm:ssXXX', sunRiseSet.solar_noon).format(timeFormat, TimeZone.getDefault()))
sendEvent(name: 'sunsetTime', value: new Date().parse('yyyy-MM-dd\'T\'HH:mm:ssXXX', sunRiseSet.sunset).format(timeFormat, TimeZone.getDefault()))
sendEvent(name: 'tw_end', value: new Date().parse('yyyy-MM-dd\'T\'HH:mm:ssXXX', sunRiseSet.civil_twilight_end).format(timeFormat, TimeZone.getDefault()))
}
if(dashSharpToolsPublish || dashSmartTilesPublish || localSunrisePublish) {
sendEvent(name: 'localSunset', value: new Date().parse('yyyy-MM-dd\'T\'HH:mm:ssXXX', sunRiseSet.sunset).format(timeFormat, TimeZone.getDefault())) // only needed for certain dashboards
sendEvent(name: 'localSunrise', value: new Date().parse('yyyy-MM-dd\'T\'HH:mm:ssXXX', sunRiseSet.sunrise).format(timeFormat, TimeZone.getDefault())) // only needed for certain dashboards
}
/* Weather-Display Data Elements */
sendEvent(name: 'humidity', value: getDataValue('humidity').toBigDecimal(), unit: '%')
sendEvent(name: 'illuminance', value: getDataValue('illuminance').toInteger(), unit: 'lx')
sendEvent(name: 'pressure', value: getDataValue('pressure').toBigDecimal(), unit: pMetric)
sendEvent(name: 'pressured', value: String.format(ddisp_p, getDataValue('pressure').toBigDecimal()), unit: pMetric)
sendEvent(name: 'temperature', value: getDataValue('temperature').toBigDecimal(), unit: tMetric)
sendEvent(name: 'ultravioletIndex', value: getDataValue('ultravioletIndex').toBigDecimal(), unit: 'uvi')
sendEvent(name: 'feelsLike', value: getDataValue('feelsLike').toBigDecimal(), unit: tMetric)
/* 'Required for Dashboards' Data Elements */
if(dashHubitatOWMPublish || dashSharpToolsPublish || dashSmartTilesPublish) { sendEvent(name: 'city', value: getDataValue('city')) }
if(dashSharpToolsPublish) { sendEvent(name: 'forecastIcon', value: getstdImgName(getDataValue('condition_code'))) }
if(dashSharpToolsPublish || dashSmartTilesPublish || percentPrecipPublish) { sendEvent(name: 'percentPrecip', value: getDataValue('percentPrecip').toBigDecimal()) }
if(dashSharpToolsPublish || dashSmartTilesPublish) { sendEvent(name: 'weather', value: getDataValue('condition_text')) }
if(dashSharpToolsPublish || dashSmartTilesPublish) { sendEvent(name: 'weatherIcon', value: getstdImgName(getDataValue('condition_code'))) }
if(dashHubitatOWMPublish) { sendEvent(name: 'weatherIcons', value: getowmImgName(getDataValue('condition_code'))) }
if(dashHubitatOWMPublish || dashSharpToolsPublish || windPublish) { sendEvent(name: 'wind', value: getDataValue('wind').toBigDecimal(), unit: dMetric) }
if(dashHubitatOWMPublish) { sendEvent(name: 'windSpeed', value: getDataValue('wind').toBigDecimal(), unit: dMetric) }
if(dashHubitatOWMPublish) { sendEvent(name: 'windDirection', value: getDataValue('wind_degree').toInteger(), unit: 'DEGREE') }
/* Selected optional Data Elements */
sendEventPublish(name: 'betwixt', value: getDataValue('bwn'))
sendEventPublish(name: 'cloud', value: getDataValue('cloud').toInteger(), unit: '%')
sendEventPublish(name: 'condition_code', value: getDataValue('condition_code'))
sendEventPublish(name: 'condition_text', value: getDataValue('condition_text'))
sendEventPublish(name: 'dewpoint', value: getDataValue('dewpoint').toBigDecimal(), unit: tMetric)
if(dsAttributionPublish){
sendEvent(name: 'dsIconlighttext', value: '<a href="https://darksky.net/poweredby/" target="_blank"><img src=' + getDataValue('iconLocation') + 'dsL.png' + ' style="height:2em";></a>')
sendEvent(name: 'dsIcondarktext', value: '<a href="https://darksky.net/poweredby/" target="_blank"><img src=' + getDataValue('iconLocation') + 'dsD.png' + ' style="height:2em";></a>')
}
sendEventPublish(name: 'forecast_code', value: getDataValue('forecast_code'))
sendEventPublish(name: 'forecast_text', value: getDataValue('forecast_text'))
if(fcstHighLowPublish){ // don't bother setting these values if it's not enabled
sendEvent(name: 'forecastHigh', value: getDataValue('forecastHigh').toBigDecimal(), unit: tMetric)
sendEvent(name: 'forecastLow', value: getDataValue('forecastLow').toBigDecimal(), unit: tMetric)
}
sendEventPublish(name: 'illuminated', value: getDataValue('illuminated') + ' lx')
sendEventPublish(name: 'is_day', value: getDataValue('is_day'))
sendEventPublish(name: 'moonPhase', value: getDataValue('moonPhase'))
if(obspollPublish){ // don't bother setting these values if it's not enabled
sendEvent(name: 'last_poll_Forecast', value: new Date().parse('EEE MMM dd HH:mm:ss z yyyy', getDataValue('futime')).format(dateFormat, TimeZone.getDefault()) + ', ' + new Date().parse('EEE MMM dd HH:mm:ss z yyyy', getDataValue('futime')).format(timeFormat, TimeZone.getDefault()))
sendEvent(name: 'last_observation_Forecast', value: new Date().parse('EEE MMM dd HH:mm:ss z yyyy', getDataValue('fotime')).format(dateFormat, TimeZone.getDefault()) + ', ' + new Date().parse('EEE MMM dd HH:mm:ss z yyyy', getDataValue('fotime')).format(timeFormat, TimeZone.getDefault()))
}
sendEventPublish(name: 'ozone', value: Math.round(getDataValue('ozone').toBigDecimal() * 10) / 10)
if(precipExtendedPublish){ // don't bother setting these values if it's not enabled
sendEvent(name: 'rainDayAfterTomorrow', value: getDataValue('rainDayAfterTomorrow').toBigDecimal(), unit: '%')
sendEvent(name: 'rainTomorrow', value: getDataValue('rainTomorrow').toBigDecimal(), unit: '%')
}
sendEventPublish(name: 'vis', value: Math.round(getDataValue('vis').toBigDecimal() * getDataValue('mult_twd').toBigDecimal()) / getDataValue('mult_twd').toBigDecimal(), unit: (dMetric=='MPH' ? 'miles' : 'kilometers'))
sendEventPublish(name: 'wind_degree', value: getDataValue('wind_degree').toInteger(), unit: 'DEGREE')
sendEventPublish(name: 'wind_direction', value: getDataValue('wind_direction'))
sendEventPublish(name: 'wind_cardinal', value: getDataValue('wind_cardinal'))
sendEventPublish(name: 'wind_gust', value: getDataValue('wind_gust').toBigDecimal(), unit: dMetric)
sendEventPublish(name: 'wind_string', value: getDataValue('wind_string'))
if(nearestStormPublish) {
sendEvent(name: 'nearestStormBearing', value: getDataValue('nearestStormBearing'), unit: 'DEGREE')
sendEvent(name: 'nearestStormCardinal', value: getDataValue('nearestStormCardinal'))
sendEvent(name: 'nearestStormDirection', value: getDataValue('nearestStormDirection'))
sendEvent(name: 'nearestStormDistance', value: getDataValue('nearestStormDistance').toBigDecimal(), unit: (dMetric=='MPH' ? 'miles' : 'kilometers'))
}
// <<<<<<<<<< Begin Built Weather Summary text >>>>>>>>>>
String Summary_last_poll_time = new Date().parse('EEE MMM dd HH:mm:ss z yyyy', getDataValue('futime')).format(timeFormat, TimeZone.getDefault())
String Summary_last_poll_date = new Date().parse('EEE MMM dd HH:mm:ss z yyyy', getDataValue('futime')).format(dateFormat, TimeZone.getDefault())
String mtprecip = getDataValue('percentPrecip') + '%'
if(weatherSummaryPublish){ // don't bother setting these values if it's not enabled
String Summary_forecastTemp = ' with a high of ' + String.format(ddisp_twd, getDataValue('forecastHigh').toBigDecimal()) + tMetric + ' and a low of ' + String.format(ddisp_twd, getDataValue('forecastLow').toBigDecimal()) + tMetric + '. '
String Summary_precip = 'There is a ' + getDataValue('percentPrecip') + '% chance of precipitation. '
String Summary_vis = 'Visibility is around ' + String.format(ddisp_twd, getDataValue('vis').toBigDecimal()) + (dMetric=='MPH' ? ' miles.' : ' kilometers.')
SummaryMessage(summaryType, Summary_last_poll_date, Summary_last_poll_time, Summary_forecastTemp, Summary_precip, Summary_vis)
}
// >>>>>>>>>> End Built Weather Summary text <<<<<<<<<<
String dsIcon = '<a href="https://darksky.net/poweredby/" target="_blank"><img src=' + getDataValue('iconLocation') + (dsIconbackgrounddark ? 'dsD.png' : 'dsL.png') + ' style="height:2em";></a>'
String dsText = '<a href="https://darksky.net/poweredby/" target="_blank">Powered by Dark Sky</a>'
// <<<<<<<<<< Begin Built 3dayfcstTile >>>>>>>>>>
if(threedayTilePublish) {
String my3day = '<style type=\'text/css\'>'
my3day += '.centerImage'
my3day += '{text-align:center;display:inline;height:50%;}'
my3day += '</style>'
my3day += '<table align="center" style="width:100%">'
my3day += '<tr>'
my3day += '<td></td>'
my3day += '<td><a href="https://darksky.net/forecast/' + altLat + ',' + altLon + '" target="_blank">Today</a></td>'
my3day += '<td>' + getDataValue('day1') + '</td>'
my3day += '<td>' + getDataValue('day2') + '</td>'
my3day += '</tr>'
my3day += '<tr>'
my3day += '<td></td>'
my3day += '<td>' + getDataValue('imgName0') + '</td>'
my3day += '<td>' + getDataValue('imgName1') + '</td>'
my3day += '<td>' + getDataValue('imgName2') + '</td>'
my3day += '</tr>'
my3day += '<tr>'
my3day += '<td style="text-align:right">Now:</td>'
my3day += '<td>' + String.format(ddisp_twd, getDataValue('temperature').toBigDecimal()) + tMetric + '</td>'
my3day += '<td>' + getDataValue('forecast_text1') + '</td>'
my3day += '<td>' + getDataValue('forecast_text2') + '</td>'
my3day += '</tr>'
my3day += '<tr>'
my3day += '<td style="text-align:right">Low:</td>'
my3day += '<td>' + String.format(ddisp_twd, getDataValue('forecastLow').toBigDecimal()) + tMetric + '</td>'
my3day += '<td>' + String.format(ddisp_twd, getDataValue('forecastLow1').toBigDecimal()) + tMetric + '</td>'
my3day += '<td>' + String.format(ddisp_twd, getDataValue('forecastLow2').toBigDecimal()) + tMetric + '</td>'
my3day += '</tr>'
my3day += '<tr>'
my3day += '<td style="text-align:right">High:</td>'
my3day += '<td>' + String.format(ddisp_twd, getDataValue('forecastHigh').toBigDecimal()) + tMetric + '</td>'
my3day += '<td>' + String.format(ddisp_twd, getDataValue('forecastHigh1').toBigDecimal()) + tMetric + '</td>'
my3day += '<td>' + String.format(ddisp_twd, getDataValue('forecastHigh2').toBigDecimal()) + tMetric + '</td>'
my3day += '</tr>'
my3day += '<tr>'
my3day += '<td style="text-align:right">PoP:</td>'
my3day += '<td>' + getDataValue('PoP') + '%</td>'
my3day += '<td>' + getDataValue('PoP1') + '%</td>'
my3day += '<td>' + getDataValue('PoP2') + '%</td>'
my3day += '</tr>'
my3day += '</table>'
if(my3day.length() + 11 > 1024) {
my3day = 'Too much data to display.</br></br>Exceeds maximum tile length by ' + 1024 - my3day.length() - 11 + ' characters.'
}else if((my3day.length() + dsIcon.length() + 11) < 1025) {
my3day += dsIcon + ' @ ' + Summary_last_poll_time
}else if((my3day.length() + dsText.length() + 11) < 1025) {
my3day += dsText + ' @ ' + Summary_last_poll_time
}else{
my3day += 'Powered by Dark Sky'
}
sendEvent(name: 'threedayfcstTile', value: my3day.take(1024))
}
// >>>>>>>>>> End Built 3dayfcstTile <<<<<<<<<<
// <<<<<<<<<< Begin Built alertTile >>>>>>>>>>
if(alertPublish){ // don't bother setting these values if it's not enabled
String alertTile = 'Weather Alerts for <a href="https://darksky.net/forecast/' + altLat + ',' + altLon + '" target="_blank">' + getDataValue('city') + '</a><br>updated at ' + Summary_last_poll_time + ' on ' + Summary_last_poll_date + '.<br>'
alertTile+= getDataValue('alertTileLink') + '<br>'
alertTile+= dsIcon
updateDataValue('alertTile', alertTile)
sendEvent(name: 'alert', value: getDataValue('alert'))
sendEvent(name: 'alertTile', value: getDataValue('alertTile'))
}
// >>>>>>>>>> End Built alertTile <<<<<<<<<<
// <<<<<<<<<< Begin Built mytext >>>>>>>>>>
if(myTilePublish){ // don't bother setting these values if it's not enabled
Boolean gitclose = (getDataValue('iconLocation').toLowerCase().contains('://github.com/')) && (getDataValue('iconLocation').toLowerCase().contains('/blob/master/'))
String iconClose = (gitclose ? '?raw=true' : '')
String iconCloseStyled = iconClose + '>'
Boolean noAlert = (!getDataValue('possAlert') || getDataValue('possAlert')=='' || getDataValue('possAlert')=='false')
String alertStyleOpen = (noAlert ? '' : '<span>')
String alertStyleClose = (noAlert ? '<br>' : '</span><br>')
BigDecimal wgust
if(getDataValue('wind_gust').toBigDecimal() < 1.0 ) {
wgust = 0.0g
} else {
wgust = getDataValue('wind_gust').toBigDecimal()
}
String mytextb = '<span style="display:inline;"><a href="https://darksky.net/forecast/' + altLat + ',' + altLon + '" target="_blank">' + getDataValue('city') + '</a><br>'
String mytextm1 = getDataValue('condition_text') + (noAlert ? '' : ' | ') + alertStyleOpen + (noAlert ? '' : getDataValue('alertLink')) + alertStyleClose
String mytextm2 = getDataValue('condition_text') + (noAlert ? '' : ' | ') + alertStyleOpen + (noAlert ? '' : getDataValue('alertLink2')) + alertStyleClose
String mytextm3 = getDataValue('condition_text') + (noAlert ? '' : ' | ') + alertStyleOpen + (noAlert ? '' : getDataValue('alertLink3')) + alertStyleClose
String mytexte = String.format(ddisp_twd, getDataValue('temperature').toBigDecimal()) + tMetric + '<img src=' + getDataValue('condition_icon_url') + iconClose + ' style="height:2.2em;display:inline;">'
mytexte+= ' Feels like ' + String.format(ddisp_twd, getDataValue('feelsLike').toBigDecimal()) + tMetric + '<br></span>'
mytexte+= '<span style="font-size:.9em;"><img src=' + getDataValue('iconLocation') + getDataValue('wind_bft_icon') + iconCloseStyled + getDataValue('wind_direction') + ' '
mytexte+= (getDataValue('wind').toBigDecimal() < 1.0 ? 'calm' : '@ ' + String.format(ddisp_twd, getDataValue('wind').toBigDecimal()) + ' ' + dMetric)
mytexte+= ', gusts ' + ((wgust < 1.0) ? 'calm' : '@ ' + String.format(ddisp_twd, wgust) + ' ' + dMetric) + '<br>'
mytexte+= '<img src=' + getDataValue('iconLocation') + 'wb.png' + iconCloseStyled + String.format(ddisp_p, getDataValue('pressure').toBigDecimal()) + ' ' + pMetric + ' <img src=' + getDataValue('iconLocation') + 'wh.png' + iconCloseStyled
mytexte+= getDataValue('humidity') + '% ' + '<img src=' + getDataValue('iconLocation') + 'wu.png' + iconCloseStyled + getDataValue('percentPrecip') + '%<br>'
mytexte+= '<img src=' + getDataValue('iconLocation') + 'wsr.png' + iconCloseStyled + getDataValue('localSunrise') + ' <img src=' + getDataValue('iconLocation') + 'wss.png' + iconCloseStyled
mytexte+= getDataValue('localSunset') + ' Updated: ' + Summary_last_poll_time
String mytext = mytextb + mytextm1 + mytexte
if((mytext.length() + dsIcon.length() + 10) < 1025) {
mytext+= '<br>' + dsIcon + '</span>'
}else{
if((mytext.length() + dsText.length() + 10) < 1025) {
mytext+= '<br>' + dsText + '</span>'
}else{
mytext = mytextb + mytextm2 + mytexte
if((mytext.length() + dsIcon.length() + 10) < 1025) {
mytext+= '<br>' + dsIcon + '</span>'
}else if((mytext.length() + dsText.length() + 10) < 1025) {
mytext+= '<br>' + dsText + '</span>'
}else{
mytext+= '<br>Powered by Dark Sky</span>'
}
}
}
if(mytext.length() > 1024) {
Integer iconfilepath = ('<img src=' + getDataValue('iconLocation') + getDataValue('wind_bft_icon') + iconCloseStyled).length()
Integer excess = (mytext.length() - 1024)
Integer removeicons = 0
Integer ics = iconfilepath + iconCloseStyled.length()
if((excess - ics + 11) < 0) {
removeicons = 1 //Remove sunset
}else if((excess - (ics * 2) + 20) < 0) {
removeicons = 2 //remove sunset and sunrise
}else if((excess - (ics * 3) + 31) < 0) {
removeicons = 3 //remove sunset, sunrise, PercentPrecip
}else if((excess - (ics * 4) + 38) < 0) {
removeicons = 4 //remove sunset, sunrise, PercentPrecip, Humidity
}else if((excess - (ics * 5) + 42) < 0) {
removeicons = 5 //remove sunset, sunrise, PercentPrecip, Humidity, Pressure
}else if((excess - (ics * 6) + 42) < 0) {
removeicons = 6 //remove sunset, sunrise, PercentPrecip, Humidity, Pressure, Wind
}else if((excess - (ics * 7) + 42) < 0) {
removeicons = 7 //remove sunset, sunrise, PercentPrecip, Humidity, Pressure, Wind, condition
}else{
removeicons = 8 // still need to remove html formatting
}
if(removeicons < 8) {
LOGDEBUG('myTile exceeds 1,024 characters (' + mytext.length() + ') ... removing last ' + (removeicons + 1).toString() + ' icons.')
mytext = '<span>' + getDataValue('city') + '<br>'
mytext+= getDataValue('condition_text') + (noAlert ? '' : ' | ') + alertStyleOpen + (noAlert ? '' : getDataValue('alert')) + alertStyleClose + '<br>'
mytext+= String.format(ddisp_twd, getDataValue('temperature').toBigDecimal()) + tMetric + (removeicons < 7 ? '<img src=' + getDataValue('condition_icon_url') + iconClose + ' style=\'height:2.0em;display:inline;\'>' : '')
mytext+= ' Feels like ' + String.format(ddisp_twd, getDataValue('feelsLike').toBigDecimal()) + tMetric + '<br></span>'
mytext+= '<span style=\'font-size:.8em;\'>' + (removeicons < (raintoday ? 7 : 6) ? '<img src=' + getDataValue('iconLocation') + getDataValue('wind_bft_icon') + iconCloseStyled : '') + getDataValue('wind_direction') + ' '
mytext+= (removeicons < 6 ? '<img src=' + getDataValue('iconLocation') + getDataValue('wind_bft_icon') + iconCloseStyled : '') + getDataValue('wind_direction') + ' '
mytext+= (getDataValue('wind').toBigDecimal() < 1.0 ? 'calm' : '@ ' + String.format(ddisp_twd, getDataValue('wind').toBigDecimal()) + ' ' + dMetric)
mytext+= ', gusts ' + ((wgust < 1.0) ? 'calm' : '@ ' + String.format(ddisp_twd, wgust) + ' ' + dMetric) + '<br>'
mytext+= (removeicons < 5 ? '<img src=' + getDataValue('iconLocation') + 'wb.png' + iconCloseStyled : 'Bar: ') + String.format(ddisp_p, getDataValue('pressure').toBigDecimal()) + ' ' + pMetric + ' '
mytext+= (removeicons < 4 ? '<img src=' + getDataValue('iconLocation') + 'wh.png' + iconCloseStyled : ' | Hum: ') + getDataValue('humidity') + '% '
mytext+= (removeicons < 3 ? '<img src=' + getDataValue('iconLocation') + 'wu.png' + iconCloseStyled : ' | Precip%: ') + getDataValue('percentPrecip') + '%<br>'
mytext+= (removeicons < 2 ? '<img src=' + getDataValue('iconLocation') + 'wsr.png' + iconCloseStyled : 'Sunrise: ') + getDataValue('localSunrise') + ' '
mytext+= (removeicons < 1 ? '<img src=' + getDataValue('iconLocation') + 'wss.png' + iconCloseStyled : ' | Sunset: ') + getDataValue('localSunset')
mytext+= ' Updated ' + Summary_last_poll_time + '</span>'
}else{
LOGINFO('myTile still exceeds 1,024 characters (' + mytext.length() + ') ... removing all formatting.')
mytext = getDataValue('city') + '<br>'
mytext+= getDataValue('condition_text') + (noAlert ? '' : ' | ') + (noAlert ? '' : getDataValue('alert')) + '<br>'
mytext+= String.format(ddisp_twd, getDataValue('temperature').toBigDecimal()) + tMetric + ' Feels like ' + String.format(ddisp_twd, getDataValue('feelsLike').toBigDecimal()) + tMetric + '<br>'
mytext+= getDataValue('wind_direction') + ' '
mytext+= getDataValue('wind').toBigDecimal() < 1.0 ? 'calm' : '@ ' + String.format(ddisp_twd, getDataValue('wind').toBigDecimal()) + ' ' + dMetric
mytext+= ', gusts ' + ((wgust < 1.0) ? 'calm' : '@ ' + String.format(ddisp_twd, wgust) + ' ' + dMetric) + '<br>'
mytext+= 'Bar: ' + String.format(ddisp_p, getDataValue('pressure').toBigDecimal()) + ' ' + pMetric
mytext+= ' | Hum: ' + getDataValue('humidity') + '% ' + ' | Precip%: ' + getDataValue('percentPrecip') + '%<br>'
mytext+= 'Sunrise: ' + getDataValue('localSunrise') + ' | Sunset:' + getDataValue('localSunset') + ' | Updated:' + Summary_last_poll_time
if(mytext.length() > 1024) {
LOGINFO('myTile even still exceeds 1,024 characters (' + mytext.length() + ') ... truncating.')
}
}
}
LOGINFO('mytext: ' + mytext)
sendEvent(name: 'myTile', value: mytext.take(1024))
}
// >>>>>>>>>> End Built mytext <<<<<<<<<<
}
// >>>>>>>>>> End Post-Poll Routines <<<<<<<<<<