-
Notifications
You must be signed in to change notification settings - Fork 0
/
Zen27_Driver.groovy
505 lines (460 loc) · 18.6 KB
/
Zen27_Driver.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
/**
* Zooz Zen27 Dimmer Switch
*
* Revision History:
* 2018-10-27 - Initial release
* 2018-11-18 - Fixes for parameters due to platform changes
* 2018-11-19 - Fix LED parameter for all values
* 2019-02-03 - Ported to HE from https://github.com/doncaruana/SmartThings-doncaruana only change tiles commented out
*
* Supported Command Classes
* Association v2
* Association Group Information
* Basic
* Configuration
* Device Reset Local
* Manufacturer Specific v2
* Powerlevel
* Switch_all
* Switch_multilevel
* Version v2
* ZWavePlus Info v2
* COMMAND_CLASS_ASSOCIATION
* COMMAND_CLASS_ASSOCIATION_GRP_INFO
* COMMAND_CLASS_CONFIGURATION
* COMMAND_CLASS_DEVICE_RESET_LOCALLY
* COMMAND_CLASS_MANUFACTURER_SPECIFIC
* COMMAND_CLASS_POWERLEVEL
* COMMAND_CLASS_SWITCH_MULTILEVEL
* COMMAND_CLASS_VERSION
* COMMAND_CLASS_ZWAVEPLUS_INFO
* COMMAND_CLASS_MULTI_CHANNEL_ASSOCIATION
* COMMAND_CLASS_TRANSPORT_SERVICE
* COMMAND_CLASS_SECURITY_2
* COMMAND_CLASS_SUPERVISION
* COMMAND_CLASS_FIRMWARE_UPDATE_MD
*
* Parm Size Description Value
* 1 1 Invert Switch 0 (Default)-Upper paddle turns light on, 1-Lower paddle turns light on
* 2 1 LED Indicator 0 (Default)-LED is on when light is OFF, 1-LED is on when light is ON, 2-LED is always off, 3-LED is always on
* 3 1 Auto Turn-Off 0 (Default)-Timer disabled, 1-Timer enabled; Set time in parameter 4
* 4 4 Turn-off Timer 60 (Default)-Time in minutes after turning on to automatically turn off (1-65535 minutes)
* 5 1 Auto Turn-On 0 (Default)-Timer disabled, 1-Timer enabled; Set time in parameter 6
* 6 4 Turn-on Timer 60 (Default)-Time in minutes after turning off to automatically turn on (1-65535 minutes)
* 8 1 Power Restore 2 (Default)-Remember state from pre-power failure, 0-Off after power restored, 1-On after power restore
* 9 1 Ramp Rate Control 1 (Default)-Ramp rate in seconds to reach full brightness or off (1-99 seconds)
* 10 1 Minimum Brightness 1 (Default)-Minimum brightness that light will set (1-99%)
* 11 1 Maximum Brightness 99 (Default)-Maximum brightness that light will set (1-99%)
* 12 1 Double Tap 0 (Default)-Light will go to full brightness with double tap, 1-light will go to max set in Parameter 11 with double tap
*/
metadata {
definition (name: "Zooz Zen27 Dimmer", namespace: "AR", author: "Don Caruana", ocfDeviceType: "oic.d.light", mnmn: "Hubitat", vid: "generic-dimmer") {
capability "Switch Level"
capability "Actuator"
capability "Health Check"
capability "Switch"
capability "Polling"
capability "Refresh"
capability "Sensor"
capability "Light"
//zw:L type:1101 mfr:027A prod:A000 model:A002 ver:1.00 zwv:5.03 lib:03 cc:5E,26,85,8E,59,55,86,72,5A,73,70,9F,6C,7A role:05 ff:8600 ui:8604
fingerprint mfr:"027A", prod:"A000", model:"A002", deviceJoinName: "Zooz Zen27 Dimmer"
fingerprint deviceId:"0x1101", inClusters: "0x26,0x55,0x59,0x5A,0x5E,0x6C,0x70,0x72,0x73,0x7A,0x85,0x86,0x8E,0x9F"
fingerprint cc: "0x26,0x55,0x59,0x5A,0x5E,0x6C,0x70,0x72,0x73,0x7A,0x85,0x86,0x8E,0x9F", mfr:"027A", prod:"A000", model:"A002", deviceJoinName: "Zooz Zen27 Dimmer"
}
simulator {
status "on": "command: 2003, payload: FF"
status "off": "command: 2003, payload: 00"
status "09%": "command: 2003, payload: 09"
status "10%": "command: 2003, payload: 0A"
status "33%": "command: 2003, payload: 21"
status "66%": "command: 2003, payload: 42"
status "99%": "command: 2003, payload: 63"
// reply messages
reply "2001FF,delay 5000,2602": "command: 2603, payload: FF"
reply "200100,delay 5000,2602": "command: 2603, payload: 00"
reply "200119,delay 5000,2602": "command: 2603, payload: 19"
reply "200132,delay 5000,2602": "command: 2603, payload: 32"
reply "20014B,delay 5000,2602": "command: 2603, payload: 4B"
reply "200163,delay 5000,2602": "command: 2603, payload: 63"
}
preferences {
input "ledIndicator", "enum", title: "LED Indicator", description: "When Off... ", options:["on": "When On", "off": "When Off", "never": "Never", "always": "Always"], defaultValue: "off"
input "invertSwitch", "bool", title: "Invert Switch", description: "Flip switch upside down", required: false, defaultValue: false
input "rampRate", "number", title: "Ramp Rate", description: "Seconds to reach full brightness (1-99)", required: false, defaultValue: 1, range: "1..99"
input "powerRestore", "enum", title: "After Power Restore", description: "State after power restore", options:["prremember": "Remember", "proff": "Off", "pron": "On"],defaultValue: "prremember",displayDuringSetup: false
input "doubleTap", "bool", title: "Double Tap", description: "Double Tap limited to max set", required: false, defaultValue: false
input "autoTurnoff", "bool", title: "Auto Off", description: "Light will automatically turn off after set time", required: false, defaultValue: false
input "autoTurnon", "bool", title: "Auto On", description: "Light will automatically turn on after set time", required: false, defaultValue: false
input "offTimer", "number", title: "Off Timer", description: "Time in minutes to automatically turn off", required: false, defaultValue: 60, range: "1..65535"
input "onTimer", "number", title: "On Timer", description: "Time in minutes to automatically turn on", required: false, defaultValue: 60, range: "1..65535"
input "maxBright", "number", title: "Maximum Brightness", description: "Maximum brightness that the light can go to", required: false, defaultValue: 99, range: "1..99"
input "minBright", "number", title: "Minimum Brightness", description: "Minimum brightness that the light can go to", required: false, defaultValue: 1, range: "1..99"
}
/* tiles(scale: 2) {
multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true){
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
attributeState "on", label:'${name}', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#00a0dc", nextState:"turningOff"
attributeState "off", label:'${name}', action:"switch.on", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:"turningOn"
attributeState "turningOn", label:'${name}', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#00a0dc", nextState:"turningOff"
attributeState "turningOff", label:'${name}', action:"switch.on", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:"turningOn"
}
tileAttribute ("device.level", key: "SLIDER_CONTROL") {
attributeState "level", action:"switch level.setLevel"
}
}
standardTile("refresh", "device.switch", width: 2, height: 2, inactiveLabel: false, decoration: "flat") {
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
}
valueTile("level", "device.level", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "level", label:'${currentValue} %', unit:"%", backgroundColor:"#ffffff"
}
main(["switch"])
details(["switch", "level", "refresh"])
}
*/
}
def installed() {
log.debug "installed"
def cmds = []
// Device-Watch simply pings if no device events received for 32min(checkInterval)
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
cmds << mfrGet()
cmds << zwave.versionV1.versionGet().format()
cmds << parmGet(1)
cmds << parmGet(2)
cmds << parmGet(3)
cmds << parmGet(4)
cmds << parmGet(5)
cmds << parmGet(6)
cmds << parmGet(8)
cmds << parmGet(9)
cmds << parmGet(10)
cmds << parmGet(11)
cmds << parmGet(12)
def level = 99
cmds << zwave.basicV1.basicSet(value: level).format()
cmds << zwave.switchMultilevelV1.switchMultilevelGet().format()
return response(delayBetween(cmds,200))
}
def updated(){
// These are needed when parameter defaults are null or non-workable numbers. They are set to the device defaults
def setOffTimer = 60
if (offTimer) {setOffTimer = offTimer}
def setOnTimer = 60
if (onTimer) {setOnTimer = onTimer}
def setRampRate = 1
if (rampRate) {setRampRate = rampRate}
def setMaxBright = 99
if (maxBright) {setMaxBright = maxBright}
def setMinBright = 1
if (minBright) {setMinBright = minBright}
def commands = []
if (getDataValue("MSR") == null) {
def level = 99
commands << mfrGet()
commands << zwave.versionV1.versionGet().format()
commands << zwave.basicV1.basicSet(value: level).format()
commands << zwave.switchMultilevelV1.switchMultilevelGet().format()
}
def setDoubleTap = doubleTap == true ? 1 : 0
def setPowerRestore = powerRestore == "prremember" ? 2 : powerRestore == "proff" ? 0 : 1
def setAutoTurnon = autoTurnon == true ? 1 : 0
def setAutoTurnoff = autoTurnoff == true ? 1 : 0
def setInvertSwitch = invertSwitch == true ? 1 : 0
def setLedIndicator = 0
switch (ledIndicator) {
case "off":
setLedIndicator = 0
break
case "on":
setLedIndicator = 1
break
case "never":
setLedIndicator = 2
break
case "always":
setLedIndicator = 3
break
default:
setLedIndicator = 0
break
}
//parmset takes the parameter number, it's size, and the value - in that order
commands << parmSet(12, 1, setDoubleTap)
commands << parmSet(11, 1, setMaxBright)
commands << parmSet(10, 1, setMinBright)
commands << parmSet(9, 1, setRampRate)
commands << parmSet(8, 1, setPowerRestore)
commands << parmSet(6, 4, setOnTimer)
commands << parmSet(5, 1, setAutoTurnon)
commands << parmSet(4, 4, setOffTimer)
commands << parmSet(3, 1, setAutoTurnoff)
commands << parmSet(2, 1, setLedIndicator)
commands << parmSet(1, 1, setInvertSwitch)
commands << parmGet(12)
commands << parmGet(11)
commands << parmGet(10)
commands << parmGet(9)
commands << parmGet(8)
commands << parmGet(6)
commands << parmGet(5)
commands << parmGet(4)
commands << parmGet(3)
commands << parmGet(2)
commands << parmGet(1)
// Device-Watch simply pings if no device events received for 32min(checkInterval)
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
return response(delayBetween(commands, 500))
}
private getCommandClassVersions() {
[
0x59: 1, // AssociationGrpInfo
0x85: 2, // Association
0x5A: 1, // DeviceResetLocally
0x72: 2, // ManufacturerSpecific
0x73: 1, // Powerlevel
0x86: 1, // Version
0x5E: 2, // ZwaveplusInfo
0x26: 1, // Multilevel Switch
0x70: 1, // Configuration
0x55: 1, //Transport Service
0x6C: 1, //Supervision
0x7A: 1, //Firmware Update Metadata
0x8E: 1, //Multi Channel Association
0x20: 1, // Basic
0x27: 1, // All Switch
//0x9F - what is this class?
]
}
def parse(String description) {
def result = null
// UI Trick to make 99%, which is actually the platform limit, show 100% on the control
if (description.indexOf('command: 2603, payload: 63 63 00') > -1) {
description = description.replaceAll('payload: 63 63 00','payload: 64 64 00')
}
if (description != "updated") {
log.debug "parse() >> zwave.parse($description)"
def cmd = zwave.parse(description, commandClassVersions)
if (cmd) {
result = zwaveEvent(cmd)
}
}
if (result?.name == 'hail' && hubFirmwareLessThan("000.011.00602")) {
result = [result, response(zwave.basicV1.basicGet())]
log.debug "Was hailed: requesting state update"
} else {
log.debug "Parse returned ${result?.descriptionText}"
}
return result
}
def zwaveEvent(hubitat.zwave.commands.basicv1.BasicReport cmd) {
dimmerEvents(cmd)
}
def zwaveEvent(hubitat.zwave.commands.basicv1.BasicSet cmd) {
dimmerEvents(cmd)
}
def zwaveEvent(hubitat.zwave.commands.switchmultilevelv1.SwitchMultilevelReport cmd) {
dimmerEvents(cmd)
}
def zwaveEvent(hubitat.zwave.commands.switchmultilevelv1.SwitchMultilevelSet cmd) {
dimmerEvents(cmd)
}
private dimmerEvents(hubitat.zwave.Command cmd) {
def value = (cmd.value ? "on" : "off")
def result = [createEvent(name: "switch", value: value)]
if (cmd.value && cmd.value <= 100) {
result << createEvent(name: "level", value: cmd.value, unit: "%")
}
return result
}
def zwaveEvent(hubitat.zwave.commands.configurationv1.ConfigurationReport cmd) {
def name = ""
def value = ""
def reportValue = cmd.configurationValue[0]
log.debug "---CONFIGURATION REPORT V1--- ${device.displayName} parameter ${cmd.parameterNumber} with a byte size of ${cmd.size} is set to ${cmd.configurationValue}"
switch (cmd.parameterNumber) {
case 1:
name = "topoff"
value = reportValue == 1 ? "true" : "false"
break
case 2:
switch (reportValue) {
case 0:
value = "off"
break
case 1:
value = "on"
break
case 2:
value = "never"
break
case 3:
value = "always"
break
default:
value = "off"
break
}
name = "ledfollow"
break
case 3:
name = "autooff"
value = reportValue == 1 ? "true" : "false"
break
case 4:
name = "autoofftimer"
value = cmd.configurationValue[3] + (cmd.configurationValue[2] * 0x100) + (cmd.configurationValue[1] * 0x10000) + (cmd.configurationValue[0] * 0x1000000)
break
case 5:
name = "autoon"
value = reportValue == 1 ? "true" : "false"
break
case 6:
name = "autoontimer"
value = cmd.configurationValue[3] + (cmd.configurationValue[2] * 0x100) + (cmd.configurationValue[1] * 0x10000) + (cmd.configurationValue[0] * 0x1000000)
break
case 8:
name = "afterfailure"
switch (reportValue) {
case 0:
value = "off"
break
case 1:
value = "on"
break
case 2:
value = "remember"
break
default:
break
}
case 9:
name = "rampspeed"
value = reportValue
break
case 10:
name = "minbrightness"
value = reportValue
break
case 11:
name = "maxbrightness"
value = reportValue
break
case 12:
name = "double_tap"
value = reportValue == 1 ? "true" : "false"
break
default:
break
}
createEvent([name: name, value: value])
}
def zwaveEvent(hubitat.zwave.commands.hailv1.Hail cmd) {
createEvent([name: "hail", value: "hail", descriptionText: "Switch button was pressed", displayed: false])
}
def zwaveEvent(hubitat.zwave.commands.manufacturerspecificv2.ManufacturerSpecificReport cmd) {
def manufacturerCode = String.format("%04X", cmd.manufacturerId)
def productTypeCode = String.format("%04X", cmd.productTypeId)
def productCode = String.format("%04X", cmd.productId)
def msr = manufacturerCode + "-" + productTypeCode + "-" + productCode
updateDataValue("MSR", msr)
updateDataValue("Manufacturer", "Zooz")
updateDataValue("Manufacturer ID", manufacturerCode)
updateDataValue("Product Type", productTypeCode)
updateDataValue("Product Code", productCode)
createEvent([descriptionText: "$device.displayName MSR: $msr", isStateChange: false])
}
def zwaveEvent(hubitat.zwave.commands.switchmultilevelv1.SwitchMultilevelStopLevelChange cmd) {
[createEvent(name:"switch", value:"on"), response(zwave.switchMultilevelV1.switchMultilevelGet().format())]
}
def zwaveEvent(hubitat.zwave.commands.crc16encapv1.Crc16Encap cmd) {
def versions = commandClassVersions
def version = versions[cmd.commandClass as Integer]
def ccObj = version ? zwave.commandClass(cmd.commandClass, version) : zwave.commandClass(cmd.commandClass)
def encapsulatedCommand = ccObj?.command(cmd.command)?.parse(cmd.data)
if (encapsulatedCommand) {
zwaveEvent(encapsulatedCommand)
}
}
def zwaveEvent(hubitat.zwave.Command cmd) {
// Handles all Z-Wave commands we aren't interested in
[:]
}
def on() {
delayBetween([
zwave.basicV1.basicSet(value: 0xFF).format(),
zwave.switchMultilevelV1.switchMultilevelGet().format()
],2000)
}
def off() {
delayBetween([
zwave.basicV1.basicSet(value: 0x00).format(),
zwave.switchMultilevelV1.switchMultilevelGet().format()
],2000)
}
def setLevel(value) {
log.debug "setLevel >> value: $value"
def valueaux = value as Integer
def level = Math.max(Math.min(valueaux, 99), 0)
if (level > 0) {
sendEvent(name: "switch", value: "on")
} else {
sendEvent(name: "switch", value: "off")
}
sendEvent(name: "level", value: level, unit: "%")
delayBetween ([zwave.basicV1.basicSet(value: level).format(), zwave.switchMultilevelV1.switchMultilevelGet().format()], 2000)
}
def setLevel(value, duration) {
log.debug "setLevel >> value: $value, duration: $duration"
def valueaux = value as Integer
def level = Math.max(Math.min(valueaux, 99), 0)
def dimmingDuration = duration < 128 ? duration : 128 + Math.round(duration / 60)
def getStatusDelay = duration < 128 ? (duration*1000)+2000 : (Math.round(duration / 60)*60*1000)+2000
delayBetween ([zwave.switchMultilevelV2.switchMultilevelSet(value: level, dimmingDuration: dimmingDuration).format(),
zwave.switchMultilevelV1.switchMultilevelGet().format()], getStatusDelay)
}
def poll() {
zwave.switchMultilevelV1.switchMultilevelGet().format()
}
/**
* PING is used by Device-Watch in attempt to reach the Device
* */
def ping() {
refresh()
}
def refresh() {
log.debug "refresh() is called"
def commands = []
if (getDataValue("MSR") == null) {
commands << mfrGet()
commands << zwave.versionV1.versionGet().format()
}
commands << zwave.switchMultilevelV1.switchMultilevelGet().format()
delayBetween(commands,100)
}
def parmSet(parmnum, parmsize, parmval) {
return zwave.configurationV1.configurationSet(scaledConfigurationValue: parmval, parameterNumber: parmnum, size: parmsize).format()
}
def parmGet(parmnum) {
return zwave.configurationV1.configurationGet(parameterNumber: parmnum).format()
}
def mfrGet() {
return zwave.manufacturerSpecificV2.manufacturerSpecificGet().format()
}
def zwaveEvent(hubitat.zwave.commands.versionv1.VersionReport cmd) {
updateDataValue("applicationVersion", "${cmd.applicationVersion}")
updateDataValue("applicationSubVersion", "${cmd.applicationSubVersion}")
updateDataValue("zWaveLibraryType", "${cmd.zWaveLibraryType}")
updateDataValue("zWaveProtocolVersion", "${cmd.zWaveProtocolVersion}")
updateDataValue("zWaveProtocolSubVersion", "${cmd.zWaveProtocolSubVersion}")
}
def zwaveEvent(hubitat.zwave.commands.versionv1.VersionCommandClassReport cmd) {
log.debug "vccr"
def rcc = ""
log.debug "version: ${cmd.commandClassVersion}"
log.debug "class: ${cmd.requestedCommandClass}"
rcc = Integer.toHexString(cmd.requestedCommandClass.toInteger()).toString()
log.debug "${rcc}"
if (cmd.commandClassVersion > 0) {log.debug "0x${rcc}_V${cmd.commandClassVersion}"}
}