-
Notifications
You must be signed in to change notification settings - Fork 47
/
Z-Wave Schlage Touchscreen Lock.groovy
1290 lines (1182 loc) · 43.9 KB
/
Z-Wave Schlage Touchscreen Lock.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
/**
*
* INSTRUCTIONS: If you scroll down a couple pages, you should find a line that looks like:
* main "toggle"
* and that followed by a line that STARTS with:
* details(["toggle",
* If you want to change the items that are available on the details page of the device (from 'things'),
* you should edit the "details" line to include whatever items you want to see (along with the order
* you want to see them in.) There's a sample "details" line commented out (starts with //) below the
* first one. That sample enables all (or mostly all) the possible items.
*
* After the first time you have the device type installed (or after you've changed it), you might have
* to forcibly terminate the mobile app before the new/changed stuff will show up. (Most mobile apps
* don't actually terminate when you exit them. How to terminate an app depends on your mobile OS.)
*
* If a toggle is showing up as "loading..." on the UI (and you haven't recently changed it), tap the
* tile and it should reload the status within 10 seconds.
*
* 2015-03-07 : When the lock is locked/unlocked automatically, from the keypad, or manually, include that
* information in the map.data, usedCode. (0 for keypad, "manual" for manually, and "auto" for automatic)
* 2015-02-02 : changed state values to prevent UI confusion. (Previously, when setting one item to 'unknown',
* the UI might show ALL the items as 'unknown'.) Also added beeper toggle.
*
* This is a modification of work originally copyrighted by "SmartThings." All modifications to their work
* is released under the following terms:
*
* The original licensing applies, with the following exceptions:
* 1. These modifications may NOT be used without freely distributing all these modifications freely
* and without limitation, in source form. The distribution may be met with a link to source code
* with these modifications.
* 2. These modifications may NOT be used, directly or indirectly, for the purpose of any type of
* monetary gain. These modifications may not be used in a larger entity which is being sold,
* leased, or anything other than freely given.
* 3. To clarify 1 and 2 above, if you use these modifications, it must be a free project, and
* available to anyone with "no strings attached." (You may require a free registration on
* a free website or portal in order to distribute the modifications.)
* 4. The above listed exceptions to the original licensing do not apply to the holder of the
* copyright of the original work. The original copyright holder can use the modifications
* to hopefully improve their original work. In that event, this author transfers all claim
* and ownership of the modifications to "SmartThings."
*
* Original Copyright information:
*
* Copyright 2014 SmartThings
*
* 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.
*
*/
metadata
{
// Automatically generated. Make future change here.
definition (name: "Z-Wave Schlage Touchscreen Lock", namespace: "garyd9", author: "Gary D")
{
capability "Actuator"
capability "Lock"
capability "Polling"
capability "Refresh"
capability "Sensor"
capability "Lock Codes"
capability "Battery"
attribute "beeperMode", "string"
attribute "vacationMode", "string" // "on", "off", "unknown"
attribute "lockLeave", "string" // "on", "off", "unknown"
attribute "alarmMode", "string" // "unknown", "Off", "Alert", "Tamper", "Kick"
attribute "alarmSensitivity", "number" // 0 is unknown, otherwise 1-5 scaled to 1-99
attribute "localControl", "string" // "on", "off", "unknown"
attribute "autoLock", "string" // "on", "off", "unknown"
attribute "pinLength", "number"
command "unlockwtimeout"
command "setBeeperMode"
command "setVacationMode"
command "setLockLeave"
command "setAlarmMode"
command "setAlarmSensitivity"
command "setLocalControl"
command "setAutoLock"
command "setPinLength"
fingerprint deviceId: "0x4003", inClusters: "0x98"
fingerprint deviceId: "0x4004", inClusters: "0x98"
}
simulator {
status "locked": "command: 9881, payload: 00 62 03 FF 00 00 FE FE"
status "unlocked": "command: 9881, payload: 00 62 03 00 00 00 FE FE"
reply "9881006201FF,delay 4200,9881006202": "command: 9881, payload: 00 62 03 FF 00 00 FE FE"
reply "988100620100,delay 4200,9881006202": "command: 9881, payload: 00 62 03 00 00 00 FE FE"
}
tiles {
standardTile("toggle", "device.lock", width: 2, height: 2)
{
state "locked", label:'locked', action:"lock.unlock", icon:"st.locks.lock.locked", backgroundColor:"#79b821", nextState:"unlocking"
state "unlocked", label:'unlocked', action:"lock.lock", icon:"st.locks.lock.unlocked", backgroundColor:"#ffffff", nextState:"locking"
state "unknown", label:"unknown", action:"lock.lock", icon:"st.locks.lock.unknown", backgroundColor:"#ffffff", nextState:"locking"
state "locking", label:'locking', icon:"st.locks.lock.locked", backgroundColor:"#79b821"
state "unlocking", label:'unlocking', icon:"st.locks.lock.unlocked", backgroundColor:"#ffffff"
}
standardTile("lock", "device.lock", inactiveLabel: false, decoration: "flat")
{
state "default", label:'lock', action:"lock.lock", icon:"st.locks.lock.locked", nextState:"locking"
}
standardTile("unlock", "device.lock", inactiveLabel: false, decoration: "flat")
{
state "default", label:'unlock', action:"lock.unlock", icon:"st.locks.lock.unlocked", nextState:"unlocking"
}
valueTile("battery", "device.battery", inactiveLabel: false, decoration: "flat")
{
state "battery", label:'${currentValue}% battery', unit:""
}
standardTile("refresh", "device.lock", inactiveLabel: false, decoration: "flat")
{
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
}
standardTile("alarmMode", "device.alarmMode", inactiveLabel: true, canChangeIcon: false)
{
state "unknown_alarmMode", label: 'Alarm Mode\nLoading...', icon:"st.unknown.unknown.unknown", action:"setAlarmMode", nextState:"unknown_alarmMode"
state "Off_alarmMode", label: 'Alarm: Off', icon:"st.alarm.beep.beep", action:"setAlarmMode", nextState:"unknown_alarmMode"
state "Alert_alarmMode", label: 'Alert Alarm', icon:"st.alarm.beep.beep", action:"setAlarmMode", backgroundColor:"#79b821", nextState:"unknown_alarmMode"
state "Tamper_alarmMode", label: 'Tamper Alarm', icon:"st.alarm.beep.beep", action:"setAlarmMode", backgroundColor:"#79b821", nextState:"unknown_alarmMode"
state "Kick_alarmMode", label: 'Kick Alarm', icon:"st.alarm.beep.beep", action:"setAlarmMode", backgroundColor:"#79b821", nextState:"unknown_alarmMode"
}
controlTile("alarmSensitivity", "device.alarmSensitivity", "slider", height: 1, width: 2, inactiveLabel: false)
{
state "alarmSensitivity", label:'Sensitivity', action:"setAlarmSensitivity", backgroundColor:"#ff0000"
}
standardTile("autoLock", "device.autoLock", inactiveLabel: true, canChangeIcon: false)
{
state "unknown_autoLock", label: 'Auto Lock\nLoading...', icon:"st.unknown.unknown.unknown", action:"setAutoLock", nextState:"unknown_autoLock"
state "off_autoLock", label: 'Auto Lock', icon:"st.presence.house.unlocked", action:"setAutoLock", nextState:"unknown_autoLock"
state "on_autoLock", label: 'Auto Lock', icon:"st.presence.house.secured", action:"setAutoLock", backgroundColor:"#79b821", nextState:"unknown_autoLock"
}
// not included in details
standardTile("vacationMode", "device.vacationMode", inactiveLabel: true, canChangeIcon: false)
{
state "unknown_vacationMode", label: 'Vacation\nLoading...', icon:"st.unknown.unknown.unknown", action:"setVacationMode", nextState:"unknown_vacationMode"
state "off_vacationMode", label: 'Vacation', icon:"st.Health & Wellness.health2", action:"setVacationMode", nextState:"unknown_vacationMode"
state "on_vacationMode", label: 'Vacation', icon:"st.Health & Wellness.health2", action:"setVacationMode", backgroundColor:"#79b821", nextState:"unknown_vacationMode"
}
// not included in details
standardTile("lockLeave", "device.lockLeave", inactiveLabel: true, canChangeIcon: false)
{
state "unknown_lockLeave", label: 'Lock & Leave\nLoading...', icon:"st.unknown.unknown.unknown", action:"setLockLeave", nextState:"unknown_lockLeave"
state "off_lockLeave", label: 'Lock & Leave', icon:"st.Health & Wellness.health12", action:"setLockLeave", nextState:"unknown_lockLeave"
state "on_lockLeave", label: 'Lock & Leave', icon:"st.Health & Wellness.health12", action:"setLockLeave", backgroundColor:"#79b821", nextState:"unknown_lockLeave"
}
// not included in details
standardTile("localControl", "device.localControl", inactiveLabel: true, canChangeIcon: false)
{
state "unknown_localControl", label: 'Local Ctrl\nLoading...', icon:"st.unknown.unknown.unknown", action:"setLocalControl", nextState:"unknown_localControl"
state "off_localControl", label: 'Local Ctrl', icon:"st.Home.home3", action:"setLocalControl", nextState:"unknown_localControl"
state "on_localControl", label: 'Local Ctrl', icon:"st.Home.home3", action:"setLocalControl", backgroundColor:"#79b821", nextState:"unknown_localControl"
}
// not included in details
standardTile("beeperMode", "device.beeperMode", inactiveLabel: true, canChangeIcon: false)
{
state "unknown_beeperMode", label: 'Beeper\nLoading...', icon:"st.unknown.unknown.unknown", action:"setBeeperMode", nextState:"unknown_beeperMode"
state "off_beeperMode", label: 'Beeper', icon:"st.unknown.unknown.unknown", action:"setBeeperMode", nextState:"unknown_beeperMode"
state "on_beeperMode", label: 'Beeper', icon:"st.unknown.unknown.unknown", action:"setBeeperMode", backgroundColor:"#79b821", nextState:"unknown_beeperMode"
}
main "toggle"
details(["toggle", "lock", "unlock", "alarmMode", "alarmSensitivity", "battery", "autoLock", "lockLeave", "refresh"])
// details(["toggle", "lock", "unlock", "alarmMode", "alarmSensitivity", "battery", "autoLock", "lockLeave", "vacationMode", "beeperMode", "refresh"])
}
}
import physicalgraph.zwave.commands.doorlockv1.*
import physicalgraph.zwave.commands.usercodev1.*
def parse(String description)
{
def result = null
if (description.startsWith("Err"))
{
if (state.sec)
{
result = createEvent(descriptionText:description, displayed:false)
}
else
{
result = createEvent(
descriptionText: "This lock failed to complete the network security key exchange. If you are unable to control it via SmartThings, you must remove it from your network and add it again.",
eventType: "ALERT",
name: "secureInclusion",
value: "failed",
displayed: true)
}
}
else
{
def cmd = zwave.parse(description, [ 0x98: 1, 0x72: 2, 0x85: 2 ])
if (cmd)
{
result = zwaveEvent(cmd)
}
}
log.debug "\"$description\" parsed to ${result.inspect()}"
result
}
def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityMessageEncapsulation cmd)
{
def encapsulatedCommand = cmd.encapsulatedCommand([0x62: 1, 0x71: 2, 0x80: 1, 0x85: 2, 0x63: 1, 0x98: 1])
// log.debug "encapsulated: $encapsulatedCommand"
if (encapsulatedCommand)
{
zwaveEvent(encapsulatedCommand)
}
}
def zwaveEvent(physicalgraph.zwave.commands.securityv1.NetworkKeyVerify cmd)
{
createEvent(name:"secureInclusion", value:"success", descriptionText:"Secure inclusion was successful")
}
def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityCommandsSupportedReport cmd)
{
state.sec = cmd.commandClassSupport.collect { String.format("%02X ", it) }.join()
if (cmd.commandClassControl)
{
state.secCon = cmd.commandClassControl.collect { String.format("%02X ", it) }.join()
}
log.debug "Security command classes: $state.sec"
createEvent(name:"secureInclusion", value:"success", descriptionText:"Lock is securely included")
}
def zwaveEvent(DoorLockOperationReport cmd)
{
def result = []
def map = [ name: "lock" ]
if (cmd.doorLockMode == 0xFF)
{
map.value = "locked"
}
else if (cmd.doorLockMode >= 0x40)
{
map.value = "unknown"
}
else if (cmd.doorLockMode & 1)
{
map.value = "unlocked with timeout"
}
else
{
map.value = "unlocked"
if (state.assoc != zwaveHubNodeId)
{
log.debug "setting association"
result << response(secure(zwave.associationV1.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId)))
result << response(zwave.associationV1.associationSet(groupingIdentifier:2, nodeId:zwaveHubNodeId))
result << response(secure(zwave.associationV1.associationGet(groupingIdentifier:1)))
}
}
result ? [createEvent(map), *result] : createEvent(map)
}
/* 0x71 */
def zwaveEvent(physicalgraph.zwave.commands.alarmv2.AlarmReport cmd)
{
def result = []
def map = null
if (cmd.zwaveAlarmType == physicalgraph.zwave.commands.alarmv2.AlarmReport.ZWAVE_ALARM_TYPE_ACCESS_CONTROL) /* 0x06 */
{
if (1 <= cmd.zwaveAlarmEvent && cmd.zwaveAlarmEvent < 10)
{
map = [ name: "lock", value: (cmd.zwaveAlarmEvent & 1) ? "locked" : "unlocked" ]
}
switch(cmd.zwaveAlarmEvent)
{
case 1:
map.descriptionText = "$device.displayName was manually locked"
map.data = [ usedCode: "manual" ]
break
case 2:
map.descriptionText = "$device.displayName was manually unlocked"
map.data = [ usedCode: "manual" ]
break
case 5:
if (cmd.eventParameter)
{
map.descriptionText = "$device.displayName was locked with code ${cmd.eventParameter.first()}"
map.data = [ usedCode: cmd.eventParameter[0] ]
}
else
{
map.descriptionText = "$device.displayName was locked with keypad"
map.data = [ usedCode: 0 ]
}
break
case 6:
if (cmd.eventParameter)
{
map.descriptionText = "$device.displayName was unlocked with code ${cmd.eventParameter.first()}"
map.data = [ usedCode: cmd.eventParameter[0] ]
}
else
{
map.descriptionText = "$device.displayName was unlocked with keypad"
map.data = [ usedCode: 0 ]
}
break
case 9:
map.descriptionText = "$device.displayName was autolocked"
map.data = [ usedCode: "auto" ]
break
case 7:
case 8:
case 0xA:
map = [ name: "lock", value: "unknown", descriptionText: "$device.displayName was not locked fully" ]
break
case 0xB:
map = [ name: "lock", value: "unknown", descriptionText: "$device.displayName is jammed", eventType: "ALERT", displayed: true ]
break
case 0xC:
map = [ name: "codeChanged", value: "all", descriptionText: "$device.displayName: all user codes deleted", displayed: true ]
allCodesDeleted()
break
case 0xD:
if (cmd.eventParameter)
{
map = [ name: "codeReport", value: cmd.eventParameter[0], data: [ code: "" ], displayed: true ]
map.descriptionText = "$device.displayName code ${map.value} was deleted"
map.isStateChange = (state["code$map.value"] != "")
state["code$map.value"] = ""
}
else
{
map = [ name: "codeChanged", descriptionText: "$device.displayName: user code deleted", displayed: true ]
}
break
case 0xE:
map = [ name: "codeChanged", value: cmd.alarmLevel, descriptionText: "$device.displayName: user code added", displayed: true ]
if (cmd.eventParameter)
{
map.value = cmd.eventParameter[0]
result << response(requestCode(cmd.eventParameter[0]))
}
break
case 0xF:
map = [ name: "lock", value: "locked", descriptionText: "$device.displayName Alarm! (Too many user code failures.)", eventType: "ALERT", displayed: true, isStateChange: true ]
break
default:
map = map ?: [ descriptionText: "$device.displayName: alarm event $cmd.zwaveAlarmEvent", display: false ]
break
}
}
else if (cmd.zwaveAlarmType == physicalgraph.zwave.commands.alarmv2.AlarmReport.ZWAVE_ALARM_TYPE_BURGLAR) /* 0x07 */
{
// seen this happen with a schlage touchscreen when banging on the door.
// Might be a tamper or forced entry type alarm.
// In that case, type was 7 and event was 2
map = [ descriptionText: "$device.displayName Burglar Alarm! Event ${cmd.zwaveAlarmEvent}", eventType: "ALERT", displayed: true, isStateChange: true ]
}
else switch(cmd.alarmType)
{
/* // Schlage locks should be using the alarmv2 variables above or lock/unlock events
case 21: // Manually locked
case 18: // Locked with keypad
case 24: // Locked by command (Kwikset 914)
case 27: // Autolocked
map = [ name: "lock", value: "locked" ]
break
case 16: // Note: for levers this means it's unlocked, for non-motorized deadbolt, it's just unsecured and might not get unlocked
case 19:
map = [ name: "lock", value: "unlocked" ]
if (cmd.alarmLevel)
{
map.descriptionText = "$device.displayName was unlocked with code $cmd.alarmLevel"
map.data = [ usedCode: cmd.alarmLevel ]
}
break
case 22:
case 25: // Kwikset 914 unlocked by command
map = [ name: "lock", value: "unlocked" ]
break
*/
case 9:
case 17:
case 23:
case 26:
map = [ name: "lock", value: "unknown", descriptionText: "$device.displayName bolt is jammed" ]
break
case 13:
map = [ name: "codeChanged", value: cmd.alarmLevel, descriptionText: "$device.displayName code $cmd.alarmLevel was added", displayed: true ]
result << response(requestCode(cmd.alarmLevel))
break
case 32:
map = [ name: "codeChanged", value: "all", descriptionText: "$device.displayName: all user codes deleted", displayed: true ]
allCodesDeleted()
case 33:
map = [ name: "codeReport", value: cmd.alarmLevel, data: [ code: "" ], displayed: true ]
map.descriptionText = "$device.displayName code $cmd.alarmLevel was deleted"
map.isStateChange = (state["code$cmd.alarmLevel"] != "")
state["code$cmd.alarmLevel"] = ""
break
case 112:
map = [ name: "codeChanged", value: cmd.alarmLevel, descriptionText: "$device.displayName code $cmd.alarmLevel changed", displayed: true ]
result << response(requestCode(cmd.alarmLevel))
break
case 130: // Yale YRD batteries replaced
map = [ descriptionText: "$device.displayName batteries replaced", displayed: true ]
break
case 131:
map = [ /*name: "codeChanged", value: cmd.alarmLevel,*/ descriptionText: "$device.displayName code $cmd.alarmLevel is duplicate", displayed: false ]
case 161:
if (cmd.alarmLevel == 2)
{
map = [ descriptionText: "$device.displayName front escutcheon removed", isStateChange: true ]
}
else
{
map = [ descriptionText: "$device.displayName detected failed user code attempt", isStateChange: true ]
}
break
case 167:
if (!state.lastbatt || (new Date().time) - state.lastbatt > 12*60*60*1000)
{
map = [ descriptionText: "$device.displayName: battery low", displayed: true ]
result << response(secure(zwave.batteryV1.batteryGet()))
}
else
{
map = [ name: "battery", value: device.currentValue("battery"), descriptionText: "$device.displayName: battery low", displayed: true ]
}
break
case 168:
map = [ name: "battery", value: 1, descriptionText: "$device.displayName: battery level critical", displayed: true ]
break
case 169:
map = [ name: "battery", value: 0, descriptionText: "$device.displayName: battery too low to operate lock", isStateChange: true ]
break
default:
map = [ displayed: false, descriptionText: "$device.displayName: alarm event $cmd.alarmType level $cmd.alarmLevel" ]
break
}
result ? [createEvent(map), *result] : createEvent(map)
}
/* 0x63 */
def zwaveEvent(UserCodeReport cmd)
{
def result = []
def name = "code$cmd.userIdentifier"
def code = cmd.code
def map = [:]
if (cmd.userIdStatus == UserCodeReport.USER_ID_STATUS_OCCUPIED ||
(cmd.userIdStatus == UserCodeReport.USER_ID_STATUS_STATUS_NOT_AVAILABLE && cmd.user && code != "**********"))
{
if (code == "**********")
{ // Schlage locks send us this instead of the real code
state.blankcodes = true
code = state["set$name"] ?: state[name] ?: code
state.remove("set$name".toString())
}
if (!code && cmd.userIdStatus == 1)
{ // Schlage touchscreen sends blank code to notify of a changed code
map = [ name: "codeChanged", value: cmd.userIdentifier, displayed: true, isStateChange: true ]
map.descriptionText = "$device.displayName code $cmd.userIdentifier " + (state[name] ? "changed" : "was added")
code = state["set$name"] ?: state[name] ?: "****"
state.remove("set$name".toString())
}
else
{
map = [ name: "codeReport", value: cmd.userIdentifier, data: [ code: code ] ]
map.descriptionText = "$device.displayName code $cmd.userIdentifier is set"
map.displayed = (cmd.userIdentifier != state.requestCode && cmd.userIdentifier != state.pollCode)
map.isStateChange = (code != state[name])
}
result << createEvent(map)
}
else
{
map = [ name: "codeReport", value: cmd.userIdentifier, data: [ code: "" ] ]
if (state.blankcodes && state["reset$name"])
{ // we deleted this code so we can tell that our new code gets set
map.descriptionText = "$device.displayName code $cmd.userIdentifier was reset"
map.displayed = map.isStateChange = false
result << createEvent(map)
state["set$name"] = state["reset$name"]
result << response(setCode(cmd.userIdentifier, state["reset$name"]))
state.remove("reset$name".toString())
}
else
{
if (state[name])
{
map.descriptionText = "$device.displayName code $cmd.userIdentifier was deleted"
}
else
{
map.descriptionText = "$device.displayName code $cmd.userIdentifier is not set"
}
map.displayed = (cmd.userIdentifier != state.requestCode && cmd.userIdentifier != state.pollCode)
map.isStateChange = state[name] as Boolean
result << createEvent(map)
}
code = ""
}
state[name] = code
if (cmd.userIdentifier == state.requestCode)
{ // reloadCodes() was called, keep requesting the codes in order
if (state.requestCode + 1 > state.codes)
{
state.remove("requestCode") // done
}
else
{
state.requestCode = state.requestCode + 1 // get next
result << response(requestCode(state.requestCode))
}
}
if (cmd.userIdentifier == state.pollCode)
{
if (state.pollCode + 1 > state.codes)
{
state.remove("pollCode") // done
}
else
{
state.pollCode = state.pollCode + 1
}
}
log.debug "code report parsed to ${result.inspect()}"
result
}
/* 0x70, 0x06 */
def zwaveEvent(physicalgraph.zwave.commands.configurationv2.ConfigurationBulkReport cmd)
{
log.debug "Got a bulk report, but don't know what to do with it."
// it seems that this lock does NOT support BulkReport.
}
def zwaveEvent(physicalgraph.zwave.commands.configurationv2.ConfigurationReport cmd)
{
def result = []
def map = null // use this for config reports that are handled
// use desc/val for generic handling of config reports (it will just send a descriptionText for the acitivty stream)
def desc = null
def val = ""
switch (cmd.parameterNumber)
{
case 0x3:
map = parseBinaryConfigRpt('beeperMode', cmd.configurationValue[0], 'Beeper Mode')
break
// done: vacation mode toggle
case 0x4:
map = parseBinaryConfigRpt('vacationMode', cmd.configurationValue[0], 'Vacation Mode')
break
// done: lock and leave mode
case 0x5:
map = parseBinaryConfigRpt('lockLeave', cmd.configurationValue[0], 'Lock & Leave')
break
// these don't seem to be useful. It's just a bitmap of the code slots used.
case 0x6:
desc = "User Slot Bit Fields"
val = "${cmd.configurationValue[3]} ${cmd.configurationValue[2]} ${cmd.configurationValue[1]} ${cmd.configurationValue[0]}"
break
// done: the alarm mode of the lock.
case 0x7:
map = [ name:"alarmMode", displayed: true ]
// when getting the alarm mode, also query the sensitivity for that current alarm mode
switch (cmd.configurationValue[0])
{
case 0x00:
map.value = "Off_alarmMode"
break
case 0x01:
map.value = "Alert_alarmMode"
result << response(secure(zwave.configurationV2.configurationGet(parameterNumber: 0x08)))
break
case 0x02:
map.value = "Tamper_alarmMode"
result << response(secure(zwave.configurationV2.configurationGet(parameterNumber: 0x09)))
break
case 0x03:
map.value = "Kick_alarmMode"
result << response(secure(zwave.configurationV2.configurationGet(parameterNumber: 0x0A)))
break
default:
map.value = "unknown_alarmMode"
}
map.descriptionText = "$device.displayName Alarm Mode set to \"$map.value\""
break
// done: alarm sensitivities - one for each mode
case 0x8:
case 0x9:
case 0xA:
def whichMode = null
switch (cmd.parameterNumber)
{
case 0x8:
whichMode = "Alert"
break;
case 0x9:
whichMode = "Tamper"
break;
case 0xA:
whichMode = "Kick"
break;
}
def curAlarmMode = device.currentValue("alarmMode")
val = "${cmd.configurationValue[0]}"
// the lock has sensitivity values between 1 and 5. ST sliders want a value between 0 and 99. Use a formula
// to make the internal attribute something visually appealing on the UI slider
def modifiedValue = (cmd.configurationValue[0] * 24) - 23
map = [ descriptionText: "$device.displayName Alarm $whichMode Sensitivity set to $val", displayed: true ]
if (curAlarmMode == "${whichMode}_alarmMode")
{
map.name = "alarmSensitivity"
map.value = modifiedValue
}
else
{
log.debug "got sensitivity for $whichMode while in $curAlarmMode"
map.isStateChange = true
}
break
case 0xB:
map = parseBinaryConfigRpt('localControl', cmd.configurationValue[0], 'Local Alarm Control')
break
// how many times has the electric motor locked or unlock the device?
case 0xC:
desc = "Electronic Transition Count"
def ttl = cmd.configurationValue[3] + (cmd.configurationValue[2] * 0x100) + (cmd.configurationValue[1] * 0x10000) + (cmd.configurationValue[0] * 0x1000000)
val = "$ttl"
break
// how many times has the device been locked or unlocked manually?
case 0xD:
desc = "Mechanical Transition Count"
def ttl = cmd.configurationValue[3] + (cmd.configurationValue[2] * 0x100) + (cmd.configurationValue[1] * 0x10000) + (cmd.configurationValue[0] * 0x1000000)
val = "$ttl"
break
// how many times has there been a failure by the electric motor? (due to jamming??)
case 0xE:
desc = "Electronic Failed Count"
def ttl = cmd.configurationValue[3] + (cmd.configurationValue[2] * 0x100) + (cmd.configurationValue[1] * 0x10000) + (cmd.configurationValue[0] * 0x1000000)
val = "$ttl"
break
// done: auto lock mode
case 0xF:
map = parseBinaryConfigRpt('autoLock', cmd.configurationValue[0], 'Auto Lock')
break
// this will be useful as an attribute/command usable by a smartapp
case 0x10:
map = [ name: 'pinLength', value: cmd.configurationValue[0], displayed: true, descriptionText: "$device.displayName PIN length configured to ${cmd.configurationValue[0]} digits"]
break
// not sure what this one stores
case 0x11:
desc = "Electronic High Preload Transition Count"
def ttl = cmd.configurationValue[3] + (cmd.configurationValue[2] * 0x100) + (cmd.configurationValue[1] * 0x10000) + (cmd.configurationValue[0] * 0x1000000)
val = "$ttl"
break
// ???
case 0x12:
desc = "Bootloader Version"
val = "${cmd.configurationValue[0]}"
break
default:
desc = "Unknown parameter ${cmd.parameterNumber}"
val = "${cmd.configurationValue[0]}"
break
}
if (map)
{
result << createEvent(map)
}
else if (desc != null)
{
// generic description text
result << createEvent([ descriptionText: "$device.displayName reports \"$desc\" configured as \"$val\"", displayed: true, isStateChange: true ])
}
result
}
def parseBinaryConfigRpt(paramName, paramValue, paramDesc)
{
def map = [ name: paramName, displayed: true ]
def newVal = "on"
if (paramValue == 0)
{
newVal = "off"
}
map.value = "${newVal}_${paramName}"
map.descriptionText = "$device.displayName $paramDesc has been turned $newVal"
return map
}
def zwaveEvent(UsersNumberReport cmd)
{
def result = []
state.codes = cmd.supportedUsers
if (state.requestCode && state.requestCode <= cmd.supportedUsers)
{
result << response(requestCode(state.requestCode))
}
result
}
def zwaveEvent(physicalgraph.zwave.commands.associationv2.AssociationReport cmd)
{
def result = []
if (cmd.nodeId.any { it == zwaveHubNodeId })
{
state.remove("associationQuery")
log.debug "$device.displayName is associated to $zwaveHubNodeId"
result << createEvent(descriptionText: "$device.displayName is associated")
state.assoc = zwaveHubNodeId
if (cmd.groupingIdentifier == 2)
{
result << response(zwave.associationV1.associationRemove(groupingIdentifier:1, nodeId:zwaveHubNodeId))
}
}
else if (cmd.groupingIdentifier == 1)
{
result << response(secure(zwave.associationV1.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId)))
}
else if (cmd.groupingIdentifier == 2)
{
result << response(zwave.associationV1.associationSet(groupingIdentifier:2, nodeId:zwaveHubNodeId))
}
result
}
def zwaveEvent(physicalgraph.zwave.commands.timev1.TimeGet cmd)
{
def result = []
def now = new Date().toCalendar()
if(location.timeZone) now.timeZone = location.timeZone
result << createEvent(descriptionText: "$device.displayName requested time update", displayed: false)
result << response(secure(zwave.timeV1.timeReport(
hourLocalTime: now.get(Calendar.HOUR_OF_DAY),
minuteLocalTime: now.get(Calendar.MINUTE),
secondLocalTime: now.get(Calendar.SECOND))))
result
}
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd)
{
// The old Schlage locks use group 1 for basic control - we don't want that, so unsubscribe from group 1
def result = [ createEvent(name: "lock", value: cmd.value ? "unlocked" : "locked") ]
result << response(zwave.associationV1.associationRemove(groupingIdentifier:1, nodeId:zwaveHubNodeId))
if (state.assoc != zwaveHubNodeId)
{
result << response(zwave.associationV1.associationGet(groupingIdentifier:2))
}
result
}
def zwaveEvent(physicalgraph.zwave.commands.batteryv1.BatteryReport cmd)
{
def map = [ name: "battery", unit: "%" ]
if (cmd.batteryLevel == 0xFF)
{
map.value = 1
map.descriptionText = "$device.displayName has a low battery"
}
else
{
map.value = cmd.batteryLevel
}
state.lastbatt = new Date().time
createEvent(map)
}
def zwaveEvent(physicalgraph.zwave.commands.manufacturerspecificv2.ManufacturerSpecificReport cmd)
{
def result = []
def msr = String.format("%04X-%04X-%04X", cmd.manufacturerId, cmd.productTypeId, cmd.productId)
log.debug "msr: $msr"
updateDataValue("MSR", msr)
result << createEvent(descriptionText: "$device.displayName MSR: $msr", isStateChange: false)
result
}
def zwaveEvent(physicalgraph.zwave.commands.versionv1.VersionReport cmd)
{
def fw = "${cmd.applicationVersion}.${cmd.applicationSubVersion}"
updateDataValue("fw", fw)
def text = "$device.displayName: firmware version: $fw, Z-Wave version: ${cmd.zWaveProtocolVersion}.${cmd.zWaveProtocolSubVersion}"
createEvent(descriptionText: text, isStateChange: false)
}
def zwaveEvent(physicalgraph.zwave.commands.applicationstatusv1.ApplicationBusy cmd)
{
def msg = cmd.status == 0 ? "try again later" :
cmd.status == 1 ? "try again in $cmd.waitTime seconds" :
cmd.status == 2 ? "request queued" : "sorry"
createEvent(displayed: false, descriptionText: "$device.displayName is busy, $msg")
}
def zwaveEvent(physicalgraph.zwave.Command cmd)
{
createEvent(displayed: false, descriptionText: "$device.displayName: $cmd")
}
def lockAndCheck(doorLockMode)
{
secureSequence([
zwave.doorLockV1.doorLockOperationSet(doorLockMode: doorLockMode),
zwave.doorLockV1.doorLockOperationGet()
], 4200)
}
def lock()
{
lockAndCheck(DoorLockOperationSet.DOOR_LOCK_MODE_DOOR_SECURED)
}
def unlock()
{
lockAndCheck(DoorLockOperationSet.DOOR_LOCK_MODE_DOOR_UNSECURED)
}
def unlockwtimeout()
{
lockAndCheck(DoorLockOperationSet.DOOR_LOCK_MODE_DOOR_UNSECURED_WITH_TIMEOUT)
}
def refresh()
{
// def cmds = [secure(zwave.doorLockV1.doorLockOperationGet())]
def cmds = secureSequence([
zwave.doorLockV1.doorLockOperationGet(),
// zwave.configurationV2.configurationBulkGet(numberOfParameters: 3, parameterOffset: 0x8),
// zwave.configurationV2.configurationBulkGet(numberOfParameters: 4, parameterOffset: 0x3),
// zwave.configurationV2.configurationGet(parameterNumber: 0x3), // beeper (done)
// zwave.configurationV2.configurationGet(parameterNumber: 0x4), // vacation mode (done)
// zwave.configurationV2.configurationGet(parameterNumber: 0x5), // lock and leave (done)
// zwave.configurationV2.configurationGet(parameterNumber: 0x6), // user slot bit field (not needed)
zwave.configurationV2.configurationGet(parameterNumber: 0x7), // alarm mode (done)
// zwave.configurationV2.configurationGet(parameterNumber: 0x8), // alert alarm sensitivity (done: retrieved after alarm mode)
// zwave.configurationV2.configurationGet(parameterNumber: 0x9), // tamper alarm sensitivity (done: retrieved after alarm mode)
// zwave.configurationV2.configurationGet(parameterNumber: 0xA), // kick alarm sensititivy (done: retrieved after alarm mode)
// zwave.configurationV2.configurationGet(parameterNumber: 0xB), // local alarm control disable (done)
// zwave.configurationV2.configurationGet(parameterNumber: 0xC), // electronic transition count
// zwave.configurationV2.configurationGet(parameterNumber: 0xD), // mechanical transition count
// zwave.configurationV2.configurationGet(parameterNumber: 0xE), // electronic failure count
// zwave.configurationV2.configurationGet(parameterNumber: 0xF), // autolock (done)
// zwave.configurationV2.configurationGet(parameterNumber: 0x10), // user code pin length (done)
// zwave.configurationV2.configurationGet(parameterNumber: 0x11,) // electronic high preload transition count
// zwave.configurationV2.configurationGet(parameterNumber: 0x12,) // bootloader version
], 5000)
if (state.assoc == zwaveHubNodeId)
{
log.debug "$device.displayName is associated to ${state.assoc}"
}
else if (!state.associationQuery)
{
log.debug "checking association"
cmds << "delay 4200"
cmds << zwave.associationV1.associationGet(groupingIdentifier:2).format() // old Schlage locks use group 2 and don't secure the Association CC
cmds << secure(zwave.associationV1.associationGet(groupingIdentifier:1))
state.associationQuery = new Date().time
}
else if (new Date().time - state.associationQuery.toLong() > 9000)
{
log.debug "setting association"
cmds << "delay 6000"
cmds << zwave.associationV1.associationSet(groupingIdentifier:2, nodeId:zwaveHubNodeId).format()
cmds << secure(zwave.associationV1.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId))
cmds << zwave.associationV1.associationGet(groupingIdentifier:2).format()
cmds << secure(zwave.associationV1.associationGet(groupingIdentifier:1))
state.associationQuery = new Date().time
}
log.debug "refresh sending ${cmds.inspect()}"
cmds
}
def poll()
{
def cmds = []
if (state.assoc != zwaveHubNodeId && secondsPast(state.associationQuery, 19 * 60))
{
log.debug "setting association"
cmds << zwave.associationV1.associationSet(groupingIdentifier:2, nodeId:zwaveHubNodeId).format()
cmds << secure(zwave.associationV1.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId))
cmds << zwave.associationV1.associationGet(groupingIdentifier:2).format()
cmds << "delay 6000"
cmds << secure(zwave.associationV1.associationGet(groupingIdentifier:1))
cmds << "delay 6000"
state.associationQuery = new Date().time
}
else
{
// Only check lock state if it changed recently or we haven't had an update in an hour
def latest = device.currentState("lock")?.date?.time
if (!latest || !secondsPast(latest, 6 * 60) || secondsPast(state.lastPoll, 67 * 60))
{
cmds << secure(zwave.doorLockV1.doorLockOperationGet())
state.lastPoll = (new Date()).time
}
else if (!state.codes)
{
state.pollCode = 1
cmds << secure(zwave.userCodeV1.usersNumberGet())
}
else if (state.pollCode && state.pollCode <= state.codes)
{
cmds << requestCode(state.pollCode)
}
else if (!state.lastbatt || (new Date().time) - state.lastbatt > 53*60*60*1000)
{
cmds << secure(zwave.batteryV1.batteryGet())
// } else {
// // TODO: at some intervals, pick up some of the other configuration values
// that might be useful
}
if(cmds) cmds << "delay 6000"
}
reportAllCodes(state)
log.debug "poll is sending ${cmds.inspect()}, state: ${state.inspect()}"
device.activity() // workaround to keep polling from being shut off
cmds ?: null
}
def reportAllCodes(state) {
def map = [ name: "reportAllCodes", data: state, displayed: true, isStateChange: true ]
sendEvent(map)
}
def requestCode(codeNumber)
{
secure(zwave.userCodeV1.userCodeGet(userIdentifier: codeNumber))
}
def reloadAllCodes()
{
def cmds = []
if (!state.codes)
{
state.requestCode = 1
cmds << secure(zwave.userCodeV1.usersNumberGet())
}
else
{
if(!state.requestCode) state.requestCode = 1
cmds << requestCode(codeNumber)
}
cmds
}
def setCode(codeNumber, code)
{
def strcode = code
log.debug "setting code $codeNumber to $code"
if (code instanceof String)
{
code = code.toList().findResults { if(it > ' ' && it != ',' && it != '-') it.toCharacter() as Short }
}
else