-
Notifications
You must be signed in to change notification settings - Fork 1
/
iris-v1-button.grovvy
778 lines (599 loc) · 28.6 KB
/
iris-v1-button.grovvy
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
/* Iris v1 Button
Iris v1 Button for hubitat
support for scripts
---------------------------------------------
supports press held and held longer
event: pushed
1 = pressed
2 = held (release at light on)
3 = held longer (release after light out)
event: held
1
2
event:doubletapped
1
3
event: button
released
pushed
---------------------------------------------
Supports tamper with options to clear tamper
or ignore tamper for broken cases.
https://fccid.io/WJHB12
WJH-B12, WJH B12, WJHB12, WJHBI2
Centrica Connected home Limited Wireless Button B12
AlertMe Iris Lowes
v1.2.2 03/25/2023 low bat setting added
v1.2.1 11/29/2022 Ranging adj
v1.2.0 11/16/2022 Added doubleTapped for hold longer, script compatability
v1.1.2 11/14/2022 First release Using current contact sensor code
=================================================================================================
Before going back to internal drivers you must use uninstall to stop chron
===================================================================================================
Copyright [2022] [tmaster winnfreenet.com]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
May contain code from the following
Iris v2 source code driver here 2.3 driver
https://github.com/arcus-smart-home/arcusplatform/blob/a02ad0e9274896806b7d0108ee3644396f3780ad/platform/arcus-containers/driver-services/src/main/resources/ZB_AlertMe_ContactSensor_2_3.driver
https://github.com/arcus-smart-home/arcusplatform/blob/a02ad0e9274896806b7d0108ee3644396f3780ad/common/arcus-protocol/src/main/irp/ame-general.irp
code includes some routines based on alertme UK code from
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.
Uk Iris code
https://github.com/birdslikewires/hubitat/blob/master/alertme/drivers/alertme_contact.groovy
*
*/
def clientVersion() {
TheVersion="1.2.2"
if (state.version != TheVersion){
logging("Upgrading ! ${state.version} to ${TheVersion}", "warn")
state.version = TheVersion
configure()
}
}
import hubitat.zigbee.clusters.iaszone.ZoneStatus
import hubitat.helper.HexUtils
metadata {
definition (name: "Iris v1 Button", namespace: "tmastersmart", author: "Tmaster", importUrl: "https://raw.githubusercontent.com/tmastersmart/hubitat-code/main/iris-v1-button.grovvy") {
capability "Battery"
capability "Configuration"
capability "Initialize"
capability "PresenceSensor"
capability "Refresh"
capability "Sensor"
capability "SignalStrength"
capability "TamperAlert"
capability "TemperatureMeasurement"
capability "Pushable Button"
capability "ReleasableButton"
capability "Holdable Button"
command "checkPresence"
command "normalMode"
command "rangeAndRefresh"
command "ClearTamper"
command "unschedule"
command "uninstall"
attribute "batteryVoltage", "string"
attribute "mode", "string"
fingerprint model:"Button Device", manufacturer:"AlertMe.com", profileId:"C216", endpointId:"02", inClusters:"00F0,00F3,00F2,00F1", 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: "tamperIgnore", type: "bool", title: "Ignore the Tamper alarm", defaultValue: false
input name: "minVoff",type: "enum", title: "Min Voltage",description: "Using minVoltTest set the min voltage your sensor will run on. minVolt test will be set when battery runs down", options: ["1.1","1.2","1.3","1.4","1.5","1.6","1.7","1.8","1.9","2","2.10","2.11","2.12","2.13","2.14","2.15","2.16","2.17","2.18","2.19","2.2","2.21","2.22","2.23","2.24","2.25","2.26","2.27","2.28","2.29"], defaultValue: "2.21" ,required: true
input name: "tempAdj",type:"enum", title: "Temperature Offset",description: "", options: ["-10","-9.8","-9.6","-9.4","-9.2","-9.0","-8.8","-8.6","-8.4","-8.2","-8.0","-7.8",
"-7.6","-7.4","-7.2","-7.0","-6.8","-6.6","-6.4","-6.2","-6.0","-5.8","-5.6","-5.4","-5.2","-5.0","-4.8",
"-4.6","-4.4","-4.2","-4.0","-3.8","-3.6","-3.4","-3.2","-3.0","-2.8","-2.6","-2.4","-2.2","-2.0","-1.8","-1.6","-1.4","-1.2","-1.0","-0.8","-0.6","-0.4","-0.2","0",
"0.2","0.4","0.6","0.8","1.0","1.2","1.4","1.6","1.8","2.0","2.2","2.4","2.6","2.8","3.0","3.2","3.4","3.6","3.8","4.0","4.2","4.4","4.6","4.8","5.0","5.2","5.4","5.6","5.8",
"6.0","6.2","6.4","6.6","6.8","7.0","7.2","7.4","7.6","7.8","8.0","8.2","8.4","8.6","8.8","9.0","9.2","9.4","9.6","9.8","10"], defaultValue: "0",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("batteryOkay"),
state.remove("battery"),
state.remove("LQI"),
state.remove("batteryOkay"),
state.remove("Config"),
state.remove("batteryState"),
state.remove("reportToDev"),
state.remove("tries"),
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)
// Works better with a delay. Some were not getting removed
}
def initialize() {
// Set states to starting values and schedule a single refresh.
// Runs on reboot, or can be triggered manually.
// Reset states...
state.presenceUpdated = 0
state.rangingPulses = 0
state.lastPress =0
// Remove state variables from old versions.
state.remove("operatingMode")
state.remove("LQI")
// Remove unnecessary device details.
removeDataValue("application")
if(!option1){sendEvent(name: "powerSource", value: "battery")}
clientVersion()
// multi devices will run this on reboot make sure they all use a diffrent time
randomSixty = Math.abs(new Random().nextInt() % 3500)
runIn(randomSixty,refresh)
logging("Initialised", "info")
}
def configure() {
// Set preferences and ongoing scheduled tasks.
// Runs after installed() when a device is paired or rejoined, or can be triggered manually.
state.model = "-model?-"
// Remove state variables from old versions.
state.remove("operatingMode")
state.remove("LQI")
state.remove("batteryOkay")
state.remove("batteryState")
state.remove("Config")
state.remove("presenceUpdated")
state.remove("hwVer")
state.remove("reportToDev")
getIcons()
unschedule()
// Schedule randon ranging in hrs
randomSixty = Math.abs(new Random().nextInt() % 60)
randomTwentyFour = Math.abs(new Random().nextInt() % 24)
schedule("${randomSixty} ${randomSixty} ${randomTwentyFour}/${5} * * ? *", rangeAndRefresh)
// Check presence every hr
randomSixty = Math.abs(new Random().nextInt() % 60)
randomTwentyFour = Math.abs(new Random().nextInt() % 24)
schedule("${randomSixty} ${randomSixty} ${randomTwentyFour}/${1} * * ? *", checkPresence)
// Schedule presence check in mins
// int checkEveryMinutes = 20
// randomSixty = Math.abs(new Random().nextInt() % 60)
// schedule("${randomSixty} 0/${checkEveryMinutes} * * * ? *", checkPresence)
// Run a ranging report and then switch to normal operating mode.
// Randomise so we dont get several running at the same time
runIn(randomSixty,rangeAndRefresh)
logging("configure", "info")
}
def updated() {
// Runs whenever preferences are saved.
clientVersion()
loggingUpdate()
refresh()
}
// useless mode shuts down the device? Unknown
// ranging message every 2 minutes.
//void offMode() {
// sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x00F0 {11 00 FA 03 01} {0xC216}"])// shut off device
// logging ("Mode: Quiet [FA:03.01]","info")
//}
def normalMode() {
// This is the standard running mode.
delayBetween([ // Once is not enough
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
], 3000)
logging("SendMode: [Normal] Pulses:${state.rangingPulses}", "info")
}
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
}
def ping(){
logging("Ping", "info")
sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x00F6 {11 00 FC 01} {0xC216}"])// version information request
}
void refresh() {
logging("Refreshing ${state.model} v${state.version}", "info")
sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x00F6 {11 00 FC 01} {0xC216}"])// version information request
}
// 3 seconds mains 6 battery 2 flash good 3 bad
def rangeAndRefresh() {
// we dont want to range if its not pressent we want to recover first
test = device.currentValue("presence")
if (test == "not present" ){
ping()
return
}
logging("StartMode : [Ranging]", "info")
sendZigbeeCommands(["he raw ${device.deviceNetworkId} 0 ${device.endpointId} 0x00F0 {11 00 FA 01 01} {0xC216}"]) // ranging
state.rangingPulses = 0
runIn(6, normalMode)
}
def checkPresence() {
// presence routine. v5.1 11-12-22
// simulated 0% battery detection
if(!state.tries){state.tries = 0}
state.lastPoll = new Date().format('MM/dd/yyyy h:mm a',location.timeZone)
def checkMin = 20
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)
sendEvent(name: "battery", value: 0, unit: "%",descriptionText:"Simulated ${state.version}", isStateChange: true)
state.minVoltTest = device.currentValue("batteryVoltage")
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 ClearTamper (){
logging("Tamper : Cleared FORCED", "info")
sendEvent(name: "tamper", value: "clear", isStateChange: true, descriptionText: "force cleared v${state.version}")
}
// process zonealarm as button
def processStatus(ZoneStatus status) {
logging("ZoneStatus Alarm1:${status.isAlarm1Set()} Alarm2:${status.isAlarm2Set()} ", "debug")
}
void doubleTap(cmd){
logging("doubleTapped: ${cmd}", "info")
sendEvent(name: "doubleTapped", value: cmd, descriptionText: "${cmd} button doubleTapped! ${state.version}",translatable: true,isStateChange: true)
}
// this is for compatability
def hold(cmd){
logging("held: ${cmd}", "info")
sendEvent(name: "held", value: cmd, descriptionText: "${cmd} button held! ${state.version}",translatable: true,isStateChange: true)
}
def released(cmd)
{
logging("Button: released ", "info")
sendEvent(name: "button", value: "released", descriptionText: "${cmd} button released! ${state.version}",translatable: true,isStateChange: true)
release(cmd)
}
def release(cmd)
{
logging("released ${cmd}", "info")
sendEvent(name: "released", value: cmd, isStateChange: true,descriptionText:"${cmd} button Pressed! ${state.version}",data: [buttonNumber: cmd])
}
def push(cmd){
logging("pushed ${cmd}", "info")
sendEvent(name: "pushed", value: cmd, isStateChange: true,descriptionText:"${cmd} button Pressed! ${state.version}",data: [buttonNumber: cmd])
}
def parse(String description) {
logging("Parse : ${description}", "trace")
clientVersion()
state.lastCheckin = now()
checkPresence()
// Device contacts are zigbee cluster compatable
if (description.startsWith("zone status")) {
ZoneStatus zoneStatus = zigbee.parseZoneStatus(description)
processStatus(zoneStatus)
return
}else 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
//profileId:C216, clusterId:00F3, clusterInt:243, sourceEndpoint:02, destinationEndpoint:02, options:0040, messageType:00, dni:97F5,
//isClusterSpecific:true, isManufacturerSpecific:false, manufacturerId:0000, command:01, direction:01, data:[00, 01, 51, 14, 00, 00]]/
//profileId:C216, clusterId:00F3, clusterInt:243, sourceEndpoint:02, destinationEndpoint:02, options:0040, messageType:00, dni:97F5,
// isClusterSpecific:true, isManufacturerSpecific:false, manufacturerId:0000, command:00, direction:01, data:[00, 02, 05, 15, 00, 00]]
if (map.clusterId == "00F3"){ // button cluster
timeSinceLastCheckin = (now() - state.lastPress ?: 0) / 100
logging("PRESS command:${map.command} map:${receivedData} ${timeSinceLastCheckin}", "debug")
if (map.command == "01") {state.lastPress = now()} // wait for released to check for holding
if (map.command == "00") {
if(timeSinceLastCheckin >=10){// how many seconds to hold
push(3)
doubleTap(1)
doubleTap(3)
released(3)
return
}
if(timeSinceLastCheckin >=6.5){// how many seconds to hold
push(2)
hold(1)
hold(2)
released(2)
return
}
push(1)
released(1)
}
}else if (map.clusterId == "00F0") {
if (map.command == "FB") {
// Device status cluster.
def temperatureValue = "NA"
def batteryVoltageHex = "NA"
BigDecimal batteryVoltage = 0
batteryVoltageHex = receivedData[5..6].reverse().join()
temperatureValue = receivedData[7..8].reverse().join()
// some sensors report bat and temp at diffrent times some both at once?
if (batteryVoltageHex != "FFFF") {
batteryVoltageRaw = zigbee.convertHexToInt(batteryVoltageHex) / 1000
batteryVoltage = batteryVoltageRaw.setScale(2, BigDecimal.ROUND_HALF_UP) // changed to x.xx from x.xxx
BigDecimal batteryPercentage = 0
BigDecimal batteryVoltageScaleMin = 2.18
BigDecimal batteryVoltageScaleMax = 3.00 // 3.2 new battery
// last hub update makes it impossible to do math on states and numbers from settings
// What used to work no longer does. You can no longer save a number then pull it back and do math.
// I gave up and created this Kludge for the bug. This is longer but safer
if (minVoff == "1.1"){batteryVoltageScaleMin = 1.1 }
if (minVoff == "1.2"){batteryVoltageScaleMin = 1.2 }
if (minVoff == "1.3"){batteryVoltageScaleMin = 1.3 }
if (minVoff == "1.4"){batteryVoltageScaleMin = 1.4 }
if (minVoff == "1.5"){batteryVoltageScaleMin = 1.5 }
if (minVoff == "1.6"){batteryVoltageScaleMin = 1.6 }
if (minVoff == "1.7"){batteryVoltageScaleMin = 1.7 }
if (minVoff == "1.8"){batteryVoltageScaleMin = 1.8 }
if (minVoff == "1.9"){batteryVoltageScaleMin = 1.9 }
if (minVoff == "2") {batteryVoltageScaleMin = 2 }
if (minVoff == "2.10"){batteryVoltageScaleMin = 2.10 }
if (minVoff == "2.11"){batteryVoltageScaleMin = 2.11 }
if (minVoff == "2.12"){batteryVoltageScaleMin = 2.12 }
if (minVoff == "2.13"){batteryVoltageScaleMin = 2.13 }
if (minVoff == "2.14"){batteryVoltageScaleMin = 2.14 }
if (minVoff == "2.15"){batteryVoltageScaleMin = 2.15 }
if (minVoff == "2.16"){batteryVoltageScaleMin = 2.16 }
if (minVoff == "2.17"){batteryVoltageScaleMin = 2.17 }
if (minVoff == "2.18"){batteryVoltageScaleMin = 2.18 }
if (minVoff == "2.19"){batteryVoltageScaleMin = 2.19 }
if (minVoff == "2.2") {batteryVoltageScaleMin = 2.2 }
if (minVoff == "2.21"){batteryVoltageScaleMin = 2.21 }
if (minVoff == "2.22"){batteryVoltageScaleMin = 2.22 }
if (minVoff == "2.23"){batteryVoltageScaleMin = 2.23 }
if (minVoff == "2.24"){batteryVoltageScaleMin = 2.24 }
if (minVoff == "2.25"){batteryVoltageScaleMin = 2.25 }
if (minVoff == "2.26"){batteryVoltageScaleMin = 2.26 }
if (minVoff == "2.27"){batteryVoltageScaleMin = 2.27 }
if (minVoff == "2.28"){batteryVoltageScaleMin = 2.28 }
if (minVoff == "2.29"){batteryVoltageScaleMin = 2.29 }
batteryPercentage = ((batteryVoltage - batteryVoltageScaleMin) / (batteryVoltageScaleMax - batteryVoltageScaleMin)) * 100.0
batteryPercentage = batteryPercentage.setScale(0, BigDecimal.ROUND_HALF_UP)
batteryPercentage = batteryPercentage > 100 ? 100 : batteryPercentage
powerLast = device.currentValue("battery")
logging("battery: now:${batteryPercentage}% Last:${powerLast}% ${batteryVoltage}V", "debug")
if (powerLast != batteryPercentage){
sendEvent(name: "battery", value:batteryPercentage, unit: "%")
sendEvent(name: "batteryVoltage", value: batteryVoltage, unit: "V", descriptionText: "Volts:${batteryVoltage}V MinVolts:${batteryVoltageScaleMin} v${state.version}")
logging("Battery:${batteryPercentage}% ${batteryVoltage}V", "info")
} // end dupe events detection
}// end battery report
if (temperatureValue != "0000") {
// We get false temp readings of 0000 so ignore for now.
// When getting a false reading bat is not FFFF
// This is not true for all sensors. So more work needed.Cannot cast object '38.9840' with class 'java.lang.String' to class 'float' on line 522 (method parse)
if(!tempAdj){tempAdj = 0}
BigDecimal temperatureCelsius = hexToBigDecimal(temperatureValue) / 16
temperatureF = (temperatureCelsius * 9/5) + 32// fixed from UK code use F
temperatureU = temperatureF
def correctNum = (tempAdj ?: 0.0).toBigDecimal()
if (correctNum != 0){ temperatureF = temperatureF + correctNum }
tempLast = device.currentValue("temperature")
logging("temperature: Now:${temperatureF}°F Last:${tempLast}°F adjust:${correctNum} [Sensor:${temperatureU}°F ${temperatureCelsius}°C]", "debug")
if (tempLast != temperatureF){
logging("temperature: Now:${temperatureF}°F Last:${tempLast}°F adjust:${correctNum} [Sensor:${temperatureU}°F ${temperatureCelsius}°C]", "info")
sendEvent(name: "temperature", value: temperatureF, unit: "F", isStateChange: true, descriptionText: "Sensor:${temperatureU} adjust:${correctNum} v${state.version}")
}// end dupe events detection
}// end temp
}// end FB
} // end cluster 00F0
else if (map.clusterId == "00F2") {// Tamper cluster.
logging("Tamper : Cluster [${map.command} ${receivedData[0]}]", "debug")
if (map.command == "00" || receivedData[0] == "02") {
if(tamperIgnore){logging("Tamper : ignored", "debug")}
else{
logging("Tamper : Detected", "warn")
sendEvent(name: "tamper", value: "detected", isStateChange: true, descriptionText: "tamper detected v${state.version}")
}
}
if (map.command == "01" || receivedData[0] == "01") {
logging("Tamper : Cleared", "info")
sendEvent(name: "tamper", value: "clear", isStateChange: true, descriptionText: "tamper clear v${state.version}")
}
}
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 > 6) {
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") {// Hello Response 0xF6 0xFE
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)
// appVerHex = receivedData[15]
// def appVerDec = Integer.parseInt(appVerHex,16)
// appVer = new Double(appVerDec) /10
// hwVer = new Double(receivedData[17]) + (new Double(receivedData[16]) / 10)
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"
String deviceModel = ""
//Unknown firmware [appV.appRel.hwV-40.6.257-date-2012-02-03] 2012-02-03
reportFirm = "unknown"
if(deviceFirmwareDate == "2012-02-03" ){reportFirm = "Ok"}
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
// Moved to debug because of to many events
logging("Ident:${deviceModel} Firm:[${firmwareVersion}] ${reportFirm} Driver v${state.version}", "debug")
if(!state.Config){
state.Config = true
updateDataValue("manufacturer", deviceManufacturer)
updateDataValue("device", deviceModel)
updateDataValue("model", "BTN900")
updateDataValue("firmware", firmwareVersion)
updateDataValue("fcc", "WJHB12")
}
}
// 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("send Zigbee :${cmds}", "trace")
sendHubCommand(new hubitat.device.HubMultiAction(cmds, hubitat.device.Protocol.ZIGBEE))
}
private BigDecimal hexToBigDecimal(String hex) {
int d = Integer.parseInt(hex, 16) << 21 >> 21
return BigDecimal.valueOf(d)
}
void getIcons(){
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/irisv1button.jpg' >"
}
// Logging block v4
void loggingUpdate() {
logging("Logging Info:[${infoLogging}] Debug:[${debugLogging}] Trace:[${traceLogging}]", "infoBypass")
// Only do this when its needed
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 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"}
}