-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiris_alertme_smartplug.groovy
749 lines (614 loc) · 27.9 KB
/
iris_alertme_smartplug.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
/* Iris v1 Smart Plug custom
Hubitat iris smart plug driver with siren and strobe comands
AlertMe USA version smart plug
Centrica Connected home Limited Wireless Smartplug SP11
___ _ _ ____ _ ____ _
|_ _|_ __(_)___ __ _/ | / ___| _ __ ___ __ _ _ __| |_ | _ \| |_ _ __ _
| || '__| / __| \ \ / / | \___ \| '_ ` _ \ / _` | '__| __| | |_) | | | | |/ _` |
| || | | \__ \ \ V /| | ___) | | | | | | (_| | | | |_ | __/| | |_| | (_| |
|___|_| |_|___/ \_/ |_| |____/|_| |_| |_|\__,_|_| \__| |_| |_|\__,_|\__, |
|___/
USA version model# SPG800 FCC ID WJHSP11
====================================================================================
v4.2.4 04/21/2023 Ranging added after power recovery
v4.2.3 03/15/2023
v4.2.2 03/01/2023 Added missing isStateChange to On/Off events.
v4.2.1 12/05/2022 Was not Refreshing after ranging
v4.2.0 11/29/2022 control loss increased ranging.
v4.1.0 11/15/2022 Bug fix in refreash and on off control
v4.0.2 11/12/2022 Bug fix presence
v4.0 11/11/2022 Bug fix on presence. Improvements from other iris drivers added
v3.9.1 11/06/2022 Logos added. Bug fix on config delay. operating Mode human form
v3.9 10/30/2022 Bug fix in presence routine
v3.8 10/11/2022 Energy usage moved to debug from info
v3.7 09/21/2022 Adjustments to ranging
v3.6 09/19/2022 Rewrote logging routines. Block code changes copied from keypad code
Rewrote presence and ranging routines.
v3.5 09/06/2022 Init routine delayed. minor fixes
v3.4 09/04/2022 Updating standard routines for all my drivers. Schedules now optional
Better error detection and less logs
v3.3 08/29/0222 Power Report bug fix
v3.1 05/02/2022 Init mode cleanup
v3.0 04/28/2022 Added Un Schedule
v2.9 04/23/2022 Added mains detection
Wattage events only created if diffrent than last reading
stoped recording voltage to many events
v2.8 10/19/2021 Ranging bug fixes
v2.7 10/15/2021 Operating state logging changed.
v2.6 10/05/2021 Icon added
v2.5 09/20/2021 Merging in code from my KepPad driver. Better error handeling and logging
v2.4 09-14-2021 Some log fixes and cleanup
v2.3 09-14-2021 Added alarm support
v2.1 09/03/2011 unknown commands logging, Battery reporting removed.
v2.0 08/05/2021 Cleanup on logging power states removal of unneeded info
v1.8.2 08/04/2021 Better logging on energy total cleanup
v1.7 05/16/2021
v1.0 04/11/2021 Release
https://github.com/tmastersmart/hubitat-code/blob/main/iris_alertme_smartplug.groovy
https://github.com/tmastersmart/hubitat-code/raw/main/iris_alertme_smartplug.groovy
tested on:
firmware: 2012-09-20 OK
firmware: 2013-09-26 OK
Hold down button while plugging in to factory reset. Should start double flashing
Energy is total since start
Power is current watts
Battery USA model has no battery but still reports internal power at 12 volts.
* based on alertme UK code from
https://github.com/birdslikewires/hubitat
GNU General Public License v3.0
Permissions of this strong copyleft license are conditioned on making available
complete source code of licensed works and modifications, which include larger
works using a licensed work, under the same license. Copyright and license
notices must be preserved. Contributors provide an express grant of patent rights.
*
*/
def clientVersion() {
TheVersion="4.2.4"
if (state.version != TheVersion){
logging("Upgrading ! ${state.version} to ${TheVersion}", "warn")
state.version = TheVersion
configure()
}
}
metadata {
definition (name: "Iris v1 Smart Plug custom", namespace: "tmastersmart", author: "Tmaster", importUrl: "https://raw.githubusercontent.com/tmastersmart/hubitat-code/main/iris_alertme_smartplug.groovy") {
capability "Actuator"
capability "Configuration"
capability "EnergyMeter"
capability "Initialize"
capability "Outlet"
capability "PowerMeter"
capability "PresenceSensor"
capability "Refresh"
capability "SignalStrength"
capability "Switch"
capability "Alarm"
// capability "Power Source"
command "normalMode"
command "rangeAndRefresh"
command "unschedule"
command "uninstall"
attribute "strobe", "string"
attribute "siren", "string"
// attribute "Voltage", "string"
attribute "power", "string"
fingerprint profileId: "C216", inClusters: "00F0,00EF,00EE", outClusters: "", manufacturer: "AlertMe", model: "SmartPlug2.5", deviceJoinName: "Iris SmartPlug v2.5"
}
}
//*fingerprint model:"SmartPlug2.5", manufacturer:"AlertMe", profileId:"C216", endpointId:"02", inClusters:"00F0,00EF,00EE", outClusters:""
preferences {
input name: "infoLogging", type: "bool", title: "Enable info logging", description: "Recomended low level" ,defaultValue: true,required: true
input name: "debugLogging", type: "bool", title: "Enable debug logging", description: "MED level Debug" ,defaultValue: false,required: true
input name: "traceLogging", type: "bool", title: "Enable trace logging", description: "Insane HIGH level", defaultValue: false,required: true
input name: "autoSync", type: "bool", title: "AutoSync to hub state", description: "Disables local button on relays, Recovery from powerfalure, Keeps relay in sync with digital state. ChildGuard outlets.", defaultValue: false,required: true
input name: "resendState", type: "bool", title: "Resend Last State on Refresh", description: "For problem devices that dont wake up or dont reply to commands.", defaultValue: false,required: true
input name: "pollHR" , type: "enum", title: "Check Presence Hours",description: "Chron Schedule. Press config after saving",options: ["1","2","3","4"], defaultValue: "1",required: true
input name: "disableLogsOff",type: "bool", title: "Disable Auto Logs off", description: "For debugging doesnt auto disable", defaultValue: false,required: true
}
def installed() {
logging("Paired!", "info")
initialize()
configure()
}
def uninstall() {
delayBetween([
unschedule(),
state.icon = "",
state.donate = "",
state.remove("presenceUpdated"),
state.remove("version"),
state.remove("checkPhase"),
state.remove("lastCheckInMin"),
state.remove("icon"),
state.remove("logo"),
state.remove("DataUpdate"),
state.remove("lastCheckin"),
state.remove("lastPoll"),
state.remove("donate"),
state.remove("model"),
state.remove("MFR"),
state.remove("poll"),
state.remove("ping"),
state.remove("tempAdj"),
state.remove("rangingPulses"),
state.remove("operatingMode"),
state.remove("operatingModeCode"),
state.remove("batteryOkay"),
state.remove("battery"),
state.remove("LQI"),
state.remove("batteryOkay"),
state.remove("Config"),
state.remove("batteryState"),
removeDataValue("battery"),
removeDataValue("battertState"),
removeDataValue("batteryVoltage"),
removeDataValue("contact"),
removeDataValue("lqi"),
removeDataValue("operation"),
removeDataValue("presence"),
removeDataValue("tamper") ,
removeDataValue("temperature"),
logging("Uninstalled - States removed you may now switch drivers", "info") ,
], 200)
}
def initialize() {
// This runs on reboot
state.operatingMode = "normal"
state.presenceUpdated = 0
state.rangingPulses = 0
// Remove disused state variables from earlier versions.
state.remove("powerWithUnit")
state.remove("energyWithUnit")
state.remove("logo")
state.remove("relayClosed")
state.remove("battery")
state.remove("batteryVoltage")
state.remove("powerSource")
state.remove("pendingChanges")
state.remove("operatingMode")
state.remove("power")
state.remove("operation")
// Remove unnecessary device details.
device.deleteCurrentState("alarm")
device.deleteCurrentState("alarmcmd")
device.deleteCurrentState("VoltageWithUnit")
device.deleteCurrentState("lqi")
clientVersion()
// multi devices will run this on reboot make sure they all use a diffrent time
randomSixty = Math.abs(new Random().nextInt() % 180)
// runIn(randomSixty,refresh)
// It needs ranging on recovery from power falure or it may not respond for hrs
runIn(randomSixty,rangeAndRefresh)
}
def configure() {
// Runs on reboot paired or rejoined
state.DataUpdate = false
state.remove("operatingModeCode")
getIcons()
unschedule()
// Schedule randon ranging in hrs
randomSixty = Math.abs(new Random().nextInt() % 60)
randomSixty2 = Math.abs(new Random().nextInt() % 60)
randomTwentyFour = Math.abs(new Random().nextInt() % 24)
schedule("${randomSixty2} ${randomSixty} ${randomTwentyFour}/${5} * * ? *", rangeAndRefresh)
logging("RangeAndRefreash Every 5hrs starting at ${randomTwentyFour}:${randomSixty}:${randomSixty2} ", "info")
// Check presence in hrs
if (!pollHR){ pollHR= 1}
state.poll = pollHR
randomSixty = Math.abs(new Random().nextInt() % 60)
randomSixty2 = Math.abs(new Random().nextInt() % 60)
randomTwentyFour = Math.abs(new Random().nextInt() % 24)
logging("CHRON: ${randomSixty2} ${randomSixty} ${randomTwentyFour}/${state.poll} * * ? *", "debug")
schedule("${randomSixty2} ${randomSixty} ${randomTwentyFour}/${state.poll} * * ? *", checkPresence)
logging("Presence Check Every ${state.poll}hrs starting at ${randomTwentyFour}:${randomSixty}:${randomSixty2} ", "info")
// rangeAndRefresh()
runIn(randomSixty,rangeAndRefresh)
logging("configure", "info")
}
def updated() {
// Runs whenever preferences are saved.
clientVersion()
loggingUpdate()
refresh()
}
// // Turns off all reporting except for a ranging message every 2 minutes.
// sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x00F0 {11 00 FA 03 01} {0xC216}"]),
def normalMode() { // v2.0
logging("Sending: [Normal Mode] Pulses:${state.rangingPulses}", "info")
sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x00F0 {11 00 FA 00 01} {0xC216}"])// normal
if (state.rangingPulses >15){
logging("Not responding! adding extra kick", "warn")
delayBetween([ // Once is not enough
// sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x00F6 {11 00 FC 01} {0xC216}"]),// version information request
sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x00F0 {11 00 FA 00 01} {0xC216}"]),// normal
sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x00F0 {11 00 FA 00 01} {0xC216}"]),// normal
sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x00F0 {11 00 FA 00 01} {0xC216}"]),// normal
sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x00F0 {11 00 FA 00 01} {0xC216}"]),// normal
sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x00F0 {11 00 FA 00 01} {0xC216}"]),// normal
sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x00F0 {11 00 FA 00 01} {0xC216}"]),// normal
], 6000)
}
}
void EnrollRequest(){
logging("Responding to Enroll Request. Likely Battery Change", "warn")
delayBetween([ // Once is not enough
sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x0500 {11 80 00 00 05} {0xC216}"]),//enrole
sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x0500 {11 80 00 00 05} {0xC216}"]),//enrole
], 3000)
}
void MatchDescriptorRequest (){
logging("Match Descriptor Request. Sending Reply","info")
sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x8006 {00 00 00 01 02} {0xC216}"])//match des
}
void ping() {
refresh()
}
void refresh() {
logging("${device} : Refreshing", "info")
delayBetween([
sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x00F6 {11 00 FC 01} {0xC216}"]),// get version info
sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x00EE {11 00 01 01} {0xC216}"]),// get power info
], 3000)
}
// 3 seconds mains 6 battery 2 flash good 3 bad
def rangeAndRefresh() {
logging("StartMode : [Ranging]", "info")
sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x00F0 {11 00 FA 01 01} {0xC216}"]) // ranging
state.rangingPulses = 0
runIn(3,normalMode)
runIn(10,refresh)
}
// Resend the proper state to get back in sync
def sync (){
if(autoSync == false){return}
if (!state.error){state.error = 0}
state.error = state.error +1
if(state.error > 12){
logging("Loss of control. Resync falure. Errors:${state.error}", "warn")
return // prevent a non stop loop
}
logging("Resyncing State. Errors:${state.error}", "warn")
if (state.switch== true){ runIn(4,on)}
else {runIn(4,off)}
}
def siren(cmd){
state.alarmcmd = 1
sendEvent(name: "siren", value: "on")
on()
}
def strobe(cmd){
state.alarmcmd = 2
sendEvent(name: "strobe", value: "on")
on()
}
def both(cmd){
state.alarmcmd = 3
sendEvent(name: "siren", value: "on")
sendEvent(name: "strobe", value: "on")
on()
}
def off() {
state.switch = false
state.alarmcmd = 0
sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x00EE {11 00 02 00 01} {0xC216}"])
}
def on() {
state.switch = true
state.alarmcmd = 0
sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x00EE {11 00 02 01 01} {0xC216}"])
}
def checkPresence() {
// presence routine. v5 11-12-22
if(!state.tries){state.tries = 0}
state.lastPoll = new Date().format('MM/dd/yyyy h:mm a',location.timeZone)
def checkMin = 60
def timeSinceLastCheckin = (now() - state.lastCheckin ?: 0) / 1000
def theCheckInterval = (checkInterval ? checkInterval as int : 2) * 60
state.lastCheckInMin = timeSinceLastCheckin/60
logging("Check Presence its been ${state.lastCheckInMin} mins Timeout:${checkMin} Tries:${state.tries}","debug")
if (state.lastCheckInMin <= checkMin){
state.tries = 0
test = device.currentValue("presence")
if (test != "present"){
value = "present"
logging("Creating presence event: ${value} ","info")
sendEvent(name:"presence",value: value , descriptionText:"${value} ${state.version}", isStateChange: true)
return
}
}
if (state.lastCheckInMin >= checkMin) {
state.tries = state.tries + 1
if (state.tries >=5){
test = device.currentValue("presence")
if (test != "not present" ){
value = "not present"
logging("Creating presence event: ${value}","warn")
sendEvent(name:"presence",value: value , descriptionText:"${value} ${state.version}", isStateChange: true)
return // we dont want a ping after this or it could toggle
}
}
runIn(2,ping)
if (state.tries <4){
logging("Recovery in process Last checkin ${state.lastCheckInMin} min ago ","warn")
runIn(50,checkPresence)
}
}
}
def parse(String description) {
logging("Parse : ${description}", "trace")
clientVersion()
state.lastCheckin = now()
checkPresence()
loggingCheck()
if (description?.startsWith('enroll request')) {
EnrollRequest()
return
}
// processMap clusterId:00F0 command:FB [1F, 7C, 63, 16, 00, 3C, 0C, 90, 01, CF, FF, 03, 00] 13
// new processing routine
Map map = zigbee.parseDescriptionAsMap(description)
if (!map){
logging("Failed to parse", "debug")
return
}
String[] receivedData = map.data
size = receivedData.size()// size of data field
logging("${map}", "trace")// full parsed data
logging("Map clusterId:${map.clusterId} command:${map.command} map:${receivedData}", "debug")// all iris valid data
if (map.clusterId == "00EE") {
if (map.command == "80") { //State:00EE command:80 data:[07, 01]
state.operatingMode = Integer.parseInt(receivedData[0],16)
operatingModeCode = receivedData[0]
onOff = receivedData[1]
current = device.currentValue("switch")
currentSiren = device.currentValue("siren")
currentStrobe = device.currentValue("strobe")
logging("State: mode:${state.operatingMode} On/Off:${onOff} [${map.data}]", "debug")
if (onOff == "00" || operatingModeCode =="06" ) {
if (current == "on"){
sendEvent(name: "switch", value: "off",descriptionText: "${state.uptime} V${state.version}",isStateChange: true)
if (currentSiren != "off"){sendEvent(name: "siren", value: "off")}
if (currentStrobe != "off"){sendEvent(name: "strobe", value: "off")}
logging("Switch : OFF ", "info")
}
else {logging("Switch :OFF Our state:${current}", "info")}
}
if (onOff == "01" || operatingModeCode =="07") {
if (current != "on"){
if(state.alarmcmd == 1){
sendEvent(name: "siren", value: "on")
logging("Sirene Alarm : ON", "info")
}
if(state.alarmcmd == 2){
sendEvent(name: "strobe", value: "on")
logging("Strobe Alarm : ON", "info")
}
if(state.alarmcmd == 3 ){
sendEvent(name: "strobe", value: "on")
sendEvent(name: "siren", value: "on")
logging("Siren-Strobe Alarm : ON", "info")
}
sendEvent(name: "switch", value: "on",descriptionText: "${state.uptime} V${state.version}",isStateChange: true)
logging("Switch : ON", "info")
}
else {logging("Switch :ON Our state:${current}", "info")}
}
// 0E power up in off
// 0F Power up in ON
// 0D on
// 0C off
// 06 and 07 are on off
// give up on mode it doesnt follow the chart all the time
}
}
// 0x00EF (239) Power Monitor Cluster
// These power readings are so frequent that we need to slow them down
// We need to only save on change.
else if (map.clusterId == "00EF") {
logging("Power:${map.clusterId} :${map.command} :${map.data}", "debug")
// RQST_PWR_REPORT = 03
// INST_PWR_REPORT = 81
// TOTAL_ENERGY_REPORT = 82
if (map.command == "81") {
def powerValueHex = "undefined"
int powerValue = 0
powerValueHex = receivedData[0..1].reverse().join()
powerValue = zigbee.convertHexToInt(powerValueHex)
if(powerValue < 0){powerValue =0 }
logging("Power: now:${powerValue}W Last:${state.power}W", "debug")
if (powerValue != state.power){
logging("Current Power: ${powerValue} Watts", "info")
sendEvent(name: "power", value: powerValue, unit: "W",descriptionText: "${state.uptime} V${state.version}")
state.power = powerValue
}
} else if (map.command == "82") {
// Command 82 returns energy summary in watt-hours with an uptime counter.
// Energy
String energyValueHex = "undefined"
energyValueHex = receivedData[0..3].reverse().join()
BigInteger energyValue = new BigInteger(energyValueHex, 16)
BigDecimal energyValueDecimal = BigDecimal.valueOf(energyValue / 3600 / 1000)
energyValueDecimal = energyValueDecimal.setScale(4, BigDecimal.ROUND_HALF_UP)
if (energyValueDecimal != state.energy){
logging("Total Energy Usage: ${energyValueDecimal}kWh", "debug")
sendEvent(name: "energy", value: energyValueDecimal, unit: "kWh",descriptionText: "${state.uptime} V${state.version}" )
state.energy = energyValueDecimal
}
// Uptime
// This reports every min.
String uptimeValueHex = "undefined"
uptimeValueHex = receivedData[4..8].reverse().join()
BigInteger uptimeValue = new BigInteger(uptimeValueHex, 16)
def newDhmsUptime = []
newDhmsUptime = millisToDhms(uptimeValue * 1000)
String uptimeReadable = "${newDhmsUptime[3]}d ${newDhmsUptime[2]}h ${newDhmsUptime[1]}m"
logging("Uptime : ${uptimeReadable} ${uptimeValue}", "debug")
state.uptime = uptimeReadable
}
} else if (map.clusterId == "00F0") {
// if bit 0 battery voltage
// if bit 1 temp
// if bit 3 lqi
// bit 5 and 6 reversed
// bit 7 and 8 reversed
// LQI = 10 (lqi * 100.0) / 255.0
def temp = 0
def batteryVoltageHex = "NA"
BigDecimal batteryVoltage = 0
batteryVoltageHex = receivedData[5..6].reverse().join()
// temp = receivedData[7..8].reverse().join()
// BigDecimal temperatureCelsius = hexToBigDecimal(temp) / 16
// temp = (temperatureCelsius * 9/5) + 32// fixed from UK code use F
// Voltage:12.81V Temp:-8c Temp17.6 (logging temp data may not be a real value)
if (batteryVoltageHex != "FFFF") {
batteryVoltageRaw = zigbee.convertHexToInt(batteryVoltageHex) / 1000
batteryVoltage = batteryVoltageRaw.setScale(2, BigDecimal.ROUND_HALF_UP)
// powerLast = device.currentValue("Voltage")
// if(powerLast != batteryVoltage){
// sendEvent(name: "Voltage", value: batteryVoltage, unit: "V", descriptionText: "Volts:${batteryVoltage}V Temp:${temperatureCelsius}c v${state.version}")
// logging("Voltage:${batteryVoltage}V", "info")
// }
logging("Voltage:${batteryVoltage}V", "debug")
}
}else if (map.clusterId == "00F6") {// Join Cluster 0xF6
// Ranging
if (map.command == "FD") { // LQI
def lqiHex = "na"
lqiHex = receivedData[0]
int lqiRanging = 0
lqiRanging = zigbee.convertHexToInt(lqiHex)
lqiLast = device.currentValue("lqi")
if(lqiRanging != lqiLast){
sendEvent(name: "lqi", value: lqiRanging)
logging("LQI: ${lqiRanging}", "info")
}
if (receivedData[1] == "77" || receivedData[1] == "FF") { // Ranging running in a loop
state.rangingPulses++
logging("Ranging ${state.rangingPulses}", "debug")
if (state.rangingPulses > 14) {
normalMode()
return
}
} else if (receivedData[1] == "00") { // Ranging during a reboot
// when the device reboots.(keypad) Must answer
logging("reboot ranging report received", "info")
refresh()
return
}
// End ranging block
} else if (map.command == "FE") {
// Device version response.
def versionInfoHex = receivedData[31..receivedData.size() - 1].join()
StringBuilder str = new StringBuilder()
for (int i = 0; i < versionInfoHex.length(); i+=2) {
str.append((char) Integer.parseInt(versionInfoHex.substring(i, i + 2), 16))
}
String versionInfo = str.toString()
String[] versionInfoBlocks = versionInfo.split("\\s")
int versionInfoBlockCount = versionInfoBlocks.size()
String versionInfoDump = versionInfoBlocks[0..versionInfoBlockCount - 1].toString()
// taken from iris source code
mfgIdhex = receivedData[11] + receivedData[10]
def mfgIddec = Integer.parseInt(mfgIdhex,16)
dvcType = receivedData[13] + receivedData[12]
def appRel = Integer.parseInt(receivedData[14],16)
def appVer = Integer.parseInt(receivedData[15],16)
hwVerHex = receivedData[17] + receivedData[16]
def hwVer = Integer.parseInt(hwVerHex,16)
String deviceFirmwareDate = versionInfoBlocks[versionInfoBlockCount - 1]
firmwareVersion = "appV.appRel.hwV-" +appVer + "." + appRel + "." + hwVer+"-date-" + deviceFirmwareDate
logging("Ident Block: ${versionInfoDump} ${firmwareVersion}", "trace")
state.firmware = appVer + "." + appRel + "." + hwVer
String deviceManufacturer = "Iris/AlertMe/Centrica"
String deviceModel = ""
String deviceFirmware = versionInfoBlocks[versionInfoBlockCount - 1]
reportFirm = "Report to DEV"
if(deviceFirmware == "2012-09-20" ){reportFirm = "Known v2012"}
if(deviceFirmware == "2013-09-26" ){reportFirm = "Known v2013"}
if(reportFirm == "unknown"){state.reportToDev="Unknown firmware [${firmwareVersion}] ${deviceFirmwareDate}" }
else{state.remove("reportToDev")}
// Sometimes the model name contains spaces.
if (versionInfoBlockCount == 2) {
deviceModel = versionInfoBlocks[0]
} else {deviceModel = versionInfoBlocks[0..versionInfoBlockCount - 2].join(' ').toString()}
state.model = deviceModel
logging("Ident:${deviceModel} Firm:[${firmwareVersion}] ${reportFirm} Driver v${state.version}", "debug")
if(!state.DataUpdate){
state.DataUpdate = true
updateDataValue("manufacturer", deviceManufacturer)
updateDataValue("device", deviceModel)
updateDataValue("model", "SPG800")
updateDataValue("firmware", firmwareVersion)
updateDataValue("fcc", "WJHSP11")
updateDataValue("partno", "SP11")
}
}
/// Standard IRIS USA Cluster detection block v4
} else if (map.clusterId == "8038") {
logging("${map.clusterId} Seen before but unknown", "debug")
} else if (map.clusterId == "8001" ) {
logging("${map.clusterId} Routing and Neighbour Information", "info")
} else if (map.clusterId == "8032" ) {
logging("${map.clusterId} New join has triggered a routing table reshuffle.", "info")
} else if (map.clusterId == "0006") {MatchDescriptorRequest()
} else if (map.clusterId == "0013" ) {
logging("${map.clusterId} Re-routeing", "warn")
} else {logging("New unknown Cluster Detected: ${map}", "warn")}// report to dev improved
}
void sendZigbeeCommands(List<String> cmds) {
logging("sending:${cmds}", "trace")
sendHubCommand(new hubitat.device.HubMultiAction(cmds, hubitat.device.Protocol.ZIGBEE))
}
// used only by uptime readable.
private String[] millisToDhms(BigInteger millisToParse) {
BigInteger secondsToParse = millisToParse / 1000
def dhms = []
dhms.add(secondsToParse % 60)
secondsToParse = secondsToParse / 60
dhms.add(secondsToParse % 60)
secondsToParse = secondsToParse / 60
dhms.add(secondsToParse % 24)
secondsToParse = secondsToParse / 24
dhms.add(secondsToParse % 365)
return dhms
}
private BigDecimal hexToBigDecimal(String hex) {
int d = Integer.parseInt(hex, 16) << 21 >> 21
return BigDecimal.valueOf(d)
}
void getIcons(){
state.remove("logo")
state.donate="<a href='https://www.paypal.com/paypalme/tmastersat?locale.x=en_US'><img src='https://raw.githubusercontent.com/tmastersmart/hubitat-code/main/images/paypal2.gif'></a>"
state.icon ="<img src='https://raw.githubusercontent.com/tmastersmart/hubitat-code/main/images/iris-v1-smartplug.jpg' >"
}
// Logging block v5
void loggingUpdate() {
logging("Logging Info:[${infoLogging}] Debug:[${debugLogging}] Trace:[${traceLogging}]", "infoBypass")
if (debugLogging){
logging("Debug log:off in 3000s", "warn")
runIn(3000,debugLogOff)
}
if (traceLogging){
logging("Trace log: off in 1800s", "warn")
runIn(1800,traceLogOff)
}
}
void loggingCheck(){
// not working fix later
}
void traceLogOff(){
device.updateSetting("traceLogging",[value:"false",type:"bool"])
log.trace "${device} : Trace Logging : Automatically Disabled"
}
void debugLogOff(){
device.updateSetting("debugLogging",[value:"false",type:"bool"])
log.debug "${device} : Debug Logging : Automatically Disabled"
}
private logging(String message, String level) {
if (level == "infoBypass"){log.info "${device} : $message"}
if (level == "error"){ log.error "${device} : $message"}
if (level == "warn") { log.warn "${device} : $message"}
if (level == "trace" && traceLogging) {log.trace "${device} : $message"}
if (level == "debug" && debugLogging) {log.debug "${device} : $message"}
if (level == "info" && infoLogging) {log.info "${device} : $message"}
}