forked from thebearmay/hubitat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hubInfo.groovy
1494 lines (1360 loc) · 55.6 KB
/
hubInfo.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
/*
* Hub Info
*
* Licensed Virtual 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.
*
* Change History:
*
* Date Who What
* ---- --- ----
* 2020-12-07 thebearmay Original version 0.1.0
* 2021-01-30 thebearmay Add full hub object properties
* 2021-01-31 thebearmay Code cleanup, release ready
* 2021-01-31 thebearmay Putting a config delay in at initialize to make sure version data is accurate
* 2021-02-16 thebearmay Add text date for restart
* 2021-03-04 thebearmay Added CPU and Temperature polling
* 2021-03-05 thebearmay Merged CSteele additions and added the degree symbol and scale to the temperature attribute
* 2021-03-05 thebearmay Merged addtions from LGKhan: Added new formatted uptime attr, also added an html attr that stores a bunch of the useful
* info in table format so you can use on any dashboard
* 2021-03-06 thebearmay Merged security login from BPTWorld (from dman2306 rebooter app)
* 2021-03-06 thebearmay Change numeric attributes to type number
* 2021-03-08 thebearmay Incorporate CSteele async changes along with some code cleanup and adding tags to the html to allow CSS overrides
* 2021-03-09 thebearmay Code tightening as suggested by CSteele, remove state variables, etc.
* 2021-03-11 thebearmay Add Sensor capability for Node-Red/MakerAPI
* 2021-03-11 thebearmay Security not set right at initialize, remove state.attrString if it exists (now a local variable)
* 2021-03-19 thebearmay Add attributes for JVM Total, Free, and Free %
* Add JVM info to HTML
* Fix for exceeded 1024 attr limit
* 2021-03-20 thebearmay Firmware 2.2.6.xxx support, CPU 5min Load
* 2021-03-23 thebearmay Add DB Size
* 2021-03-24 thebearmay Calculate CPU % from load
* 2021-03-28 thebearmay jvmWork.eachline error on reboot
* 2021-03-30 thebearmay Index out of bounds on reboot
* 2021-03-31 thebearmay jvm to HTML null error (first run)
* 2021-04-13 thebearmay pull in suggested additions from lgkhan - external IP and combining some HTML table elements
* 2021-04-14 thebearmay add units to the HTML
* 2021-04-20 thebearmay provide a smooth transition from 1.8.x to 1.9.x
* 2021-04-26 thebearmay break out polls as separate preference options
* 2021-04-27 thebearmay replace the homegrown JSON parser, with groovy's JsonSluper
* 2021-04-29 thebearmay merge pull request from nh.schottfam, clean up/add type declarations, optimize code and add local variables
* 2021-05-03 thebearmay add nonPolling zigbee channel attribute, i.e. set at hub startup
* 2021-05-04 thebearmay release 2.2.7.x changes (v2.2.0 - v2.2.2)
* 2021-05-06 thebearmay code cleanup from 2.2.2, now 2.2.3
* 2021-05-09 thebearmay return NA when zigbee channel not valid
* 2021-05-25 thebearmay use upTime to recalculate system start when initialize called manually
* 2021-05-25 thebearmay upTime display lagging by 1 poll
* 2021-06-11 thebearmay add units to the jvm and memory attributes
* 2021-06-12 thebearmay put a space between unit and values
* 2021-06-14 thebearmay add Max State/Event days, required trimming of the html attribute
* 2021-06-15 thebearmay add ZWave Version attribute
* 2.4.1 temporary version to stop overflow on reboot
* 2021-06-16 thebearmay 2.4.2 overflow trap/retry
* 2.4.3 firmware0Version and subVersion is the radio firmware. target 1 version and subVersion is the SDK
* 2.4.4/5 restrict Zwave Version query to C7
* 2021-06-17 thebearmay 2.4.8-10 - add MAC address and hub model, code cleanup, better compatibility check, zwaveVersion check override
* 2021-06-17 thebearmay freeMemPollEnabled was combined with the JVM/CPU polling when creating the HTML
* 2021-06-19 thebearmay fix the issue where on a driver update, if configure isn't a hubModel and macAddr weren't updated
* 2021-06-29 thebearmay 2.2.8.x removes JVM data -> v2.5.0
* 2021-06-30 thebearmay clear the JVM attributes if >=2.2.8.0, merge pull request from nh.schottfam (stronger typing)
* 2021-07-01 thebearmay allow Warn level logging to be suppressed
* 2021-07-02 thebearmay fix missing formatAttrib call
* 2021-07-15 thebearmay attribute clear fix
* 2021-07-22 thebearmay prep work for deleteCurrentState() with JVM attributes
* use the getHubVersion() call for >=2.2.8.141
* 2021-07-23 thebearmay add remUnused preference to remove all attributes that are not being polled
* 2021-08-03 thebearmay put back in repoll on invalid zigbee channel
* 2021-08-14 thebearmay add html update from HIA
* 2021-08-19 thebearmay zwaveSDKVersion not in HTML
* 2021-08-23 thebearmay simplify unit retrieval
* 2021-09-16 thebearmay add localIP check into the polling cycle instead of one time check
* 2021-09-29 thebearmay suppress temperature event if negative
* 2021-10-21 thebearmay force a read against the database instead of cache when building html
* 2021-11-02 thebearmay add hubUpdateStatus
* 2021-11-05 thebearmay add hubUpdateVersion
* 2021-11-09 thebearmay add NTP Information
* 2021-11-24 thebearmay remove the hub update response attribute - release notes push it past the 1024 size limit.
* 2021-12-01 thebearmay add additional subnets information
* 2021-12-07 thebearmay allow data attribute to be suppressed if zigbee data is null, remove getMacAddress() as it has been retired from the API
* 2021-12-08 thebearmay fix zigbee channel bug
* 2021-12-27 thebearmay 169.254.x.x reboot option
* 2022-01-17 thebearmay allow reboot to be called without Hub Monitor parameter
* 2022-01-21 thebearmay add Mode and HSM Status as a pollable attribute
* 2022-03-03 thebearmay look at attribute size each poll and enforce 1024 limit
* 2022-03-09 thebearmay fix lastUpdated not always updated
* 2022-03-17 thebearmay add zigbeeStatus
* 2022-03-18 thebearmay add zwaveStatus
* 2022-03-23 thebearmay code cleanup
* 2022-03-27 thebearmay fix zwaveStatus with hub security
* 2022-03-28 thebearmay add a try..catch around the zwaveStatus
* 2022-05-17 thebearmay enforce 1 decimal place for temperature
* 2022-05-20 thebearmay remove a check/force remove for hubUpdateResp
* 2022-06-10 thebearmay add hubAlerts, change source for zwaveStatus
* 2022-06-20 thebearmay trap login error
* 2022-06-24 thebearmay add hubMesh data
* 2022-06-30 thebearmay add shutdown command
* 2022-08-11 thebearmay add attribute update logging
* 2022-08-15 thebearmay add zigbeeStatus2 from the hub2 data
* 2022-08-19 thebearmay allow for a user defined HTML attribute using a file template
* 2022-08-24 thebearmay switch all HTML attribute processing to the template
* 2022-09-18 thebearmay add a security in use attribute
* 2022-09-29 thebearmay handle null or 'null' html template
* 2022-10-20 thebearmay add sunrise sunset
* 2022-10-21 thebearmay add format option for lastUpdated
* 2022-10-25 thebearmay handle a 408 in fileExists()
* 2022-10-26 thebearmay fix a typo
* 2022-10-28 thebearmay add a couple of additional dateTime formats, add traps for null sdf selection
* 2022-11-18 thebearmay add an attribute to display next poll time, add checkPolling method instead of forcing a poll at startup
* 2022-11-22 thebearmay catch an error on checking poll times
* 2022-11-22 thebearmay correct stack overflow
* 2022-11-23 thebearmay change host for publicIP
* 2022-11-25 thebearmay log.warn instead of log.warning
* 2022-12-09 thebearmay fix timing issue with Next Poll Time
* 2022-12-23 thebearmay use the loopback address for shutdown and reboot
* 2022-12-29 thebearmay more hub2 data with HEv2.3.4.126
* 2023-01-03 thebearmay minor cosmetic fixes
*/
import java.text.SimpleDateFormat
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import groovy.transform.Field
@SuppressWarnings('unused')
static String version() {return "2.7.22"}
metadata {
definition (
name: "Hub Information",
namespace: "thebearmay",
author: "Jean P. May, Jr.",
importUrl:"https://raw.githubusercontent.com/thebearmay/hubitat/main/hubInfo.groovy"
) {
capability "Actuator"
capability "Configuration"
capability "Initialize"
capability "Refresh"
capability "Sensor"
capability "TemperatureMeasurement"
attribute "latitude", "string"
attribute "longitude", "string"
attribute "hubVersion", "string"
attribute "id", "string"
attribute "name", "string"
attribute "data", "string"
attribute "zigbeeId", "string"
attribute "zigbeeEui", "string"
attribute "hardwareID", "string"
attribute "type", "string"
attribute "localIP", "string"
attribute "localSrvPortTCP", "string"
attribute "uptime", "number"
attribute "lastUpdated", "string"
attribute "lastHubRestart", "string"
attribute "firmwareVersionString", "string"
attribute "timeZone", "string"
attribute "temperatureScale", "string"
attribute "zipCode", "string"
attribute "locationName", "string"
attribute "locationId", "string"
attribute "lastHubRestartFormatted", "string"
attribute "freeMemory", "number"
attribute "temperatureF", "string"
attribute "temperatureC", "string"
attribute "formattedUptime", "string"
attribute "html", "string"
attribute "jvmTotal", "number"
attribute "jvmFree", "number"
attribute "jvmFreePct", "number"
attribute "cpu5Min", "number"
attribute "cpuPct", "number"
attribute "dbSize", "number"
attribute "publicIP", "string"
attribute "zigbeeChannel","string"
attribute "maxEvtDays", "number"
attribute "maxStateDays", "number"
attribute "zwaveVersion", "string"
attribute "zwaveSDKVersion", "string"
attribute "zwaveData", "string"
attribute "hubModel", "string"
attribute "hubUpdateStatus", "string"
attribute "hubUpdateVersion", "string"
attribute "currentMode", "string"
attribute "currentHsmMode", "string"
attribute "ntpServer", "string"
attribute "ipSubnetsAllowed", "string"
attribute "zigbeeStatus", "string"
attribute "zigbeeStatus2", "string"
attribute "zigbeeStack", "string"
attribute "zwaveStatus", "string"
attribute "hubAlerts", "string"
attribute "hubMeshData", "string"
attribute "hubMeshCount", "number"
attribute "securityInUse", "string"
attribute "sunrise", "string"
attribute "sunset", "string"
attribute "nextPoll", "string"
//HE v2.3.4.126
attribute "connectType", "string" //Ethernet, WiFi, Dual
attribute "dnsServers", "string"
attribute "staticIPJson", "string"
attribute "lanIPAddr", "string"
attribute "wirelessIP", "string"
attribute "wifiNetwork", "string"
command "hiaUpdate", ["string"]
command "reboot"
command "shutdown"
command "updateCheck"
}
}
preferences {
input("quickref","href", title:"<a href='https://htmlpreview.github.io/?https://github.com/thebearmay/hubitat/blob/main/hubInfoQuickRef.html' target='_blank'>Quick Reference v${version()}</a>")
input("debugEnable", "bool", title: "Enable debug logging?", width:4)
input("warnSuppress", "bool", title: "Suppress Warn Level Logging", width:4)
input("tempPollEnable", "bool", title: "Enable Temperature Polling", width:4)
input("freeMemPollEnabled", "bool", title: "Enable Free Memory Polling", width:4)
input("cpuPollEnabled", "bool", title: "Enable CPU Load Polling", width:4)
input("dbPollEnabled","bool", title: "Enable DB Size Polling", width:4)
input("publicIPEnable", "bool", title: "Enable Querying the cloud \nto obtain your Public IP Address?", defaultValue: false, required: false, submitOnChange: true, width:4)
input("evtStateDaysEnable", "bool", title:"Enable Display of Max Event/State Days Setting", width:4)
input("attribEnable", "bool", title: "Enable HTML Attribute Creation?", defaultValue: false, required: false, submitOnChange: true, width:4)
input("alternateHtml", "string", title: "Template file for HTML attribute", submitOnChange: true, defaultValue: "hubInfoTemplate.res")
input("checkZwVersion","bool",title:"Force Update of ZWave Version Attribute", defaultValue: false, submitOnChange: true, width:4)
input("zwLocked", "bool", title: "Never Run ZWave Version Update", defaultValue:false, submitOnChange: true, width:4)
input("ntpCkEnable","bool", title: "Check NTP Server on Poll", defaultValue:false,submitOnChange: true, width:4)
input("subnetEnable", "bool", title: "Check for additional Subnets on Poll",defaultValue:false,submitOnChange: true, width:4)
input("hubMeshPoll", "bool", title: "Include Hub Mesh Data", defaultValue:false, submitOnChange:true, width:4)
input("extNetData", "bool", title: "Include Expanded Network Data", defaultValue: false, submitOnChange:true, width:4)
input("sunSdfPref", "enum", title: "Date/Time Format for Sunrise/Sunset", options:sdfList, defaultValue:"HH:mm:ss", width:4)
input("updSdfPref", "enum", title: "Date/Time Format for Last Updated", options:sdfList, defaultValue:"Milliseconds", width:4)
input("upTimeSep", "string", title: "Separator for Formatted Uptime", defaultValue: ",", width:4)
input("suppressData", "bool", title: "Suppress <i>data</i> attribute if Zigbee is null", defaultValue:false, submitOnChange: true, width:4)
input("remUnused", "bool", title: "Remove unused attributes (Requires HE >= 2.2.8.141", defaultValue: false, submitOnChange: true, width:4)
input("attrLogging", "bool", title: "Log all attribute changes", defaultValue: false, submitOnChange: true, width:4)
input("allowReboot","bool", title: "Allow Hub to be shutdown or rebooted", defaultValue: false, submitOnChange: true, width:4)
input("security", "bool", title: "Hub Security Enabled", defaultValue: false, submitOnChange: true, width:4)
if (security) {
input("username", "string", title: "Hub Security Username", required: false, width:4)
input("password", "password", title: "Hub Security Password", required: false, width:4)
}
if(pollingCheck())
input("tempPollRate", "number", title: "Polling Rate (seconds)\nDefault:300", defaultValue:300, submitOnChange: true, width:4)
input("fwUpdatePollRate","number", title:"Poll rate (in seconds) for FW Update Check (Default:6000, Disable:0):", defaultValue:6000, submitOnChange:true, width:4)
if(fwUpdatePollRate != null && fwUpdatePollRate.toInteger() > 0)
input("rawUpdateNotice", "bool", title:"Use raw update notice", defaultValue:true, width:4, submitOnChange:true)
}
boolean pollingCheck(){
if(tempPollEnable||freeMemPollEnabled||cpuPollEnabled||dbPollEnabled||publicIPEnable||evtStateDaysEnable||checkZwVersion||ntpCkEnable||subnetEnable||hubMeshPoll||extNetData)
return true
else
return false
}
@SuppressWarnings('unused')
def installed() {
log.trace "installed()"
xferFile("https://raw.githubusercontent.com/thebearmay/hubitat/main/hubInfoTemplate.res","hubInfoTemplate.res")
initialize()
}
def initialize(){
log.trace "Hub Information Driver ${version()} initialized"
if (!security) device.updateSetting("security",[value:"false",type:"bool"])
// will additionally be checked before execution to determine if C-7 or above
if(!zwLocked)
device.updateSetting("checkZwVersion",[value:"true",type:"bool"])
pollHub2()
runIn(45,"configure")
restartCheck() //set Restart Time using uptime and current timeatamp
}
@SuppressWarnings('unused')
def updated(){
if(debugEnable) {
log.debug "updated()"
runIn(1800,logsOff)
}
if(pollingCheck()){
unschedule("getPollValues")
getPollValues()
}else {
unschedule("getPollValues")
updateAttr("nextPoll","None")
}
if(fwUpdatePollRate == null)
device.updateSetting("fwUpdatePollRate",[value:6000,type:"number"])
if(fwUpdatePollRate>0){
unschedule("updateCheck")
updateCheck()
}
if(warnSuppress == null) device.updateSetting("warnSuppress",[value:"false",type:"bool"])
if (attribEnable)
altHtml()
else if(location.hub.firmwareVersionString < "2.2.8.141")
sendEvent(name: "html", value: "<table></table>", isChanged: true)
if(remUnused && location.hub.firmwareVersionString >= "2.2.8.141") {
if(location.hub.firmwareVersionString >= "2.2.8.0") {
device.deleteCurrentState("jvmFree")
device.deleteCurrentState("jvmTotal")
device.deleteCurrentState("jvmFreePct")
}
if(!tempPollEnable) {
device.deleteCurrentState("temperatureC")
device.deleteCurrentState("temperatureF")
device.deleteCurrentState("temperature")
}
if(!freeMemPollEnabled){
device.deleteCurrentState("freeMemory")
}
if(!cpuPollEnabled){
device.deleteCurrentState("cpu5Min")
device.deleteCurrentState("cpuPct")
}
if(!dbPollEnabled){
device.deleteCurrentState("dbSize")
}
if(!publicIPEnable){
device.deleteCurrentState("publicIP")
}
if(!checkZwVersion){
device.deleteCurrentState("zwaveSDKVersion")
device.deleteCurrentState("zwaveVersion")
}
if(!attribEnable){
device.deleteCurrentState("html")
}
if(!evtStateDaysEnable){
device.deleteCurrentState("maxStateDays")
device.deleteCurrentState("maxEvtDays")
}
if(!ntpCkEnable){
device.deleteCurrentState("ntpServer")
}
if(!subnetEnable){
device.deleteCurrentState("ipSubnetsAllowed")
}
if(!hubMeshPoll){
device.deleteCurrentState("hubMeshData")
device.deleteCurrentState("hubMeshCount")
}
if(!extNetData) {
device.deleteCurrentState("connectType")
device.deleteCurrentState("dnsServers")
device.deleteCurrentState("staticIPJson")
device.deleteCurrentState("lanIPAddr")
device.deleteCurrentState("dnsServers")
device.deleteCurrentState("wirelessIP")
device.deleteCurrentState("wifiNetwork")
}
device.deleteCurrentState("hubUpdateResp")
}
if(attribEnable && fileExists("$alternateHtml") != true){
xferFile("https://raw.githubusercontent.com/thebearmay/hubitat/main/hubInfoTemplate.res","hubInfoTemplate.res")
device.updateSetting("alternateHtml",[value:"hubInfoTemplate.res",type:"string"])
}
}
@SuppressWarnings('unused')
def configure() {
if(debugEnable) log.debug "configure()"
List locProp = ["latitude", "longitude", "timeZone", "zipCode", "temperatureScale"]
def myHub = location.hub
List hubProp = ["id","name","data","zigbeeId","zigbeeEui","hardwareID","type","localIP","localSrvPortTCP","firmwareVersionString","uptime"]
for(i=0;i<hubProp.size();i++){
if(hubProp[i] != "data")
updateAttr(hubProp[i], myHub["${hubProp[i]}"])
else if(location.hub.properties.data.zigbeeChannel != null || suppressData == false)
updateAttr(hubProp[i], myHub["${hubProp[i]}"])
else if(location.hub.firmwareVersionString >= "2.2.8.0") {
device.deleteCurrentState("data")
device.deleteCurrentState("zigbeeChannel")
}
}
for(i=0;i<locProp.size();i++){
updateAttr(locProp[i], location["${locProp[i]}"])
}
if(!suppressData || location.hub.properties.data.zigbeeChannel != null)
updateAttr("zigbeeChannel",location.hub.properties.data.zigbeeChannel)
if(location.hub.properties.data.zigbeeChannel != null)
updateAttr("zigbeeStatus", "enabled")
else
updateAttr("zigbeeStatus", "disabled")
formatUptime()
updateAttr("hubVersion", location.hub.firmwareVersionString) //retained for backwards compatibility
updateAttr("locationName", location.name)
updateAttr("locationId", location.id)
updateAttr("hubModel", getModel())
if(updSdfPref == null) device.updateSetting("updSdfPref",[value:"Milliseconds",type:"string"])
if(updSdfPref == "Milliseconds" || updSdfPref == null)
updateAttr("lastUpdated", new Date().getTime())
else {
SimpleDateFormat sdf = new SimpleDateFormat(updSdfPref)
updateAttr("lastUpdated", sdf.format(new Date().getTime()))
}
if (pollingCheck())
checkPolling()
else
updateAttr("nextPoll","None")
if (attribEnable) altHtml()
if(fwUpdatePollRate == null)
device.updateSetting("fwUpdatePollRate",[value:6000,type:"number"])
if(fwUpdatePollRate > 0 ) updateCheck()
}
void updateAttr(String aKey, aValue, String aUnit = ""){
aValue = aValue.toString()
if(aValue.length() > 1024) {
log.error "Attribute value for $aKey exceeds 1024, current size = ${aValue.length()}, truncating to 1024..."
aValue = aValue.substring(0,1023)
}
sendEvent(name:aKey, value:aValue, unit:aUnit)
if(attrLogging) log.info "$aKey : $aValue$aUnit"
}
void formatUptime(){
try {
Long ut = location.hub.uptime.toLong()
Integer days = Math.floor(ut/(3600*24)).toInteger()
Integer hrs = Math.floor((ut - (days * (3600*24))) /3600).toInteger()
Integer min = Math.floor( (ut - ((days * (3600*24)) + (hrs * 3600))) /60).toInteger()
Integer sec = Math.floor(ut - ((days * (3600*24)) + (hrs * 3600) + (min * 60))).toInteger()
if(upTimeSep == null){
device.updateSetting("upTimeSep",[value:",", type:"string"])
upTimeSep = ","
}
String attrval = "${days.toString()}d$upTimeSep${hrs.toString()}h$upTimeSep${min.toString()}m$upTimeSep${sec.toString()}s"
updateAttr("formattedUptime", attrval)
} catch(ignore) {
updateAttr("formattedUptime", "")
}
}
String getModel(){
try{
String model = getHubVersion() // requires >=2.2.8.141
} catch (ignore){
try{
httpGet("http://${location.hub.localIP}:8080/api/hubitat.xml") { res ->
model = res.data.device.modelName
return model
}
} catch(ignore_again) {
return ""
}
}
}
void checkZigStack(){
if(!beta)
return
try{
httpGet("http://127.0.0.1:8080/hub/currentZigbeeStack") { resp ->
if(resp.data.toString().indexOf('standard') > -1)
updateAttr("zigbeeStack","standard")
else
updateAttr("zigbeeStack","new")
}
} catch(ignore) { }
}
boolean isCompatible(Integer minLevel) { //check to see if the hub version meets the minimum requirement
String model = device.currentValue("hubModel",true)
if(!model){
model = getModel()
updateAttr("hubModel", model)
}
String[] tokens = model.split('-')
String revision = tokens.last()
return (Integer.parseInt(revision) >= minLevel)
}
void pollHub2() {
Map params =
[
uri : "http://127.0.0.1:8080",
path : "/hub2/hubData"
]
if(debugEnable)log.debug params
asynchttpGet("getHub2", params)
}
void refresh() {
getPollValues()
}
void getPollValues(){
SimpleDateFormat sdfIn = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy")
sunrise = sdfIn.parse(location.sunrise.toString())
sunset = sdfIn.parse(location.sunset.toString())
if(sunSdfPref == null) device.updateSetting("sunSdfPref",[value:"HH:mm:ss",type:"enum"])
if(sunSdfPref != "Milliseconds") {
SimpleDateFormat sdf = new SimpleDateFormat(sunSdfPref)
updateAttr("sunrise", sdf.format(sunrise))
updateAttr("sunset", sdf.format(sunset))
} else {
updateAttr("sunrise", sunrise.getTime())
updateAttr("sunset", sunset.getTime())
}
String cookie=(String)null
if(security) cookie = getCookie()
if(debugEnable) log.debug "Cookie = $cookie"
// repoll zigbee channel if invalid
if (device.currentValue("zigbeeChannel") == "NA") {
updateAttr("zigbeeChannel",location.hub.properties.data.zigbeeChannel)
}
if(location.hub.properties.data.zigbeeChannel != null)
updateAttr("zigbeeStatus", "enabled")
else
updateAttr("zigbeeStatus", "disabled")
//verify localIP in case of change
updateAttr("localIP", location.hub.localIP)
//Hub Mode & HSM Status
updateAttr("currentMode", location.properties.currentMode)
updateAttr("currentHsmMode", location.hsmStatus)
// Zwave Version
if(checkZwVersion == null && isCompatible(7))
device.updateSetting("checkZwVersion",[value:"true",type:"bool"])
else if(checkZwVersion == null)
device.updateSetting("checkZwVersion",[value:"false",type:"bool"])
if(zwLocked == null) device.updateSetting("zwLocked",[value:"false",type:"bool"])
if(checkZwVersion && isCompatible(7) && !zwLocked){
Map paramZ = [
uri : "http://127.0.0.1:8080",
path : "/hub/zwaveVersion",
headers: ["Cookie": cookie]
]
if (debugEnable) log.debug paramZ
asynchttpGet("getZwave", paramZ)
} else if (checkZwVersion) {
device.updateSetting("checkZwVersion",[value:"false",type:"bool"])
updateAttr("zwaveData",null)
}
//Zwave Status - enabled/disabled & hubAlerts
pollHub2()
// get Temperature
if(tempPollEnable) {
params = [
uri : "http://127.0.0.1:8080",
path : "/hub/advanced/internalTempCelsius",
headers: ["Cookie": cookie]
]
if (debugEnable) log.debug params
asynchttpGet("getTempHandler", params)
}
// get Free Memory
if(freeMemPollEnabled) {
params = [
uri : "http://127.0.0.1:8080",
path : "/hub/advanced/freeOSMemory",
headers: ["Cookie": cookie]
]
if (debugEnable) log.debug params
asynchttpGet("getFreeMemHandler", params)
}
// get Free JVM & CPU
if(cpuPollEnabled) {
if (location.hub.firmwareVersionString <= "2.2.5.131") {
params = [
uri : "http://127.0.0.1:8080",
path : "/hub/advanced/freeOSMemoryHistory",
headers: ["Cookie": cookie]
]
} else {
params = [
uri : "http://127.0.0.1:8080",
path : "/hub/advanced/freeOSMemoryLast",
headers: ["Cookie": cookie]
]
}
if (debugEnable) log.debug params
asynchttpGet("getJvmHandler", params)
}
//Get DB size
if(dbPollEnabled) {
params = [
uri : "http://127.0.0.1:8080",
path : "/hub/advanced/databaseSize",
headers: ["Cookie": cookie]
]
if (debugEnable) log.debug params
asynchttpGet("getDbHandler", params)
}
//get Public IP
if(publicIPEnable) {
params =
[
uri: "https://api.ipify.org?format=json",
headers: [
Accept: "application/json"
]
]
if(debugEnable)log.debug params
asynchttpGet("getIfHandler", params)
}
//Max State Days
if(evtStateDaysEnable) {
params =
[
uri : "http://127.0.0.1:8080",
path : "/hub/advanced/maxDeviceStateAgeDays",
headers: ["Cookie": cookie]
]
if(debugEnable)log.debug params
asynchttpGet("getStateDaysHandler", params)
//Max Event Days
params =
[
uri : "http://127.0.0.1:8080",
path : "/hub/advanced/maxEventAgeDays",
headers: ["Cookie": cookie]
]
if(debugEnable)log.debug params
asynchttpGet("getEvtDaysHandler", params)
}
// NTP Server
if(ntpCkEnable){
params =
[
uri : "http://127.0.0.1:8080",
path : "/hub/advanced/ntpServer",
headers: ["Cookie": cookie]
]
if(debugEnable)log.debug params
asynchttpGet("getNtpServer", params)
}
// Additional Subnets
if(subnetEnable) {
params =
[
uri : "http://127.0.0.1:8080",
path : "/hub/allowSubnets",
headers: ["Cookie": cookie]
]
if(debugEnable)log.debug params
asynchttpGet("getSubnets", params)
}
//HubMesh Data
if(hubMeshPoll) {
params =
[
uri : "http://127.0.0.1:8080",
path : "/hub2/hubMeshJson",
headers: ["Cookie": cookie]
]
if(debugEnable)log.debug params
asynchttpGet("getHubMesh", params)
}
//v2.3.4.126 data
if(location.hub.firmwareVersionString >= "2.3.4.126" && extNetData){
params =
[
uri : "http://127.0.0.1:8080",
path : "/hub2/networkConfiguration",
headers: ["Cookie": cookie]
]
if(debugEnable)log.debug params
asynchttpGet("getNetworkConfig", params)
}
//End Pollable Gets
if(!suppressData || location.hub.properties.data.zigbeeChannel != null)
updateAttr("zigbeeChannel",location.hub.properties.data.zigbeeChannel)
updateAttr("uptime", location.hub.uptime)
formatUptime()
if (attribEnable) altHtml()
if (debugEnable) log.debug "tempPollRate: $tempPollRate"
if(location.hub.firmwareVersionString >= "2.3.3.120") checkZigStack()
if (pollingCheck()) {
if(tempPollRate == null){
device.updateSetting("tempPollRate",[value:300,type:"number"])
runIn(300,"getPollValues")
}else {
runIn(tempPollRate,"getPollValues")
}
}
getNextPoll()
if(updSdfPref == null) device.updateSetting("updSdfPref",[value:"Milliseconds",type:"string"])
if(updSdfPref == "Milliseconds")
updateAttr("lastUpdated", new Date().getTime())
else {
SimpleDateFormat sdf = new SimpleDateFormat(updSdfPref)
updateAttr("lastUpdated", sdf.format(new Date().getTime()))
}
}
@SuppressWarnings('unused')
def getTemp(){ // this is to handle the upgrade path from >= 1.8.x
log.info "Upgrading HubInfo polling from 1.8.x"
unschedule("getTemp")
getPollValues()
}
@SuppressWarnings('unused')
void getTempHandler(resp, data) {
try {
if(resp.getStatus() == 200 || resp.getStatus() == 207) {
Double tempWork = new Double(resp.data.toString())
if(tempWork > 0) {
if(debugEnable) log.debug tempWork
if (location.temperatureScale == "F")
updateAttr("temperature",String.format("%.1f", celsiusToFahrenheit(tempWork)),"°F")
else
updateAttr("temperature",String.format("%.1f",tempWork),"°C")
updateAttr("temperatureF",String.format("%.1f",celsiusToFahrenheit(tempWork))+ " °F")
updateAttr("temperatureC",String.format("%.1f",tempWork)+ " °C")
}
}
} catch(ignored) {
def respStatus = resp.getStatus()
if (!warnSuppress) log.warn "getTemp httpResp = $respStatus but returned invalid data, will retry next cycle"
}
}
@SuppressWarnings('unused')
void getZwave(resp, data) {
try {
if(resp.getStatus() == 200 || resp.getStatus() == 207) {
String zwaveData = resp.data.toString()
if(debugEnable) log.debug resp.data.toString()
if(zwaveData.length() < 1024){
updateAttr("zwaveData",zwaveData)
parseZwave(zwaveData)
device.updateSetting("checkZwVersion",[value:"false",type:"bool"])
}
else if (!warnSuppress) log.warn "Invalid data returned for Zwave, length = ${zwaveData.length()} will retry"
}
} catch(ignored) {
if (!warnSuppress) log.warn "getZwave Parsing Error"
}
}
@SuppressWarnings('unused')
void getFreeMemHandler(resp, data) {
try {
if(resp.getStatus() == 200 || resp.getStatus() == 207) {
Integer memWork = new Integer(resp.data.toString())
if(debugEnable) log.debug memWork
updateAttr("freeMemory",memWork, "KB")
}
} catch(ignored) {
def respStatus = resp.getStatus()
if (!warnSuppress) log.warn "getFreeMem httpResp = $respStatus but returned invalid data, will retry next cycle"
}
}
@SuppressWarnings('unused')
void getJvmHandler(resp, data) {
String jvmWork
List<String> jvmArr = []
try {
if(resp.getStatus() == 200 || resp.getStatus() == 207) {
jvmWork = resp.data.toString()
}
if (attribEnable) runIn(5,"altHtml") //allow for events to register before updating - thebearmay 210308
} catch(ignored) {
def respStatus = resp.getStatus()
if (!warnSuppress) log.warn "getJvm httpResp = $respStatus but returned invalid data, will retry next cycle"
}
if (jvmWork) {
Integer lineCount = 0
jvmWork.eachLine{
lineCount++
}
Integer lineCount2 = 0
jvmWork.eachLine{
lineCount2++
if(lineCount==lineCount2)
jvmArr = it.split(",")
}
if(jvmArr.size() > 1){
if(location.hub.firmwareVersionString <= "2.2.8.0"){
Integer jvmTotal = jvmArr[2].toInteger()
updateAttr("jvmTotal",jvmTotal, "KB")
Integer jvmFree = jvmArr[3].toInteger()
updateAttr("jvmFree",jvmFree, "KB")
Double jvmFreePct = (jvmFree/jvmTotal)*100
updateAttr("jvmFreePct",jvmFreePct.round(1),"%")
if(jvmArr.size() > 4) {
Double cpuWork=jvmArr[4].toDouble()
updateAttr("cpu5Min",cpuWork.round(2))
cpuWork = (cpuWork/4.0D)*100.0D //Load / #Cores - if cores change will need adjusted to reflect
updateAttr("cpuPct",cpuWork.round(2),"%")
}
} else {
Double cpuWork=jvmArr[2].toDouble()
updateAttr("cpu5Min",cpuWork.round(2))
cpuWork = (cpuWork/4.0D)*100.0D //Load / #Cores - if cores change will need adjusted to reflect
updateAttr("cpuPct",cpuWork.round(2),"%")
if(device.currentValue("jvmFree")) {
try { // requires >= 2.2.8.141
device.deleteCurrentState("jvmFree")
device.deleteCurrentState("jvmTotal")
device.deleteCurrentState("jvmFreePct")
} catch (ignore) {
updateAttr("jvmFree","\0")
updateAttr("jvmTotal","\0")
updateAttr("jvmFreePct","\0")
}
}
}
}
}
}
@SuppressWarnings('unused')
void getDbHandler(resp, data) {
try {
if(resp.getStatus() == 200 || resp.getStatus() == 207) {
Integer dbWork = new Integer(resp.data.toString())
if(debugEnable) log.debug dbWork
updateAttr("dbSize",dbWork,"MB")
}
} catch(ignored) {
def respStatus = resp.getStatus()
if (!warnSuppress) log.warn "getDb httpResp = $respStatus but returned invalid data, will retry next cycle"
}
}
@SuppressWarnings('unused')
void getIfHandler(resp, data){
try{
if (resp.getStatus() == 200){
if (debugEnable)
log.debug resp.data
def jSlurp = new JsonSlurper()
Map ipData = (Map)jSlurp.parseText((String)resp.data)
updateAttr("publicIP",ipData.ip)
} else {
if (!warnSuppress) log.warn "Status ${resp.getStatus()} while fetching Public IP"
}
} catch (Exception ex){
if (!warnSuppress) log.warn ex
}
}
@SuppressWarnings('unused')
void getStateDaysHandler(resp, data) {
try {
if(resp.getStatus() == 200 || resp.getStatus() == 207) {
Integer stateDays = new Integer(resp.data.toString())
if(debugEnable) log.debug "Max State Days $stateDays"
updateAttr("maxStateDays",stateDays)
}
} catch(ignored) {
def respStatus = resp.getStatus()
if (!warnSuppress) log.warn "getStateDays httpResp = $respStatus but returned invalid data, will retry next cycle"
}
}
@SuppressWarnings('unused')
void getEvtDaysHandler(resp, data) {
try {
if(resp.getStatus() == 200 || resp.getStatus() == 207) {
Integer evtDays = new Integer(resp.data.toString())
if(debugEnable) log.debug "Max Event Days $evtDays"
updateAttr("maxEvtDays",evtDays)
}
} catch(ignored) {
def respStatus = resp.getStatus()
if (!warnSuppress) log.warn "getEvtDays httpResp = $respStatus but returned invalid data, will retry next cycle"
}
}
@SuppressWarnings('unused')
void getNtpServer(resp, data) {
try {
if (resp.status == 200) {
ntpServer = resp.data.toString()
if(ntpServer == "No value set") ntpServer = "Hub Default(Google)"
updateAttr("ntpServer", ntpServer)
} else {
if(!warnSuppress) log.warn "NTP server check returned status: ${resp.status}"
}
}catch (ignore) {
}
}
@SuppressWarnings('unused')
void getSubnets(resp, data) {
try {
if (resp.status == 200) {
subNets = resp.data.toString()
if(subNets == "Not set") subNets = "Hub Default"
updateAttr("ipSubnetsAllowed", subNets)
} else {
if(!warnSuppress) log.warn "Subnet check returned status: ${resp.status}"
}
}catch (ignore) {
}
}
@SuppressWarnings('unused')
void parseZwave(String zString){
Integer start = zString.indexOf('(')
Integer end = zString.length()
String wrkStr
if(start == -1 || end < 1 || zString.indexOf("starting up") > 0 ){ //empty or invalid string - possibly non-C7
updateAttr("zwaveData",null)
}else {
wrkStr = zString.substring(start,end)
wrkStr = wrkStr.replace("(","[")
wrkStr = wrkStr.replace(")","]")
HashMap zMap = (HashMap)evaluate(wrkStr)
updateAttr("zwaveSDKVersion","${((List)zMap.targetVersions)[0].version}.${((List)zMap.targetVersions)[0].subVersion}")
updateAttr("zwaveVersion","${zMap?.firmware0Version}.${zMap?.firmware0SubVersion}")
}
}
String getUnitFromState(String attrName){
return device.currentState(attrName)?.unit
}
void restartCheck() {
if(debugEnable) log.debug "$rsDate"
Long ut = new Date().getTime().toLong() - (location.hub.uptime.toLong()*1000)
Date upDate = new Date(ut)
if(debugEnable) log.debug "RS: $rsDate UT:$ut upTime Date: $upDate upTime: ${location.hub.uptime}"
updateAttr("lastHubRestart", ut)
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
updateAttr("lastHubRestartFormatted",sdf.format(upDate))
}
@SuppressWarnings('unused')
void getHub2(resp, data){
try{
if (resp.getStatus() == 200){
if (debugEnable) log.debug resp.data