forked from MichaelStruck/SmartThingsPublic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest26931
557 lines (551 loc) · 28.7 KB
/
Test26931
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
/**
* GE Motion Switch (Model 26931) DTH
*
* Copyright © 2020 Michael Struck
* Original Author: Matt Lebaugh (@mlebaugh)
*
* Version 1.1.0 2/1/21
*
* Verison 1.1.0 (2/1/21) - Fixed a few items related to using in the new version of the ST mobile app. Removed much of the interface from the old app. Moved logging to live logging as device logging no longer is present.
* Version 1.0.9 (8/24/20) - Reverted back to Boolean selection in settings. Probably last update of this DTH before ST API is put into place
* Version 1.0.8 (6/3/20) - Updated Setting to allow for Boolean for items like enabling motion sensor; added button capability back in
* Version 1.0.7 (5/27/20) - Fixed a few outstanding GUI issues and started adding secure commands to the code. Optimized code slightly and gave more meaningful logging
* Version 1.0.6 (5/22/20) - Fixed the reset cycle parameter that was not saving properly. Thank @Morgon! Alignment with dimmer parameter
* Version 1.0.5 (12/4/18) - Removed logging to reduce Zwave traffic; optimized button triple press
* Version 1.0.4b (10/18/18) - Skipped 1.0.4 to maintain consistency with dimmer code version. Changed to triple push for special options
* Version 1.0.2 (8/2/18) - Updated some of the text/options on the Settings page
* Version 1.0.1 (7/15/18) - Format and syntax updates. Thanks to @Darwin for the motion sensitivity/timeout minutes idea!
* Version 1.0.0 (3/17/17)- Original release by Matt Lebaugh. Great Work!
*
* 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 {
definition (name: "GE Motion Switch 26931", namespace: "MichaelStruck", author: "Michael Struck", mnmn:"SmartThings", ocfDeviceType: "oic.d.switch", vid: "generic-motion-light") {
capability "Motion Sensor"
capability "Actuator"
capability "Switch"
capability "Polling"
capability "Refresh"
capability "Sensor"
capability "Health Check"
capability "Light"
capability "Button"
command "toggleMode"
command "occupied"
command "occupancy"
command "vacant"
command "vacancy"
command "manual"
command "setMotionSenseOff"
command "setMotionSenseHigh"
command "setMotionSenseMed"
command "setMotionSenseLow"
command "lightSenseOn"
command "lightSenseOff"
command "setTimeout5Seconds"
command "setTimeout1Minute"
command "setTimeout5Minutes"
command "setTimeout15Minutes"
command "setTimeout30Minutes"
attribute "operatingMode", "enum", ["Manual", "Vacancy", "Occupancy"]
fingerprint mfr:"0063", prod:"494D", model: "3032", deviceJoinName: "GE Z-Wave Plus Motion Wall Switch"
}
preferences {
input title: "", description: "Select your preferences here, they will be sent to the device once updated.\n\nTo verify the current settings of the device, they will be shown in the 'Recently' page once any setting is updated", displayDuringSetup: false, type: "paragraph", element: "paragraph"
input (name: "operationmode", title: "Operating Mode",
description: "Select the mode of the switch (no entry will keep the current mode)",
type: "enum",
options: [
"1" : "Manual (no auto-on/no auto-off)",
"2" : "Vacancy (no auto-on/auto-off)",
"3" : "Occupancy (auto-on/auto-off)"
],
required: false
)
input (name: "timeoutduration", title: "Timeout Duration (Occupancy/Vacancy)",
description: "Time after no motion for light to turn off",
type: "enum",
options: [
"0" : "5 seconds",
"1" : "1 minute",
"5" : "5 minutes (Default)",
"15" : "15 minutes",
"30" : "30 minutes"
],
required: false
)
input (name: "timeoutdurationPress", title: "Triple Press Timeout (Occupancy/Vacancy)",
description: "Physically press 'on' three times within 10 seconds to override timeout. Resets when light goes off",
type: "enum",
options: [
"0" : "5 seconds",
"1" : "1 minute",
"5" : "5 minutes",
"15" : "15 minutes",
"30" : "30 minutes"
],
required: false
)
input "timeoutdurationPressReset", "bool", title: "Reset Timeout When Light Goes Out (If Triple Press Timeout Is Set)", defaultValue:true
input (name: "modeOverride", title: "Triple Press Operating Mode Override",
description: "Physically press 'off' three times within 10 seconds to override the current operating mode",
type: "enum",
options: [
"1" : "Manual (no auto-on/no auto-off)",
"2" : "Vacancy (no auto-on/auto-off)",
"3" : "Occupancy (auto-on/auto-off)"
],
required: false
)
//param 6
input "motion", "bool", title: "Enable Motion Sensor", defaultValue:true
//param 13
input (name: "motionsensitivity", title: "Motion Sensitivity (When Motion Sensor Enabled)",
description: "Motion Sensitivity",
type: "enum",
options: [
"1" : "High",
"2" : "Medium (Default)",
"3" : "Low"
],
required: false
)
//param 14
input "lightsense", "bool", title: "Enable Light Sensing (Occupancy)", defaultValue: true
//param 5
input "invertSwitch", "bool", title: "Invert Remote Switch Orientation", defaultValue: false
//param 15
input ("resetcycle","enum",title: "Motion Reset Cycle",
description: "Time to stop reporting motion once motion has stopped",
type: "enum",
options: [
"0" : "Disabled",
"1" : "10 sec",
"2" : "20 sec (Default)",
"3" : "30 sec",
"4" : "45 sec",
"5" : "60 sec",
"110" : "27 mins"
]
)
input (
type: "paragraph", element: "paragraph", title: "",
description: "**Configure Association Groups**\nDevices in association groups 2 & 3 will receive Basic Set commands directly from the switch when it is turned on or off (physically or locally through the motion detector). Use this to control other devices as if they was connected to this switch.\n\n" +
"Devices are entered as a comma delimited list of the Device Network IDs in hexadecimal format."
)
input (name: "requestedGroup2", title: "Association Group 2 Members (Max of 5):", description: "Use the 'Device Network ID' for each device", type: "text", required: false )
input (name: "requestedGroup3", title: "Association Group 3 Members (Max of 4):", description: "Use the 'Device Network ID' for each device", type: "text", required: false )
}
}
def parse(String description) {
def result = null
if (description != "updated") {
//log.debug "parse() >> zwave.parse($description)"
def cmd = zwave.parse(description, [0x20: 1, 0x25: 1, 0x56: 1, 0x70: 2, 0x72: 2, 0x85: 2, 0x71: 3])
if (cmd) {
result = zwaveEvent(cmd)
}
}
if (!result) { log.warn "Parse returned ${result} for $description" }
//else {log.debug "Parse returned ${result}"}
return result
if (result?.name == 'hail' && hubFirmwareLessThan("000.011.00602")) {
result = [result, response(zwave.basicV1.basicGet())]
log.debug "Was hailed: requesting state update"
}
return result
}
def zwaveEvent(physicalgraph.zwave.commands.crc16encapv1.Crc16Encap cmd) {
log.debug("zwaveEvent(): CRC-16 Encapsulation Command received: ${cmd}")
def encapsulatedCommand = zwave.commandClass(cmd.commandClass)?.command(cmd.command)?.parse(cmd.data)
if (!encapsulatedCommand) {
log.debug("zwaveEvent(): Could not extract command from ${cmd}")
} else {
return zwaveEvent(encapsulatedCommand)
}
}
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd) {
createEvent([name: "switch", value: cmd.value ? "on" : "off", type: "physical"])
}
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) {
//log.debug "---BASIC SET V1--- ${device.displayName} sent ${cmd}"
def result = []
if (cmd.value == 255) {
result << createEvent([name: "button", value: "pushed", data: [buttonNumber: "1"], descriptionText: "On/Up (button 1) on $device.displayName was pushed", isStateChange: true, type: "physical"])
if (timeoutdurationPress){
if (modeOverride) state.offCounter=0
if (!state.onCounter || state.onCounter > 2 || (now()-state.Timer) > 10000) state.onCounter=0
state.onCounter = state.onCounter + 1
if (state.onCounter==1) state.Timer=now()
log.debug "On button push:" + state.onCounter
if (state.onCounter==3 && (now()-state.Timer)<10000) {
log.info "Triple press of on button in less than 10 seconds - Overriding timeout"
def cmds=[]
cmds << zwave.configurationV1.configurationSet(configurationValue: [timeoutdurationPress.toInteger()], parameterNumber: 1, size: 1)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 1)
sendHubCommand(cmds.collect{ new physicalgraph.device.HubAction(it.format()) }, 1000)
showDashboard(timeoutdurationPress.toInteger(), "", "")
}
}
}
else if (cmd.value == 0) {
result << createEvent([name: "button", value: "pushed", data: [buttonNumber: "2"], descriptionText: "Off/Down (button 2) on $device.displayName was pushed", isStateChange: true, type: "physical"])
if (modeOverride) {
if (timeoutdurationPress) state.onCounter=0
if (!state.offCounter || state.offCounter >2 || (now()-state.timerOff)>10000) state.offCounter=0
state.offCounter = state.offCounter + 1
if (state.offCounter==1) state.timerOff=now()
log.debug "Off button push:" + state.offCounter
if (state.offCounter==3 && (now()-state.timerOff)<10000) {
log.info "Triple press of off button in less than 10 seconds - Overriding mode"
def cmds=[]
cmds << zwave.configurationV1.configurationSet(configurationValue: [modeOverride.toInteger()], parameterNumber: 3, size: 1)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 3)
sendHubCommand(cmds.collect{ new physicalgraph.device.HubAction(it.format()) }, 1000)
}
}
}
return result
}
def zwaveEvent(physicalgraph.zwave.commands.associationv2.AssociationReport cmd) {
log.debug "---ASSOCIATION REPORT V2--- ${device.displayName} sent groupingIdentifier: ${cmd.groupingIdentifier} maxNodesSupported: ${cmd.maxNodesSupported} nodeId: ${cmd.nodeId} reportsToFollow: ${cmd.reportsToFollow}"
state.group3 = "1,2"
if (cmd.groupingIdentifier == 3) {
if (cmd.nodeId.contains(zwaveHubNodeId)) {
sendEvent(name: "numberOfButtons", value: 2, displayed: false)
}
else {
sendEvent(name: "numberOfButtons", value: 0, displayed: false)
sendHubCommand(new physicalgraph.device.HubAction(zwave.associationV2.associationSet(groupingIdentifier: 3, nodeId: zwaveHubNodeId).format()))
sendHubCommand(new physicalgraph.device.HubAction(zwave.associationV2.associationGet(groupingIdentifier: 3).format()))
}
}
}
def zwaveEvent(physicalgraph.zwave.commands.configurationv2.ConfigurationReport cmd) {
//log.debug "---CONFIGURATION REPORT V2--- ${device.displayName} sent ${cmd}"
def config = cmd.scaledConfigurationValue
def result = []
if (cmd.parameterNumber == 1) {
def value = config == 0 ? "5 seconds" : config == 1 ? "1 minute" : config == 5 ? "5 minutes" : config == 15 ? "15 minutes" :"30 minutes"
result << createEvent([name:"TimeoutDuration", value: value, displayed:true, isStateChange:true])
} else if (cmd.parameterNumber == 13) {
def value = config == 1 ? "High" : config == 2 ? "Medium" : "Low"
result << createEvent([name:"MotionSensitivity", value: value, displayed:true, isStateChange:true])
} else if (cmd.parameterNumber == 14) {
def value = config == 0 ? "Disabled" : "Enabled"
result << createEvent([name:"LightSense", value: value, displayed:true, isStateChange:true])
} else if (cmd.parameterNumber == 15) {
def value = config == 0 ? "Disabled" : config == 1 ? "10 sec" : config == 2 ? "20 sec" : config == 3 ? "30 sec" : config == 4 ? "45 sec" : config == 5 ? "60 sec" : "27 minute"
result << createEvent([name:"ResetCycle", value: value, displayed:true, isStateChange:true])
} else if (cmd.parameterNumber == 3) {
if (config == 1 ) {
result << createEvent([name:"operatingMode", value: "Manual", displayed:true, isStateChange:true])
} else if (config == 2 ) {
result << createEvent([name:"operatingMode", value: "Vacancy", displayed:true, isStateChange:true])
} else if (config == 3 ) {
result << createEvent([name:"operatingMode", value: "Occupancy", displayed:true, isStateChange:true])
}
} else if (cmd.parameterNumber == 6) {
def value = config == 0 ? "Disabled" : "Enabled"
result << createEvent([name:"MotionSensor", value: value, displayed:true, isStateChange:true])
} else if (cmd.parameterNumber == 5) {
def value = config == 0 ? "Normal" : "Inverted"
result << createEvent([name:"SwitchOrientation", value: value, displayed:true, isStateChange:true])
}
return result
}
def zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd) {
//log.debug "---BINARY SWITCH REPORT V1--- ${device.displayName} sent ${cmd}"
if (cmd.value==0 && timeoutdurationPress && timeoutdurationPressReset){
log.info "Resetting timeout duration"
def cmds=[],timeoutValue = timeoutduration ? timeoutduration.toInteger() : 5
cmds << zwave.configurationV1.configurationSet(configurationValue: [timeoutValue], parameterNumber: 1, size: 1)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 1)
sendHubCommand(cmds.collect{ new physicalgraph.device.HubAction(it.format()) }, 1000)
showDashboard(timeoutValue, "", "")
}
createEvent(name: "switch", value: cmd.value ? "on" : "off")
}
def zwaveEvent(physicalgraph.zwave.commands.hailv1.Hail cmd) {
[name: "hail", value: "hail", descriptionText: "Switch button was pressed", displayed: false]
}
def zwaveEvent(physicalgraph.zwave.commands.notificationv3.NotificationReport cmd)
{
//log.debug "---NOTIFICATION REPORT V3--- ${device.displayName} sent ${cmd}"
def result = []
if (cmd.notificationType == 0x07) {
if ((cmd.event == 0x00)) {
result << createEvent(name: "motion", value: "inactive", descriptionText: "$device.displayName motion has stopped")
log.debug "$device.displayName motion has stopped"
} else if (cmd.event == 0x08) {
result << createEvent(name: "motion", value: "active", descriptionText: "$device.displayName detected motion")
log.debug "$device.displayName detected motion"
}
}
result
}
def zwaveEvent(physicalgraph.zwave.Command cmd) {
log.warn "${device.displayName} received unhandled command: ${cmd}"
}
def on() {
[
secure(zwave.switchBinaryV1.switchBinarySet(switchValue: 0xFF)),
"delay 100",
secure(zwave.switchBinaryV1.switchBinaryGet())
]
}
def off() {
[
secure(zwave.switchBinaryV1.switchBinarySet(switchValue: 0x00)),
"delay 100",
secure(zwave.switchBinaryV1.switchBinaryGet())
]
}
def poll() { refresh() }
def ping() { refresh() }
def refresh() {
log.debug "refresh() is called"
response(secure(zwave.switchBinaryV1.switchBinaryGet()))
showDashboard("", "", "")
}
def toggleMode() {
log.debug("Toggling Mode")
def cmds = []
if (device.currentValue("operatingMode") == "Manual") vacancy()
else if (device.currentValue("operatingMode") == "Vacancy") occupancy()
else if (device.currentValue("operatingMode") == "Occupancy") manual()
}
def setTimeout5Seconds() { setTimeoutMinutes(0) }
def setTimeout1Minute() { setTimeoutMinutes(1) }
def setTimeout5Minutes() { setTimeoutMinutes(5) }
def setTimeout15Minutes() { setTimeoutMinutes(15) }
def setTimeout30Minutes() { setTimeoutMinutes(30) }
def setTimeoutMinutes(value){
def cmds = [], newTimeOut
if (value==0) newTimeOut="5 seconds"
else if (value==1) newTimeOut="1 minute"
else if (value==5) newTimeOut="5 minutes"
else if (value==15) newTimeOut="15 minutes"
else if (value==30) newTimeOut="30 minutes"
cmds << zwave.configurationV1.configurationSet(configurationValue: [value], parameterNumber: 1, size: 1)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 1)
sendHubCommand(cmds.collect{ new physicalgraph.device.HubAction(it.format()) }, 1000)
showDashboard(value, "", "")
log.debug "Setting timeout duration to: ${newTimeOut}"
}
def occupied() { occupancy() }
def occupancy() {
log.debug "Setting operating mode to: Occupancy"
def cmds = []
cmds << zwave.configurationV1.configurationSet(configurationValue: [3] , parameterNumber: 3, size: 1)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 3)
sendHubCommand(cmds.collect{ new physicalgraph.device.HubAction(it.format()) }, 1000)
}
def vacant() { vacancy() }
def vacancy() {
log.debug "Setting operating mode to: Vacancy"
def cmds = []
cmds << zwave.configurationV1.configurationSet(configurationValue: [2] , parameterNumber: 3, size: 1)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 3)
sendHubCommand(cmds.collect{ new physicalgraph.device.HubAction(it.format()) }, 1000)
}
def manual() {
log.debug "Setting operating mode to: Manual"
def cmds = []
cmds << zwave.configurationV1.configurationSet(configurationValue: [1] , parameterNumber: 3, size: 1)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 3)
sendHubCommand(cmds.collect{ new physicalgraph.device.HubAction(it.format()) }, 1000)
}
def setMotionSenseLow(){ setMotionSensitivity(3) }
def setMotionSenseMed(){ setMotionSensitivity(2) }
def setMotionSenseHigh(){ setMotionSensitivity(1) }
def setMotionSenseOff(){ setMotionSensitivity(0) }
def setMotionSensitivity(value) {
def cmds = []
if (value>0){
def mode=value==1 ? "High" : value==2 ? "Medium" : "Low"
log.debug("Setting motion sensitivity to: ${mode}")
cmds << zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 6, size: 1)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 6)
cmds << zwave.configurationV1.configurationSet(configurationValue: [value] , parameterNumber: 13, size: 1)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 13)
}
else if (value==0){
log.debug("Turning off motion sensor")
cmds << zwave.configurationV1.configurationSet(configurationValue: [0], parameterNumber: 6, size: 1)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 6)
}
sendHubCommand(cmds.collect{ new physicalgraph.device.HubAction(it.format()) }, 1000)
showDashboard("", value, "")
}
def lightSenseOn() {
log.debug("Setting Light Sense On")
def cmds = []
cmds << zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 14, size: 1)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 14)
sendHubCommand(cmds.collect{ new physicalgraph.device.HubAction(it.format()) }, 1000)
showDashboard("", "", 1)
}
def lightSenseOff() {
log.debug("Setting Light Sense Off")
def cmds = []
cmds << zwave.configurationV1.configurationSet(configurationValue: [0], parameterNumber: 14, size: 1)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 14)
sendHubCommand(cmds.collect{ new physicalgraph.device.HubAction(it.format()) }, 1000)
showDashboard("", "", 0)
}
def installed() {
updated()
}
def updated() {
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
if (state.lastUpdated && now() <= state.lastUpdated + 3000) return
state.lastUpdated = now()
def cmds = [], timeDelay, motionSensor, lightSensor, dimLevel
//switch and dimmer settings
//param 1 timeout duration
if (settings.timeoutduration) {
cmds << zwave.configurationV1.configurationSet(configurationValue: [settings.timeoutduration.toInteger()], parameterNumber: 1, size: 1)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 1)
timeDelay = timeoutduration.toInteger()
}
else{
cmds << zwave.configurationV1.configurationSet(configurationValue: [5], parameterNumber: 1, size: 1)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 1)
timeDelay = 5
}
//param 13 motion sensitivity
if (settings.motionsensitivity) {
cmds << zwave.configurationV1.configurationSet(configurationValue: [settings.motionsensitivity.toInteger()], parameterNumber: 13, size: 1)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 13)
motionSensor=motionsensitivity.toInteger()
}
else {
cmds << zwave.configurationV1.configurationSet(configurationValue: [2], parameterNumber: 13, size: 1)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 13)
motionSensor=2
}
//param 14 lightsense
lightSensor = lightsense ? 1 : 0
cmds << zwave.configurationV1.configurationSet(configurationValue: [lightSensor], parameterNumber: 14, size: 1)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 14)
//param 15 reset cycle
if (settings.resetcycle) {
cmds << zwave.configurationV1.configurationSet(configurationValue: [0, settings.resetcycle.toInteger()], parameterNumber: 15, size: 2)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 15)
}
else {
cmds << zwave.configurationV1.configurationSet(configurationValue: [0,2], parameterNumber: 15, size: 2)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 15)
}
//param 3 operating mode (no default...no entry=no change)
if (settings.operationmode) cmds << zwave.configurationV1.configurationSet(configurationValue: [settings.operationmode.toInteger()], parameterNumber: 3, size: 1)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 3)
//param 6 motion
//motionSensor = motion=="Disabled" ? 0 : motionSensor
motionSensor = !motion ? "Disabled" : motionSensor
cmds << zwave.configurationV1.configurationSet(configurationValue: [motion ? 1 : 0], parameterNumber: 6, size: 1)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 6)
//param 5 invert switch
cmds << zwave.configurationV1.configurationSet(configurationValue: [ invertSwitch ? 1 : 0 ], parameterNumber: 5, size: 1)
cmds << zwave.configurationV1.configurationGet(parameterNumber: 5)
// Make sure lifeline is associated - was missing on a dimmer:
cmds << zwave.associationV1.associationSet(groupingIdentifier:0, nodeId:zwaveHubNodeId)
cmds << zwave.associationV1.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId)
cmds << zwave.associationV1.associationSet(groupingIdentifier:2, nodeId:zwaveHubNodeId)
cmds << zwave.associationV1.associationSet(groupingIdentifier:3, nodeId:zwaveHubNodeId)
//association groups
def nodes = []
if (settings.requestedGroup2 != state.currentGroup2) {
nodes = parseAssocGroupList(settings.requestedGroup2, 2)
cmds << zwave.associationV2.associationRemove(groupingIdentifier: 2, nodeId: [])
cmds << zwave.associationV2.associationSet(groupingIdentifier: 2, nodeId: nodes)
cmds << zwave.associationV2.associationGet(groupingIdentifier: 2)
state.currentGroup2 = settings.requestedGroup2
}
if (settings.requestedGroup3 != state.currentGroup3) {
nodes = parseAssocGroupList(settings.requestedGroup3, 3)
cmds << zwave.associationV2.associationRemove(groupingIdentifier: 3, nodeId: [])
cmds << zwave.associationV2.associationSet(groupingIdentifier: 3, nodeId: nodes)
cmds << zwave.associationV2.associationGet(groupingIdentifier: 3)
state.currentGroup3 = settings.requestedGroup3
}
sendHubCommand(cmds.collect{ new physicalgraph.device.HubAction(it.format()) }, 500)
showDashboard(timeDelay, motionSensor, lightSensor)
}
def configure() {
def cmds = []
// Make sure lifeline is associated - was missing on a dimmer:
cmds << zwave.associationV1.associationSet(groupingIdentifier:0, nodeId:zwaveHubNodeId)
cmds << zwave.associationV1.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId)
cmds << zwave.associationV1.associationSet(groupingIdentifier:2, nodeId:zwaveHubNodeId)
cmds << zwave.associationV1.associationSet(groupingIdentifier:3, nodeId:zwaveHubNodeId)
sendHubCommand(cmds.collect{ new physicalgraph.device.HubAction(it.format()) }, 1000)
}
private parseAssocGroupList(list, group) {
def nodes = group == 2 ? [] : [zwaveHubNodeId]
if (list) {
def nodeList = list.split(',')
def max = group == 2 ? 5 : 4
def count = 0
nodeList.each { node ->
node = node.trim()
if ( count >= max) {
log.warn "Association Group ${group}: Number of members is greater than ${max}! The following member was discarded: ${node}"
}
else if (node.matches("\\p{XDigit}+")) {
def nodeId = Integer.parseInt(node,16)
if (nodeId == zwaveHubNodeId) {
log.warn "Association Group ${group}: Adding the hub as an association is not allowed."
}
else if ( (nodeId > 0) & (nodeId < 256) ) {
nodes << nodeId
count++
}
else {
log.warn "Association Group ${group}: Invalid member: ${node}"
}
}
else {
log.warn "Association Group ${group}: Invalid member: ${node}"
}
}
}
return nodes
}
private secure(cmd) {
if ((zwaveInfo.zw == null && state.sec != 0) || zwaveInfo?.zw?.contains("s")) {
zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format()
} else {
cmd.format()
}
}
def showDashboard(timeDelay, motionSensor, lightSensor) {
String result =""
if (timeDelay=="") timeDelay=state.currentTimeDelay
if (motionSensor=="") motionSensor=state.currentMotionSensor
if (lightSensor=="") lightSensor=state.currentLightSensor
state.currentTimeDelay=timeDelay
state.currentMotionSensor=motionSensor
state.currentLightSensor=lightSensor
def motionSensorTxt = motionSensor == 1 ? "High" : motionSensor == 2 ? "Medium" : motionSensor==3 ? "Low" : "Disabled"
def lightSensorTxt = lightSensor == 0 ? "Disabled" : "Enabled"
def timeDelayTxt = timeDelay == 0 ? "5 seconds" : timeDelay == 1 ? "1 minute" : timeDelay == 5 ? "5 minutes" : timeDelay == 15 ? "15 minutes" : "30 minutes"
def motionSync = ((motion && motionSensorTxt !="Disabled" && motionsensitivity && state.currentMotionSensor==motionsensitivity.toInteger()) || (!motionsensitivity && state.currentMotionSensor==2)) ||
(!motion && motionSensorTxt =="Disabled") ? "✔" : "‼"
def lightSync = (!lightsense && state.currentLightSensor == 0) || (lightsense && state.currentLightSensor == 1) ? "✔" : "‼"
def timeSync = (timeoutduration && state.currentTimeDelay == timeoutduration.toInteger()) || (!timeoutduration && state.currentTimeDelay == 5) ? "✔" : "‼"
result +="**Operating Mode: " + (operationmode=="1" ? "Manual" : operationmode=="2" ? "Vacancy" : "Occupancy") + "**\n"
result +="\n${motionSync} Motion Sensitivity: " + motionSensorTxt
result +="\n${lightSync} Light Sensing: " + lightSensorTxt
result +="\n${timeSync} Timeout Duration: " + timeDelayTxt
log.info "\n=====DTH Version 1.1.0 (2/1/21)=====\n" + result + "\n====================================="
}