-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiris_utilitech_siren_zwave.groovy
607 lines (473 loc) · 19.5 KB
/
iris_utilitech_siren_zwave.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
/**Iris Utilitech Siren driver hubitat
This is for the Iris Utilitech Siren #0422360 No test done on other models
Designed to detect false alarms and give proper bat suppot and drop out detection.
Device does not support tamper. The tamper button never sends any status.
There are no settings on this device however some EverSpring models have a timeout
setting but im unable to test that.
Presence is used to detect dead batteries.
New timeout timmer that works.
State verification and repair. No more ignoring the OFF commands
------------------------------------------------------------------------------------------------------
Its sometimes hard to get it to pair or repair after removing or resetting.
Remove batteries let it set and try again later.
UNDOCUMENTED HUBITAT Z-WAVE BUG
Go to settings/Z-Wave Details/Z-Wave Radio Devices
Unlike other zwave devices this device gets stuck in this list and the hub gets confused.
GENERIC_TYPE_SWITCH_BINARY Everspring
If its already in zwave list it will never be able to re-pair. Press REPAIR or REFREASH and you will
get a option to REMOVE, Remove it then the hub will now see it as a new device.
I beleive the cause is that normal devices creating a new ID on each pair. Whatever the case the hub does
not know what to do. I think it was said after several reboots it will go away but we need it out now.
---------------------------------------------------------------------------------------------------------
v1.1.0 01/25/2023 Power Up init rewriten
v1.0.9 01/23/2023 Adjustments to timeout
v1.0.8 01/23/2023 Extra battery polling added / Removed dupe on-off signal bug. / Timeout code rewritten
v1.0.7 12/05/2022 State Verify added
v1.0.6 12/04/2022 Bug fixes
v1.0.5 12/03/2022 First working release
v1.0.1 12/01/2022 beta
v1.0.0 10/01/2022 created
* Copyright 2022 by 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.
*
* using zwave commands from this driver. Code rewritten......
* https://github.com/SmartThingsCommunity/SmartThingsPublic/blob/master/devicetypes/smartthings/zwave-siren.src/zwave-siren.groovy
*/
metadata {
definition(name: "Iris Utilitech Siren", namespace: "tmastersmart", author: "tmaster",importUrl: "https://raw.githubusercontent.com/tmastersmart/hubitat-code/main/iris_utilitech_siren_zwave.groovy") {
capability "Actuator"
capability "Alarm"
capability "Sensor"
capability "Switch"
capability "Health Check"
capability "Battery"
capability "Configuration"
capability "Refresh"
capability "Polling"
capability "PresenceSensor"
command "checkPresence"
command "initialize"
command "uninstall"
fingerprint mfr: "0060", prod: "000C", deviceId:"0001", deviceJoinName: "Utilitech Siren" , inClusters:"0x20,0x25,0x86,0x80,0x85,0x72,0x71"
fingerprint mfr: "0060", prod: "000C", model: "0001", deviceJoinName: "Utilitech Siren"
fingerprint mfr: "0060", prod: "000C", model: "0002", deviceJoinName: "Everspring Siren"//Everspring Outdoor Solar Siren
}
}
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: "timeout" ,type: "enum", title: "Timeout Timer",description: "Driver sends off after x seconds 300=5min, 900=10min, 1200=20min, 1800=30min",options: ["300","900","1200","1800"], defaultValue: 1200 ,required: true
input name: "pollYes",type: "bool", title: "Enable Presence", description: "", defaultValue: true,required: true
input name: "pollHR" ,type: "enum", title: "Check Presence Hours",description: "Press config after saving",options: ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20"], defaultValue: 8 ,required: true
}
def clientVersion() {
TheVersion="1.1.0"
if (state.version != TheVersion){
state.version = TheVersion
configure()
}
}
// Runs after first pairing.
def installed() {
logging("Installed ", "warn")
state.DataUpdate = false
pollHR = 10
configure()
updated()
}
// Runs on reboot
def initialize(){
logging("initialize ", "debug")
state.FalseAlarm = 0
clientVersion()
randomSixty = Math.abs(new Random().nextInt() % 180)
runIn(randomSixty,refresh)
}
def uninstall() {
unschedule()
state.icon = ""
state.donate = ""
state.remove("presenceUpdated")
state.remove("version")
state.remove("configured")
state.remove("lastCheckInMin")
state.remove("icon")
state.remove("logo")
state.remove("FalseAlarm")
state.remove("tries")
state.remove("lastPoll")
state.remove("Alarm")
state.remove("fingerprint")
state.remove("lastCheckin")
}
def updated() {
logging("updated","info")
clientVersion()
loggingUpdate()
if (pollYes == false){unschedule(checkPresence)}
}
def configure() {
logging("Config","info")
state.Alarm = false
if(!state.FalseAlarm){state.FalseAlarm = 0}
removeDataValue("manufacturerName")
getIcons()
unschedule(checkPresence)
if (pollYes){
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}/${pollHR} * * ? *", "debug")
schedule("${randomSixty2} ${randomSixty} ${randomTwentyFour}/${pollHR} * * ? *", checkPresence)
logging("Presence Check Every ${pollHR}hrs starting at ${randomTwentyFour}:${randomSixty}:${randomSixty2} ", "info")
}
//Everspring 1,2,3 minutes 1:60, 2:120, 3:180 (untested this is a IRIS driver)
if (zwaveInfo?.mfr == "0060" && zwaveInfo?.prod == "000C" && zwaveInfo?.model == "0002") {// 0001= Utilitech 0002=Everspring
logging("Everspring alarm Length 3 min", "debug")
delayBetween([
secure(zwave.configurationV2.configurationSet(parameterNumber: 1, size: 2, configurationValue: [0,180])),
secure(zwave.configurationV2.configurationGet(parameterNumber: 1)),
zwave.configurationV2.configurationSet(parameterNumber: 1, size: 2, configurationValue: [0,180]).format(),
zwave.configurationV2.configurationGet(parameterNumber: 1).format(),
], 2300)
}
runIn(20,refresh)
}
// Resend the proper state to get back in sync
def sync (){
state.FalseAlarm = state.FalseAlarm +1
if(state.FalseAlarm > 25){
logging("Loss of control. Resync falure. Errors:${state.FalseAlarm}", "warn")
return // prevent a non stop loop
}
logging("Resyncing State. Errors:${state.FalseAlarm}", "warn")
if (state.Alarm== true){ on()}
else {off()}
}
def on() {
logging("Sending On Timeout:${timeout}", "warn")
state.Alarm = true
// "300","900","1200","1800"
if (timeout == 300){ runIn(300,offTimeout)}
else if (timeout == 900){ runIn(900,offTimeout)}
else if (timeout == 1200){ runIn(1200,offTimeout)}
else if (timeout == 1800){ runIn(1800,offTimeout)}
else {runIn(1800,offTimeout)}
delayBetween([
// zwave.basicV1.basicSet(value: 0xFF).format(),
// zwave.switchBinaryV1.switchBinaryGet().format(),
// zwave.basicV1.basicGet().format(),// this just dupes switchbinary
secure(zwave.basicV1.basicSet(value: 0xFF)),
secure(zwave.switchBinaryV1.switchBinaryGet()),
// secure(zwave.basicV1.basicGet())
], 3000)
}
def offOFF(){
off()
}
def offTimeout(){
logging("Timeout reached State:${state.Alarm} Verifying OFF", "info")
off()
}
def off() {
logging("Sending Off", "info")
state.Alarm = false
runIn(10,poll)
runIn(20,batPoll)
runIn(30,poll)
delayBetween([
// zwave.basicV1.basicSet(value: 0x00).format(),
// zwave.switchBinaryV1.switchBinaryGet().format(),
// zwave.basicV1.basicGet().format(),// this just dupes switchbinary
secure(zwave.basicV1.basicSet(value: 0x00)),
secure(zwave.switchBinaryV1.switchBinaryGet())
], 3000)
}
// included for compatability
def siren() {
logging("Sirene", "info")
on()
}
def strobe() {
logging("Strobe", "info")
on()
}
def both() {
logging("Both", "info")
on()
}
def batPoll(){
logging("Poll-Bat", "info")
zwave.batteryV1.batteryGet().format()
}
// -------------------------------------------------
def poll() {
logging("Poll", "info")
// zwave.basicV1.basicGet().format()
zwave.switchBinaryV1.switchBinaryGet().format()
}
def ping() {
logging("Ping", "info")
// zwave.basicV1.basicGet().format()
zwave.switchBinaryV1.switchBinaryGet().format()
}
def refresh() {
clientVersion()
def nowCal = Calendar.getInstance(location.timeZone)
Timecheck = "${nowCal.getTime().format("EEE MM/dd/YYYY", location.timeZone)}"
logging("Refresh ${Timecheck} v${state.version}", "info")
delayBetween([
// zwave.configurationV2.configurationGet().format(),
zwave.manufacturerSpecificV2.manufacturerSpecificGet().format(),// fingerprint
// zwave.basicV1.basicGet().format(),// this just dupes switchbinary
zwave.batteryV1.batteryGet().format(),
zwave.switchBinaryV1.switchBinaryGet().format(),
], 3000)
}
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 = 2800
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)
return // we dont want a ping after this or it could toggle
}
}
runIn(2,ping)
runIn(20,batPoll)
if (state.tries <4){
logging("Recovery in process Last checkin ${state.lastCheckInMin} min ago ","warn")
runIn(50,checkPresence)
}
}
}
def parse(String description) {
def nowCal = Calendar.getInstance(location.timeZone)
state.lastCheckin = now()
logging("Raw [${description}]", "trace")
checkPresence()
hubitat.zwave.Command map = zwave.parse(description, getCommandClassVersions())
if (map) {
logging("Parse ${map}", "trace")
zwaveEvent(map)
}else{logging("Parse failed", "warn")}
}
/**
* getCommandClassVersions()
*
* Returns a map of the command class versions supported by the device. Used by parse() and zwaveEvent() to
* extract encapsulated commands from MultiChannelCmdEncap, MultiInstanceCmdEncap, SecurityMessageEncapsulation,
* and Crc16Encap messages.
*
* Reference: http://products.z-wavealliance.org/products/629/classes
**/
private getCommandClassVersions() {
return [
0x20: 1, // Basic V1
0x22: 1, // Application Status V1 (Not advertised but still sent)
0x25: 1, // Switch Binary V1
0x27: 1, // Switch All V1
0x30: 1, // ?
0x32: 3, // Meter V3
0x56: 1, // CRC16 Encapsulation V1
0x70: 1, // Configuration V1
0x71: 1, // Alarm (Notification) V1
0x72: 2, // Manufacturer Specific V2
0x75: 2, // Protection V2
0x80: 1, // Battery v1
0x84: 2, // ?
0x85: 2, // Association V2
0x86: 1, // Version V1
0x87: 1, // Indicator V1
0x9C: 1 // Alarm Sensor
]
}
//The siren supports Z-Wave™ Command Classes including:
// * COMMAND_CLASS_BASIC
// * COMMAND_CLASS_VERSION
// * COMMAND_CLASS_BATTERY
// * COMMAND_CLASS_MANUFACTURER_SPECIFIC
// * COMMAND_CLASS_SWITCH_BINARY
// * COMMAND_CLASS_ASSOCIATION_V2
private secure(hubitat.zwave.Command cmd) {
if (zwaveInfo?.zw?.contains("s")) {
zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format()
} else {
cmd.format()
}
}
def zwaveEvent(hubitat.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) {
def encapsulatedCommand
logging("${device} : encapsulated:: ${encapsulatedCommand}", "debug")
if (encapsulatedCommand) {
zwaveEvent(encapsulatedCommand)
}
}
void readSwitch (cmd){
if (cmd == 0){ value="off"}
if (cmd == 255){value="on"}
if (value == "on" || value=="off"){
logging("State:${value} [Ours:${state.Alarm}]", "info")
sendEvent(name: "switch", value: value, descriptionText: " v${state.version}", isStateChange:true)
sendEvent(name: "alarm", value: value, descriptionText: " v${state.version}", isStateChange:true)
sendEvent(name: "strobe", value: value, descriptionText: " v${state.version}", isStateChange:true)
// Error recovery
if (value == "on" && state.Alarm == false){sync()}
if (value == "off" && state.Alarm == true ){sync()}
if (value == "off" && state.Alarm == false){// stop the auto off timmer
unschedule(offTimeout)
state.FalseAlarm = 0
}
if (value == "on" && state.Alarm == true){state.FalseAlarm = 0}
}
}
// SwitchBinaryReport(value:0) (only when we request status )
def zwaveEvent(hubitat.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd) {
logging("${cmd}", "debug")
readSwitch(cmd.value)
}
// zwaveEvent( COMMAND_CLASS_BASIC (0x20) v1 ) (normaly reports here)
def zwaveEvent(hubitat.zwave.commands.basicv1.BasicReport cmd) {
logging("${cmd}", "debug")
readSwitch(cmd.value)
}
/**
* zwaveEvent( COMMAND_CLASS_BATTERY V1 (0x80) : BATTERY_REPORT (0x03) )
*
*
* Example: BatteryReport(batteryLevel: 52)
**/
def zwaveEvent(hubitat.zwave.commands.batteryv1.BatteryReport cmd) {
logging("${cmd}", "debug")
if (cmd.batteryLevel == 0xFF) {
logging("Low battery FLAG FF", "warn")
return
}
if (cmd.batteryLevel == 0) {
logging("Ignoring false bat 0 ", "debug")
return
}
state.LastBat = device.currentValue("battery")
logging("battery: ${cmd.batteryLevel} ", "info")
if (state.LastBat != cmd.batteryLevel ){
sendEvent(name: "battery", value: cmd.batteryLevel,unit: "%", descriptionText: "${cmd.batteryLevel} ${state.LastCheckin} v${state.version}", isStateChange:true)
}
}
/**
* zwaveEvent( COMMAND_CLASS_MANUFACTURER_SPECIFIC V2 (0x72) : MANUFACTURER_SPECIFIC_REPORT (0x05) )
*
* Manufacturer-Specific Reports are used to advertise manufacturer-specific information, such as product number
* and serial number.
**/
def zwaveEvent(hubitat.zwave.commands.manufacturerspecificv2.ManufacturerSpecificReport cmd) {
logging("${cmd} ", "debug")
// does not send name in text
def map = [:]
map.mfr = hubitat.helper.HexUtils.integerToHexString(cmd.manufacturerId, 2)
map.model = hubitat.helper.HexUtils.integerToHexString(cmd.productId, 2)
map.type = hubitat.helper.HexUtils.integerToHexString(cmd.productTypeId, 2)
state.fingerprint = "${map.mfr}-${map.type}-${map.model}"
logging("fingerprint ${state.fingerprint}", "debug")
updateDataValue("manufacturer","Iris Utilitech")
updateDataValue("manufacturerId","${cmd.manufacturerId}")
updateDataValue("deviceType","${cmd.productTypeId}")
updateDataValue("model","TSE07-1")
updateDataValue("deviceId","${cmd.productId}")
}
/**
* zwaveEvent( COMMAND_CLASS_ALARM (0x71) : ALARM_REPORT (0x05) )
*
* The Alarm Report command used to report the type and level of an alarm.
*
* cmd attributes:
* Short alarmLevel Application specific
* Short alarmType Application specific
**/
def zwaveEvent(hubitat.zwave.commands.alarmv1.AlarmReport cmd) {
logging("${cmd} ", "debug")
logging("Alarm Level:${cmd.alarmLevel} Type:${cmd.alarmType}", "info")
if (cmd.alarmLevel == 0 && cmd.alarmType==0){
logging("Clear", "info")
return
}
if (cmd.alarmLevel == 1 && cmd.alarmType==2){
logging("Powering Up OK", "warn")
return
}
// Way to many false alarms here (unusable) Just log for now
if (cmd.alarmLevel == 1 && cmd.alarmType==1){
logging("Battery Low", "warn")
return
}
logging("Unknown Alarm", "warn")
}
def zwaveEvent(hubitat.zwave.Command cmd) {
logging("${cmd} ", "debug")
}
void getIcons(){
state.icon ="<a href='https://github.com/tmastersmart/hubitat-code/blob/main/docs/UT_IndoorSiren_IM%208-2%20ENG-101512.pdf'><img src='https://raw.githubusercontent.com/tmastersmart/hubitat-code/main/images/utilitech-siren.jpg'>Manual</a>"
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>"
}
// 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"}
}