Code by Scott שאול בן ישוע
weeWX-driver.groovy 66.5 KB
Newer Older
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
/**
 * Please Note: This app is NOT released under any open-source license.
 * Please be sure to read the license agreement before installing this code.
 *
 *  Weewx Weather Driver for Hubitat Elevation
 *
 *  Copyright © 2019 AScott Grayban
 *  Original code from Andrew Parker
 *
 * This software package is created and licensed by Scott Grayban.
 *
 * This software, along with associated elements, including but not limited to online and/or electronic documentation are
 * protected by international laws and treaties governing intellectual property rights.
 *
 * This software has been licensed to you. All rights are reserved. You may use and/or modify the software.
 * You may not sublicense or distribute this software or any modifications to third parties in any way.
 *
 * You may not distribute any part of this software without the author's express permission
 *
 * By downloading, installing, and/or executing this software you hereby agree to the terms and conditions set forth in the Software license agreement.
 * This agreement can be found on-line at: https://sgrayban.github.io/Hubitat-Public/software_License_Agreement.txt
 * 
 * Hubitat is the trademark and intellectual property of Hubitat Inc. 
 * Scott Grayban has no formal or informal affiliations or relationships with Hubitat.
 *
 * 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 Agreement
 * for the specific language governing permissions and limitations under the License.
 *
 *-------------------------------------------------------------------------------------------------------------------
 *
 *  This driver is specifically designed to be used with 'Weewx' and your own PWS and
 *  requires you to install my Weewx Skin at https://github.com/sgrayban/hubitat-weewx-driver/
 *
Sha'ul ben Yeshua's avatar
Sha'ul ben Yeshua committed
35
36
37
 *  Version:
 *  1.0.0 - Initial commit
 *
38
39
40
 */

metadata {
Sha'ul ben Yeshua's avatar
Sha'ul ben Yeshua committed
41
42
43
44
45
46
47
48
    definition (
	name: "Weewx Weather Driver",
	namespace: "sgrayban",
	author: "Scott Grayban",
	importUrl: "https://raw.githubusercontent.com/sgrayban/hubitat-weewx-driver/master/Driver/weeWX-driver.groovy"
	)

	{
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
        capability "Actuator"
        capability "Sensor"
        capability "Temperature Measurement"
        capability "Illuminance Measurement"
        capability "Relative Humidity Measurement"
        capability "Polling"
        command "PollStation"
        command "poll"
        
// Base Info   
        attribute "Missing or No Data", "string"
        attribute "WeewxUptime", "string"
        attribute "WeewxLocation", "string"
        attribute "Refresh-Weewx", "string"
		attribute "WeatherDisplay", "string"
        
// Units
        attribute "distanceUnit", "string"
        attribute "pressureUnit", "string"
        attribute "rainUnit", "string"
        
// Collected Local Station Data       
        attribute "solarradiation", "string"
        attribute "dewpoint", "string"
        attribute "inside_humidity", "string"
        attribute "inside_temperature", "string"
        attribute "pressure", "string"
        attribute "pressure_trend", "string"
        attribute "wind", "string"
        attribute "wind_gust", "string"
        attribute "maxwindGust", "string"
        attribute "wind_dir", "string"
        attribute "rain_rate", "string"
        attribute "uv", "string"
        attribute "uvHarm", "string"
        attribute "feelsLike", "string"
        attribute "LastUpdate-Weewx", "string"
        attribute "precip_1hr", "string"
        attribute "precip_today", "string"
        attribute "localSunrise", "string"
        attribute "localSunset", "string"
        attribute "tempMaxToday", "string"
        attribute "tempMinToday", "string"
        attribute "tempMaxInsideToday", "string"
        attribute "tempMinInsideToday", "string"
    }

    preferences() {
    
        section("Query Inputs"){
            input "ipaddress", "text", required: true, title: "weeWX Server IP/URI", defaultValue: "0.0.0.0"
            input "weewxPort", "text", required: true, title: "Connection Port", defaultValue: "800"
            input "weewxPath", "text", required: true, title: "path to file", defaultValue: "weewx/daily.json"
            input "unitSet", "bool", title: "Display Data Units", required: true, defaultValue: false
            input "logSet", "bool", title: "Log All Data", required: true, defaultValue: false
            input "pollInterval", "enum", title: "weeWX Station Poll Interval", required: true, defaultValue: "5 Minutes", options: ["Manual Poll Only", "5 Minutes", "10 Minutes", "15 Minutes", "30 Minutes", "1 Hour", "3 Hours"]
            input "pressureUnit", "enum", title: "Pressure Unit", required:true, defaultValue: "INHg", options: ["INHg", "MBAR"]
            input "rainUnit", "enum", title: "Rain Unit", required:true, defaultValue: "IN", options: ["IN", "MM"]
            input "speedUnit", "enum", title: "Distance & Speed Unit", required:true, defaultValue: "Miles (MPH)", options: ["Miles (MPH)", "Kilometers (KPH)"]
            input "temperatureUnit", "enum", title: "Temperature Unit", required:true, defaultValue: "Fahrenheit (�F)", options: ["Fahrenheit (�F)", "Celsius (�C)"]
            input "decimalUnit", "enum", title: "Max Decimal Places", required:true, defaultValue: "2", options: ["1", "2", "3", "4", "5"]
        }
	
		section(){
		input "summaryDashboard", "bool", title: "Weather Dashboard Summary", required: true, defaultValue: false, submitOnChange: true
			if(summaryDashboard == true){
			input "fweight", "enum",  title: "Font Weight", submitOnChange: true, defaultValue: "Normal", options: ["Normal", "Italic", "Bold"]
			input "fcolour", "text",  title: "Font Colour (Hex Value)", defaultValue:"000000", submitOnChange: true
	//		input "fsize", "enum",  title: "Font Size", submitOnChange: true, defaultValue: "Normal", options: fontSize()
			
		input "dashboardFormat", "bool", title: "Custom Weather Dashboard Summary", required: true, defaultValue: false, submitOnChange: true		
			if(dashboardFormat == true){
			input "slot1", "enum",  title: "Attribute For Line 1", options: checkInput(), submitOnChange: true		
					if(slot1 == "Free Text"){ 
					input "slot1Text1", "text",  title: "Text For Line 1", submitOnChange: true	
					}	
			input "slot2", "enum",  title: "Attribute For Line 2", options: checkInput()
					if(slot2 == "Free Text"){ 
					input "slot2Text1", "text",  title: "Text For Line 2", submitOnChange: true	
					}	
			input "slot3", "enum",  title: "Attribute For Line 3", options: checkInput()
					if(slot3 == "Free Text"){ 
					input "slot3Text1", "text",  title: "Text For Line 3", submitOnChange: true	
					}	
			input "slot4", "enum",  title: "Attribute For Line 4", options: checkInput()
					if(slot4 == "Free Text"){ 
					input "slot4Text1", "text",  title: "Text For Line 4", submitOnChange: true	
					}	
			input "slot5", "enum",  title: "Attribute For Line 5", options: checkInput()
					if(slot5 == "Free Text"){ 
					input "slot5Text1", "text",  title: "Text For Line 5", submitOnChange: true	
					}	
			input "slot6", "enum",  title: "Attribute For Line 6", options: checkInput()
					if(slot6 == "Free Text"){ 
					input "slot6Text1", "text",  title: "Text For Line 6", submitOnChange: true	
					}
			input "slot7", "enum",  title: "Attribute For Line 7", options: checkInput()
					if(slot7 == "Free Text"){ 
					input "slot7Text1", "text",  title: "Text For Line 7", submitOnChange: true	
					}	
			input "slot8", "enum",  title: "Attribute For Line 8", options: checkInput()
					if(slot8 == "Free Text"){ 
					input "slot8Text1", "text",  title: "Text For Line 8", submitOnChange: true	
					}			
				}
			}
		}
    }
}

def initialize(){
    updated()
}

private dbCleanUp() {
	unschedule()
	state.remove("Missing or No Data")
//	state.remove("icon")
//	state.remove("Copyright")
//	state.remove("author")
//	state.remove("InternalName")
//	state.remove("newUpdateDate")
//	state.remove("Status")
//	state.remove("UpdateInfo")
//	state.remove("CobraAppCheck")
}

def updated() {
    dbCleanUp()
    sendEvent(name: "Missing or No Data", value: "---")
    log.debug "Updated called"
    logCheck()
    units()
    PollStation()
    def pollIntervalCmd = (settings?.pollInterval ?: "3 Hours").replace(" ", "")
    if(pollInterval == "Manual Poll Only"){LOGINFO( "MANUAL POLLING ONLY")}
    else{ "runEvery${pollIntervalCmd}"(pollSchedule)}
}

def poll(){
    log.info "Manual Poll"
    PollStation()
	if(summaryDashboard == true){
	if(dashboardFormat == true){advancedDash()}
	if(dashboardFormat == false){standardDash()}
	}
	if(summaryDashboard == false){sendEvent(name: "WeatherDisplay", value: "N/A ")}
}

def units(){
    state.SRU = " watts"
    state.IU = " watts"
 	state.HU = " %" 
    
    state.DecimalPlaces = decimalUnit.toInteger()
    state.DisplayUnits = unitSet
}

def pollSchedule()
{
    PollStation()
	if(summaryDashboard == true){
	if(dashboardFormat == true){advancedDash()}
	if(dashboardFormat == false){standardDash()}
	}
	if(summaryDashboard == false){sendEvent(name: "WeatherDisplay", value: "N/A ")}
}
              
def parse(String description) {
}

def PollStation()
{
    units()
    LOGDEBUG("Weewx: ForcePoll called")
    def params1 = [
        uri: "http://${ipaddress}:${weewxPort}/${weewxPath}"
         ]
    
    try {
        httpGet(params1) { resp1 ->
            resp1.headers.each {
            LOGINFO( "Response1: ${it.name} : ${it.value}")
        }
            if(logSet == true){  
           
            LOGINFO( "params1: ${params1}")
            LOGINFO( "response contentType: ${resp1.contentType}")
 		    LOGINFO( "response data: ${resp1.data}")
            } 

            if(logSet == false){ 
      //      log.info "Further Weewx detailed data logging disabled"    
            }    
            
// Collect Data
           
 // ************************ ILLUMINANCE **************************************************************************************           
           LOGINFO("Checking illuminance")    
            def illuminanceRaw = (resp1.data.stats.current.solarRadiation)  
                if(illuminanceRaw == null || illuminanceRaw.contains("N/A")){
                	state.Illuminance = '---'
                }   
            	else{
                	def illuminanceRaw1 = (resp1.data.stats.current.solarRadiation.replaceFirst(wmcode, ""))
                	state.Illuminance = illuminanceRaw1.toFloat()
                }
            
// ************************* SOLAR RADIATION*****************************************************************************************           
            	LOGINFO("Checking SolarRadiation")
              def solarradiationRaw = (resp1.data.stats.current.solarRadiation)
            	if(solarradiationRaw == null || solarradiationRaw.contains("N/A")){
                  	state.SolarRadiation = '---'
                }
            	else{
                     def solarradiationRaw1 = (resp1.data.stats.current.solarRadiation.replaceFirst(wmcode, ""))
                     state.SolarRadiation = solarradiationRaw1.toFloat()
                }
            
// ************************** HUMIDITY ***************************************************************************************   
         LOGINFO("Checking Humidity")
              def humidityRaw = (resp1.data.stats.current.humidity)
            	if(humidityRaw == null || humidityRaw.contains("N/A")){
                state.Humidity = '---'
                }
            	else{
                   def humidityRaw1 = (resp1.data.stats.current.humidity.replaceFirst("%", ""))
                   state.Humidity = humidityRaw1
                }

// ************************** INSIDE HUMIDITY ************************************************************************************
            LOGINFO("Checking Inside Humidity")
              def inHumidRaw1 = (resp1.data.stats.current.insideHumidity.replaceFirst("%", "")) 
            	if(inHumidRaw1 ==null || inHumidRaw1.contains("N/A")){
                   
                	state.InsideHumidity = '---'}
            	else{
                    
                	state.InsideHumidity = inHumidRaw1
                }
                        
            
// ************************* DEWPOINT *****************************************************************************************
            LOGINFO("Checking Dewpoint")
                def dewpointRaw1 = (resp1.data.stats.current.dewpoint)
                 	if(dewpointRaw1 == null || dewpointRaw1.contains("N/A")){
                    state.Dewpoint = '---'}
            
            	if (dewpointRaw1.contains("F")) {
                dewpointRaw1 = dewpointRaw1.replace(fcode, "")
                    
                if(temperatureUnit == "Fahrenheit (�F)"){
            	state.TU = '°F'
                state.Dewpoint = dewpointRaw1
                LOGINFO("Dewpoint Input = F - Output = F -- No conversion required")
                }    
                if(temperatureUnit == "Celsius (�C)"){
                state.TU = '°C'
                def dewpoint1 = convertFtoC(dewpointRaw1) 
                state.Dewpoint = dewpoint1 
                   
                }    
            } 
            
           		if (dewpointRaw1.contains("C")) {
                dewpointRaw1 = dewpointRaw1.replace(ccode, "")
                    
                 if(temperatureUnit == "Fahrenheit (�F)"){
            	state.TU = '°F'
                def dewpoint1 = convertCtoF(dewpointRaw1)    
                state.Dewpoint = dewpoint1 
                }    
                 if(temperatureUnit == "Celsius (�C)"){
                state.TU = '°C'
                state.Dewpoint = dewpointRaw1
                 LOGINFO("Dewpoint Input = C - Output = C -- No conversion required" ) 
                }        
            } 

// ************************** PRESSURE ****************************************************************************************            
           LOGINFO("Checking Pressure")
              def pressureRaw1 = (resp1.data.stats.current.barometer)
                    if (insideTemperatureRaw1 == null || pressureRaw1.contains("N/A")){
                    state.Pressure = '---'}
            
            if (pressureRaw1.contains("inHg")) {
                pressureRaw1 = pressureRaw1.replace("inHg", "")
                
                if(pressureUnit == "INHg"){
            	state.PU = 'inhg'
                state.Pressure = pressureRaw1
                LOGINFO("Pressure Input = INHg - Output = INHg -- No conversion required")
                }
                
                if(pressureUnit == "MBAR"){
                state.PU = 'mbar'
                def pressureTemp1 = convertINtoMB(pressureRaw1) 
                state.Pressure = pressureTemp1 
                
                }
            } 
            
            if (pressureRaw1.contains("mbar")) {
                 pressureRaw1 = pressureRaw1.replace("mbar", "")
                
            	if(pressureUnit == "INHg"){
            	state.PU = 'inhg'
                def pressureTemp1 = convertMBtoIN(pressureRaw1)
                state.Pressure = pressureTemp1
                }
                 if(pressureUnit == "MBAR"){
                 state.PU = 'mbar'
                 state.Pressure = pressureRaw1 
                 LOGINFO( "Pressure Input = MBAR - Output = MBAR --No conversion required")
                }
            } 
            
// ************************** WIND SPEED ****************************************************************************************
            LOGINFO("Checking Wind speed")
    		  def windSpeedRaw1 = (resp1.data.stats.current.windSpeed) 
            if(windSpeedRaw1 == null || windSpeedRaw1.contains("N/A")){
                    state.WindSpeed = '---'}
            
            if (windSpeedRaw1.contains("mph")) {
                windSpeedRaw1 = windSpeedRaw1.replace("mph", "")
                
                if(speedUnit == "Miles (MPH)"){
            	state.SU = 'mph'
                state.WindSpeed = windSpeedRaw1
                LOGINFO("Wind Speed Input = MPH - Output = MPH -- No conversion required")
                }
                
                if(speedUnit == "Kilometers (KPH)"){
                state.SU = 'kph'
                def speedTemp1 = convertMPHtoKPH(windSpeedRaw1) 
                state.WindSpeed = speedTemp1 
            
                }
                
            } 
            
            if (windSpeedRaw1.contains("km/h")) {
                 windSpeedRaw1 = windSpeedRaw1.replace("km/h", "")
                
            	if(speedUnit == "Miles (MPH)"){
            	state.SU = 'mph'
                def speedTemp1 = convertKPHtoMPH(pressureRaw1)
                state.WindSpeed = speedTemp1
                }
                 if(speedUnit == "Kilometers (KPH)"){
                 state.SU = 'kph'
                 state.WindSpeed = windSpeedRaw1 
                 LOGINFO("WindSpeed Input = KPH - Output = KPH --No conversion required")
                }
                
            } 
            
                   
// ************************** WIND GUST ****************************************************************************************
            LOGINFO("Checking Wind Gust")
              def windGustRaw1 = (resp1.data.stats.current.windGust)  
            	 if(windGustRaw1 == null || windGustRaw1.contains("N/A")){
                    state.WindGust = '---'}
            
            if (windGustRaw1.contains("mph")) {
                windGustRaw1 = windGustRaw1.replace("mph", "")
                
                if(speedUnit == "Miles (MPH)"){
            	state.SU = 'mph'
                state.WindGust = windGustRaw1
                LOGINFO( "Wind Gust Speed Input = MPH - Output = MPH -- No conversion required")
                }
                
                if(speedUnit == "Kilometers (KPH)"){
                state.SU = 'kph'
                def speedTemp2 = convertMPHtoKPH(windGustRaw1) 
                state.WindGust = speedTemp2 
            
                }
                
            } 
            
            if (windGustRaw1.contains("km/h")) {
                 windGustRaw1 = windGustRaw1.replace("km/h", "")
                
            	if(speedUnit == "Miles (MPH)"){
            	state.SU = 'mph'
                def speedTemp2 = convertKPHtoMPH(windGustRaw1)
                state.WindGust = speedTemp2
                }
                 if(speedUnit == "Kilometers (KPH)"){
                 state.SU = 'kph'
                 state.WindGust = windGustRaw1 
                LOGINFO( "Wind Gust Speed Input = KPH - Output = KPH --No conversion required")
                }
                
            } 
            
// ************************** INSIDE TEMP **************************************************************************************** 
          LOGINFO("Checking Inside Temperature")
              def insideTemperatureRaw1 = (resp1.data.stats.current.insideTemp)
                    if (insideTemperatureRaw1 == null || insideTemperatureRaw1.contains("N/A")){
                    state.InsideTemp = '---'}
            
            if (insideTemperatureRaw1.contains("F")) {
                insideTemperatureRaw1 = insideTemperatureRaw1.replace(fcode, "")
                
                if(temperatureUnit == "Fahrenheit (�F)"){
            	state.TU = '°F'
                state.InsideTemp = insideTemperatureRaw1
                LOGINFO("InsideTemperature Input = F - Output = F -- No conversion required")
                }
                
                if(temperatureUnit == "Celsius (�C)"){
                state.TU = '°C'
                def insideTemp1 = convertFtoC(insideTemperatureRaw1) 
                state.InsideTemp = insideTemp1 
                
                }
                
            } 
            
            if (insideTemperatureRaw1.contains("C")) {
                insideTemperatureRaw1 = insideTemperatureRaw1.replace(ccode, "")
                
            	if(temperatureUnit == "Fahrenheit (�F)"){
            	state.TU = '°F'
                def insideTemp1 = convertCtoF(insideTemperatureRaw1)
                state.InsideTemp = insideTemp1
                }
                if(temperatureUnit == "Celsius (�C)"){
                state.TU = '°C'
                state.InsideTemp = insideTemperatureRaw1  
                LOGINFO( "InsideTemperature Input = C - Output = C --No conversion required")
                }
                
            } 
  
// ************************** RAIN RATE ****************************************************************************************    
            LOGINFO("Checking Rain Rate")
            
            def rainRateRaw1 = (resp1.data.stats.current.rainRate) 
            	if(rainRateRaw1 == null || rainRateRaw1.contains("N/A")){
                   state.Rainrate = '---'}
            	
            if(rainRateRaw1.contains("in/hr")){
                rainRateRaw1 = rainRateRaw1.replace("in/hr", "")
                
                if(rainUnit == "IN"){
                    state.RRU = " in/hr"
                 	state.Rainrate = rainRateRaw1  
                    LOGINFO( "Rainrate Input = in/hr - Output = in/hr --No conversion required")
                }
            
            	if(rainUnit == "MM"){
            		state.RRU = "mm/hr"
                    rrTemp = convertINtoMM(rainRateRaw1)
                    state.Rainrate = rrTemp
            }
            }
            
             if(rainRateRaw1.contains("mm/hr")){
                rainRateRaw1 = rainRateRaw1.replace("mm/hr", "")
                0.621371
                if(rainUnit == "IN"){
                    state.RRU = "in/hr"
                    rrTemp = convertMMtoIN(rainRateRaw1)
                 	state.Rainrate = rrTemp 
                }
            
            	if(rainUnit == "MM"){
            		state.RRU = " mm/hr"
                   state.Rainrate = rainRateRaw1 
                   LOGINFO( "Rainrate Input = mm/hr - Output = mm/hr --No conversion required")
            }
            }
            

// ************************** RAIN TODAY ****************************************************************************************    
            LOGINFO("Checking Rain Today")
              def rainTodayRaw1 = (resp1.data.stats.sinceMidnight.rainSum)
               	if(rainTodayRaw1 == null || rainTodayRaw1.contains("N/A")){
                   state.RainToday = '---'}
            	
            if(rainTodayRaw1.contains("in")){
                rainTodayRaw1 = rainTodayRaw1.replace("in", "")
                
                if(rainUnit == "IN"){
                    state.RU = "in"
                 	state.RainToday = rainTodayRaw1 
                    LOGINFO( "RainToday Input = in - Output = in --No conversion required")
                }
            
            	if(rainUnit == "MM"){
            		state.RU = "mm"
                    rtTemp = convertINtoMM(rainTodayRaw1)
                    state.RainToday = rtTemp
            }
            }
            
             if(rainTodayRaw1.contains("mm")){
                rainTodayRaw1 = rainTodayRaw1.replace("mm", "")
                
                if(rainUnit == "IN"){
                    state.RU = "in"
                    rtTemp = convertMMtoIN(rainTodayRaw1)
                 	state.RainToday = rtTemp 
                }
            
            	if(rainUnit == "MM"){
            		state.RU = "mm"
                   state.RainToday = rainTodayRaw1 
                  LOGINFO("RainToday Input = mm - Output = mm --No conversion required")
            }
            }


// ************************** TEMPERATURE ****************************************************************************************
            LOGINFO("Checking Temperature")
              def temperatureRaw1 = (resp1.data.stats.current.outTemp) 
            	if(temperatureRaw1 ==null || temperatureRaw1.contains("N/A")){
                state.Temperature = '---'}
            
            if (temperatureRaw1.contains("F")) {
                temperatureRaw1 = temperatureRaw1.replace(fcode, "")
                
                if(temperatureUnit == "Fahrenheit (�F)"){
            	state.TU = '°F'
                state.Temperature = temperatureRaw1
                LOGINFO("Temperature Input = F - Output = F -- No conversion required")
                }
                
                if(temperatureUnit == "Celsius (�C)"){
                state.TU = '°C'
                def temp1 = convertFtoC(temperatureRaw1) 
                state.Temperature = temp1 
                
                }
                
            } 
            
            if (temperatureRaw1.contains("C")) {
                temperatureRaw1 = temperatureRaw1.replace(ccode, "")
                
            	if(temperatureUnit == "Fahrenheit (�F)"){
            	state.TU = '°F'
                    def temp1 = convertCtoF(temperatureRaw1)
                state.Temperature = temp1
                }
                if(temperatureUnit == "Celsius (�C)"){
                state.TU = '°C'
                state.Temperature = temperatureRaw1  
                 LOGINFO("Temperature Input = C - Output = C --No conversion required")
                }
                
            }
           
                    
// ************************** MIN Outside TEMPERATURE *******************************************************************************                     

             LOGINFO("Checking Min Outside Temperature")
              def tempMinRaw1 = (resp1.data.stats.sinceMidnight.mintemptoday) 
            	if(tempMinRaw1 ==null || tempMinRaw1.contains("N/A")){
                state.MinTemperature = '---'}
            
            if (tempMinRaw1.contains("F")) {
                tempMinRaw1 = tempMinRaw1.replace(fcode, "")
                
                if(temperatureUnit == "Fahrenheit (�F)"){
            	state.TU = '°F'
                state.MinTemperature = tempMinRaw1
                LOGINFO("Min Temperature Input = F - Output = F -- No conversion required")
                }
                
                if(temperatureUnit == "Celsius (�C)"){
                state.TU = '°C'
                def tempMin = convertFtoC(tempMinRaw1) 
                state.MinTemperature = tempMin 
                
                }
                
            } 
            
            if (tempMinRaw1.contains("C")) {
                tempMinRaw1 = tempMinRaw1.replace(ccode, "")
                
            	if(temperatureUnit == "Fahrenheit (�F)"){
            	state.TU = '°F'
                    def tempMin = convertCtoF(tempMinRaw1)
                state.MinTemperature = tempMin
                }
                if(temperatureUnit == "Celsius (�C)"){
                state.TU = '°C'
                state.MinTemperature = tempMinRaw1 
                 LOGINFO("Min Temperature Input = C - Output = C --No conversion required")
                }
                
            } 
            
            
 // ************************** MAX Outside TEMPERATURE *******************************************************************************                     

             LOGINFO("Checking Max Outside Temperature")
              def tempMaxRaw1 = (resp1.data.stats.sinceMidnight.maxtemptoday) 
            	if(tempMaxRaw1 ==null || tempMaxRaw1.contains("N/A")){
                state.MaxTemperature = '---'}
            
            if (tempMaxRaw1.contains("F")) {
                tempMaxRaw1 = tempMaxRaw1.replace(fcode, "")
                
                if(temperatureUnit == "Fahrenheit (�F)"){
            	state.TU = '°F'
                state.MaxTemperature = tempMaxRaw1
                LOGINFO("Max Temperature Input = F - Output = F -- No conversion required")
                }
                
                if(temperatureUnit == "Celsius (�C)"){
                state.TU = '°C'
                def tempMax = convertFtoC(tempMaxRaw1) 
                state.MaxTemperature = tempMax 
                
                }
                
            } 
            
            if (tempMaxRaw1.contains("C")) {
                tempMaxRaw1 = tempMaxRaw1.replace(ccode, "")
                
            	if(temperatureUnit == "Fahrenheit (�F)"){
            	state.TU = '°F'
                    def tempMax = convertCtoF(tempMaxRaw1)
                state.MaxTemperature = tempMax
                }
                if(temperatureUnit == "Celsius (�C)"){
                state.TU = '°C'
                state.MaxTemperature = tempMaxRaw1 
                 LOGINFO("Max Temperature Input = C - Output = C --No conversion required")
                }
                
            }            
            
// ************************** MIN Inside TEMPERATURE *******************************************************************************                     

             LOGINFO("Checking Min Inside Temperature")
              def tempMinInRaw1 = (resp1.data.stats.sinceMidnight.mininsidetemptoday) 
            	if(tempMinInRaw1 ==null || tempMinInRaw1.contains("N/A")){
                state.MinInsideTemperature = '---'}
            
            if (tempMinInRaw1.contains("F")) {
                tempMinInRaw1 = tempMinInRaw1.replace(fcode, "")
                
                if(temperatureUnit == "Fahrenheit (�F)"){
            	state.TU = '°F'
                state.MinInsideTemperature = tempMinInRaw1
                LOGINFO("Min Temperature Input = F - Output = F -- No conversion required")
                }
                
                if(temperatureUnit == "Celsius (�C)"){
                state.TU = '°C'
                def tempMinIn = convertFtoC(tempMinInRaw1) 
                state.MinInsideTemperature = tempMinIn 
                
                }
                
            } 
            
            if (tempMinInRaw1.contains("C")) {
                tempMinInRaw1 = tempMinInRaw1.replace(ccode, "")
                
            	if(temperatureUnit == "Fahrenheit (�F)"){
            	state.TU = '°F'
                    def tempMinIn = convertCtoF(tempMinInRaw1)
                state.MinInsideTemperature = tempMinIn
                }
                if(temperatureUnit == "Celsius (�C)"){
                state.TU = '°C'
                state.MinInsideTemperature = tempMinInRaw1 
                 LOGINFO("Min Temperature Input = C - Output = C --No conversion required")
                }
                
            }    
            
            
  // ************************** MAX Inside TEMPERATURE *******************************************************************************                     

             LOGINFO("Checking Max Inside Temperature")
              def tempMaxInRaw1 = (resp1.data.stats.sinceMidnight.maxinsidetemptoday) 
            	if(tempMaxInRaw1 ==null || tempMaxInRaw1.contains("N/A")){
                state.MaxInsideTemperature = '---'}
            
            if (tempMaxInRaw1.contains("F")) {
                tempMaxInRaw1 = tempMaxInRaw1.replace(fcode, "")
                
                if(temperatureUnit == "Fahrenheit (�F)"){
            	state.TU = '°F'
                state.MaxInsideTemperature = tempMaxInRaw1
                LOGINFO("Max Temperature Input = F - Output = F -- No conversion required")
                }
                
                if(temperatureUnit == "Celsius (�C)"){
                state.TU = '°C'
                def tempMaxIn = convertFtoC(tempMaxInRaw1) 
                state.MaxInsideTemperature = tempMaxIn 
                
                }
                
            } 
            
            if (tempMaxInRaw1.contains("C")) {
                tempMaxInRaw1 = tempMaxInRaw1.replace(ccode, "")
                
            	if(temperatureUnit == "Fahrenheit (�F)"){
            	state.TU = '°F'
                    def tempMaxIn = convertCtoF(tempMaxInRaw1)
                state.MaxInsideTemperature = tempMaxIn
                }
                if(temperatureUnit == "Celsius (�C)"){
                state.TU = '°C'
                state.MaxInsideTemperature = tempMaxInRaw1 
                 LOGINFO("Max Temperature Input = C - Output = C --No conversion required")
                }
                
            }             
            
            
// ************************** UV ************************************************************************************************            
            LOGINFO("Checking UV")
              def UVRaw1 = (resp1.data.stats.current.UV)
            	if(UVRaw1 ==null || UVRaw1.contains("N/A")){
                   
                	state.UV = '---'}
            	else{
                    state.UV = UVRaw1
   
                    
 // Calculate UV likelyhood of causing harm to someone *****************************************************     
          LOGINFO("Checking UV Harm")          
                    
                    LOGINFO ( "state.UV -- $state.UV")
                    if(state.UV <= '0.1'){
                        state.UVHarm = 'Zero'
                        LOGINFO  ("UV Zero -- $state.UV")
                    }
                    if(state.UV >= '0.2' && state.UV <= '2.9'){
                        state.UVHarm = 'Low'
                         LOGINFO  ( "UV Low -- $state.UV")
                    }
                    if(state.UV >= '3.0' && state.UV <= '5.9'){
                        state.UVHarm = 'Moderate'
                        LOGINFO  ( "UV Moderate -- $state.UV")
                    }
            		if(state.UV >= '6.0' && state.UV <= '7.9'){
                        state.UVHarm = 'High'
                         LOGINFO  ( "UV High -- $state.UV")
                    }
 					if(state.UV >= '8.0' && state.UV <= '9.8'){
                        state.UVHarm = 'VeryHigh'
                        LOGINFO  ( "UV VeryHigh -- $state.UV")
                    }
					if(state.UV >= "9.99"){
                        state.UVHarm = 'Extreme'
                         LOGINFO  ( "UV Extreme -- $state.UV")
                    }
                } 

// ************************** WINDCHILL ****************************************************************************************            
            LOGINFO("Checking WindChill")
              def windChillRaw1 = (resp1.data.stats.current.windchill)
            	if(windChillRaw1 ==null || windChillRaw1.contains("N/A")){
                   state.FeelsLike = '---'}
                	
            
 				if (windChillRaw1.contains("F")) {
                windChillRaw1 = windChillRaw1.replace(fcode, "")
                
                if(temperatureUnit == "Fahrenheit (�F)"){
            	state.TU = '&deg;F'
                state.FeelsLike = windChillRaw1
                LOGINFO( "FeelsLike Input = F - Output = F -- No conversion required")
                }
                
                if(temperatureUnit == "Celsius (�C)"){
                state.TU = '&deg;C'
                def feelslike1 = convertFtoC(windChillRaw1) 
                state.FeelsLike = feelslike1
                
                }
                
            } 
            
            if (windChillRaw1.contains("C")) {
                windChillRaw1 = windChillRaw1.replace(ccode, "")
                             
            	if(temperatureUnit == "Fahrenheit (�F)"){
            	state.TU = '&deg;F'
                def feelslike1 = convertCtoF(windChillRaw1)
                state.FeelsLike = feelslike1
                }
                if(temperatureUnit == "Celsius (�C)"){
                state.TU = '&deg;C'
                state.FeelsLike = windChillRaw1 
                 LOGINFO( "FeelsLike Input = C - Output = C --No conversion required")
                }
                
            } 
           
// ************************** WIND DIR ****************************************************************************************  
             LOGINFO("Checking Wind direction")
            def windDirRaw = (resp1.data.stats.current.windDirText)
            	if(windDirRaw != null){
					if(windDirRaw.contains("N/A")){state.WindDir = "---"}	
					else {state.WindDir = windDirRaw}
					sendEvent(name: "wind_dir", value: state.WindDir, isStateChange: true)	
                
                }                    

// ************************** PRESSURE TREND ************************************************************************************   
             LOGINFO("Checking Pressure Trend")
             def pressureTrend = (resp1.data.stats.current.barometerTrendData) 
                  if(pressureTrend != null){
					  if(pressureTrend.contains("N/A")){state.PressureTrend = "---"}
					  else if(pressureTrend.contains("-")){state.PressureTrend = "Falling"}					
					  else if(pressureTrend.contains("+")){state.PressureTrend = "Rising"}
					  else {state.PressureTrend = "Static"}
					  sendEvent(name: "pressure_trend", value:state.PressureTrend, isStateChange: true)
                  }
            
 // Basics - No units ************************************************************************************************
			state.LocalSunrise = (resp1.data.almanac.sun.sunrise)
			state.LocalSunset = (resp1.data.almanac.sun.sunset)

             sendEvent(name: "WeewxUptime", value: resp1.data.serverUptime)
             sendEvent(name: "WeewxLocation", value: resp1.data.location)
             sendEvent(name: "Refresh-Weewx", value: pollInterval)
             sendEvent(name: "localSunrise", value: state.LocalSunrise, isStateChange: true)
             sendEvent(name: "localSunset", value: state.LocalSunset, isStateChange: true)
             sendEvent(name: "uv", value: state.UV, isStateChange: true)
             sendEvent(name: "uvHarm", value: state.UVHarm, isStateChange: true)
             sendEvent(name: "LastUpdate-Weewx", value: resp1.data.time)
            
// // Send Events  - WITH UNITS ********************************************************************************************            
              if(state.DisplayUnits == true){  
                         
                  sendEvent(name: "illuminance", value: state.Illuminance +" " +state.IU)
                  sendEvent(name: "solarradiation", value: state.SolarRadiation +" " +state.SRU)
                  sendEvent(name: "dewpoint", value: state.Dewpoint +" " +state.TU)
                  sendEvent(name: "humidity", value: state.Humidity +" " +state.HU)
                  sendEvent(name: "pressure", value: state.Pressure +" " +state.PU) 
                  sendEvent(name: "wind", value: state.WindSpeed +" " +state.SU)
                  sendEvent(name: "wind_gust", value: state.WindGust +" " +state.SU)
                  sendEvent(name: "maxwindGust", value: state.maxwindGust +" " +state.SU)
                  sendEvent(name: "inside_temperature", value: state.InsideTemp +" " +state.TU)
                  sendEvent(name: "inside_humidity", value: state.InsideHumidity +" " +state.HU)  
                  sendEvent(name: "temperature", value: state.Temperature +" " +state.TU)
                  sendEvent(name: "rain_rate", value: state.Rainrate +" " +state.RRU)
                  sendEvent(name: "precip_today", value: state.RainToday +" " +state.RU) 
                  sendEvent(name: "precip_1hr", value: state.Rainrate +" " +state.RU)
                  sendEvent(name: "feelsLike", value: state.FeelsLike +" " +state.TU)                
                  sendEvent(name: "tempMaxTemperature", value: state.MaxTemperature +" " +state.TU)
    			  sendEvent(name: "tempMinToday", value: state.MinTemperature +" " +state.TU)
                  sendEvent(name: "tempMaxInsideToday", value: state.MaxInsideTemperature +" " +state.TU)
    			  sendEvent(name: "tempMinInsideToday", value: state.MinInsideTemperature +" " +state.TU)
              }
            
// // Send Events  - WITHOUT UNITS ****************************************************************************************
            
            if(state.DisplayUnits == false){
                
                  sendEvent(name: "illuminance", value: state.Illuminance, unit: "lux", isStateChange: true)    
                  sendEvent(name: "solarradiation", value: state.SolarRadiation, unit: "lux", isStateChange: true)
                  sendEvent(name: "dewpoint", value: state.Dewpoint, isStateChange: true)
                  sendEvent(name: "humidity", value: state.Humidity, isStateChange: true)
                  sendEvent(name: "pressure", value: state.Pressure, isStateChange: true)
                  sendEvent(name: "wind", value: state.WindSpeed, isStateChange: true)
                  sendEvent(name: "wind_gust", value: state.WindGust, isStateChange: true)
                  sendEvent(name: "maxwindGust", value: state.maxwindGust, isStateChange: true)
                  sendEvent(name: "inside_temperature", value: state.InsideTemp, isStateChange: true)
                  sendEvent(name: "inside_humidity", value: state.InsideHumidity, isStateChange: true)   
                  sendEvent(name: "temperature", value: state.Temperature, isStateChange: true)
                  sendEvent(name: "rain_rate", value: state.Rainrate, isStateChange: true)  
                  sendEvent(name: "precip_today", value: state.RainToday, isStateChange: true)  
                  sendEvent(name: "precip_1hr", value: state.Rainrate, isStateChange: true)  
                  sendEvent(name: "feelsLike", value: state.FeelsLike, isStateChange: true) 
             	  sendEvent(name: "tempMaxToday", value: state.MaxTemperature, isStateChange: true)
    			  sendEvent(name: "tempMinToday", value: state.MinTemperature, isStateChange: true)
                  sendEvent(name: "tempMaxInsideToday", value: state.MaxInsideTemperature, isStateChange: true)
    			  sendEvent(name: "tempMinInsideToday", value: state.MinInsideTemperature, isStateChange: true)
        }
   } 
        
    } catch (e) {
        log.error "something went wrong: $e"
    }
}

def checkInput(){
    listInput = [
		"Blank Line",
		"Free Text",
        "City",
		"State - County",
        "External Temp",
        "External Temp (Feels Like)",
        "External Temp (Feels Like) Humidity",
		"Forecast Low, Forecast High",
		"Temp Feels Like",
		"Humidity",
        "Wind Speed",
		"Wind Speed, Wind Gust",
		"Wind Speed, Wind Direction, Wind Gust",
		"Wind Speed, Wind Direction",
		"Weather Current",
        "Weather Forecast",
		"Chance of Rain",
        "Rain Today",
        "Sunrise & Sunset"
]
     return listInput
}

 // Future feature
def fSize1(){
	if(fsize == '1') {state.fsize = '-2'}
	if(fsize == '2') {state.fsize = '-1'}
	if(fsize == '3') {state.fsize = '+1'}
	if(fsize == '4') {state.fsize = '+3'}
	if(fsize == '5') {state.fsize = '+5'}	
}

def fontSize(){
	listInput1 = ["1","2","3","4","5"]  
	return listInput1
}

def sData(){
	state.slot1 = slot1
	state.slot2 = slot2
	state.slot3 = slot3
	state.slot4 = slot4
	state.slot5 = slot5
	state.slot6 = slot6
	state.slot7 = slot7
	state.slot8 = slot8
	state.slot1Text = slot1Text1
	state.slot2Text = slot2Text1
	state.slot3Text = slot3Text1
	state.slot4Text = slot4Text1
	state.slot5Text = slot5Text1
	state.slot6Text = slot6Text1
	state.slot7Text = slot7Text1
	state.slot8Text = slot8Text1	
	if(slot1){
For faster browsing, not all history is shown. View entire blame