-
Notifications
You must be signed in to change notification settings - Fork 14
/
gezwaveplus.groovy
409 lines (349 loc) · 16.4 KB
/
gezwaveplus.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
/**
* GE/Jasco Z-Wave Plus On/Off Switch
*
* Contains code from https://github.com/nuttytree/Nutty-SmartThings/blob/master/devicetypes/nuttytree/ge-jasco-zwave-plus-on-off-switch.src/ge-jasco-zwave-plus-on-off-switch.groovy
*
* Copyright 2020 Chris Nussbaum, Tim Grimley
* Thanks Chris for the original copy of this great code!
*
* 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.
*
* Author: Tim Grimley
* Date: 08/31/2020
*
* Changelog:
*
* 0.12 (09/23/2020) - Support added for double tap and hold, added code to make sure button values updated
* 0.11 (08/31/2020) - Initial Release Updated to Work with New Smartthings App
*
*
* Button Mappings:
*
* ACTION BUTTON# BUTTON ACTION
* Double-Tap Up 1 pressed/held
* Double-Tap Down 2 pressed/held
*
* Note - For double tap hold, tap twice and keep pressed up or down after second tap
* If held does not appear as an option, update any device preference (ie indicator) to add the "held" button value
*/
import groovy.transform.Field
import groovy.json.JsonOutput
metadata {
definition (name: "GE Jasco Z-Wave Plus On Off Switch", namespace: "mwav3", author: "Tim Grimley") {
capability "Actuator"
capability "DoubleTapableButton"
capability "HoldableButton"
capability "Configuration"
capability "Indicator"
capability "Polling"
capability "Refresh"
capability "Sensor"
capability "Switch"
attribute "inverted", "enum", ["inverted", "not inverted"]
command "doubleUp"
command "doubleDown"
command "inverted"
command "notInverted"
// These include version because there are older firmwares that don't support double-tap or the extra association groups
fingerprint mfr:"0063", prod:"4952", model: "3036", ver: "5.20", deviceJoinName: "GE Z-Wave Plus Wall Switch"
fingerprint mfr:"0063", prod:"4952", model: "3036", ver: "5.22", deviceJoinName: "GE Z-Wave Plus Wall Switch"
fingerprint mfr:"0063", prod:"4952", model: "3037", ver: "5.20", deviceJoinName: "GE Z-Wave Plus Toggle Switch"
fingerprint mfr:"0063", prod:"4952", model: "3038", ver: "5.20", deviceJoinName: "GE Z-Wave Plus Toggle Switch"
fingerprint mfr:"0063", prod:"4952", model: "3130", ver: "5.20", deviceJoinName: "Jasco Z-Wave Plus Wall Switch"
fingerprint mfr:"0063", prod:"4952", model: "3131", ver: "5.20", deviceJoinName: "Jasco Z-Wave Plus Toggle Switch"
fingerprint mfr:"0063", prod:"4952", model: "3132", ver: "5.20", deviceJoinName: "Jasco Z-Wave Plus Toggle Switch"
}
simulator {
status "on": "command: 2003, payload: FF"
status "off": "command: 2003, payload: 00"
// reply messages
reply "2001FF,delay 5000,2602": "command: 2603, payload: FF"
reply "200100,delay 5000,2602": "command: 2603, payload: 00"
}
preferences {
input "ledIndicator", "enum", title: "LED Indicator", description: "Turn LED indicator... ", required: false, options:["on": "When On", "off": "When Off", "never": "Never"], defaultValue: "off"
input "invertSwitch", "bool", title: "Invert Switch", description: "Invert switch? ", required: false
input (
type: "paragraph",
element: "paragraph",
title: "Configure Association Groups:",
description: "Devices in association group 2 will receive Basic Set commands directly from the switch when it is turned on or off. Use this to control another device as if it was connected to this switch.\n\n" +
"Devices in association group 3 will receive Basic Set commands directly from the switch when it is double tapped up or down.\n\n" +
"Devices are entered as a comma delimited list of IDs in hexadecimal format."
)
input (
name: "requestedGroup2",
title: "Association Group 2 Members (Max of 5):",
type: "text",
required: false
)
input (
name: "requestedGroup3",
title: "Association Group 3 Members (Max of 4):",
type: "text",
required: false
)
}
}
// parse events into attributes
def parse(String description) {
log.debug "description: $description"
def result = null
def cmd = zwave.parse(description, [0x20: 1, 0x25: 1, 0x56: 1, 0x70: 2, 0x72: 2, 0x85: 2])
if (cmd) {
result = zwaveEvent(cmd)
log.debug "Parsed ${cmd} to ${result.inspect()}"
} else {
log.debug "Non-parsed event: ${description}"
}
if (!device.currentValue("supportedButtonValues")) {
sendEvent(name: "supportedButtonValues", value:JsonOutput.toJson(["pushed","held"]), displayed:false)
}
result
}
def zwaveEvent(hubitat.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(hubitat.zwave.commands.basicv1.BasicReport cmd) {
log.debug "---BASIC REPORT V1--- ${device.displayName} sent ${cmd}"
createEvent(name: "switch", value: cmd.value ? "on" : "off", type: "physical")
}
def zwaveEvent(hubitat.zwave.commands.basicv1.BasicSet cmd) {
log.debug "---Double Tap--- ${device.displayName} sent ${cmd}"
if (cmd.value == 255) {
createEvent(name: "button", value: "pushed", data: [buttonNumber: 1], descriptionText: "Double-tap up (button 1) on $device.displayName", isStateChange: true, type: "physical")
}
else if (cmd.value == 0) {
createEvent(name: "button", value: "pushed", data: [buttonNumber: 2], descriptionText: "Double-tap down (button 2) on $device.displayName", isStateChange: true, type: "physical")
}
}
def zwaveEvent(hubitat.zwave.commands.switchmultilevelv3.SwitchMultilevelStartLevelChange cmd) {
log.debug "---Double Tap and Hold--- ${device.displayName} sent ${cmd}"
if (cmd.startLevel == 0) {
createEvent(name: "button", value: "held", data: [buttonNumber: 1], descriptionText: "Double-tap up and hold (button 1) on $device.displayName", isStateChange: true, type: "physical")
}
else if (cmd.startLevel == 255) {
createEvent(name: "button", value: "held", data: [buttonNumber: 2], descriptionText: "Double-tap down and hold (button 2) on $device.displayName", isStateChange: true, type: "physical")
}
}
def zwaveEvent(hubitat.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}"
if (cmd.groupingIdentifier == 3) {
if (cmd.nodeId.contains(zwaveHubNodeId)) {
createEvent(name: "numberOfButtons", value: 2, displayed: false)
sendEvent(name: "supportedButtonValues", value:JsonOutput.toJson(["pushed","held"]), displayed:false)
}
else {
sendHubCommand(new hubitat.device.HubAction(zwave.associationV2.associationSet(groupingIdentifier: 3, nodeId: zwaveHubNodeId).format()))
sendHubCommand(new hubitat.device.HubAction(zwave.associationV2.associationGet(groupingIdentifier: 3).format()))
createEvent(name: "numberOfButtons", value: 0, displayed: false)
}
}
}
def zwaveEvent(hubitat.zwave.commands.configurationv2.ConfigurationReport cmd) {
log.debug "---CONFIGURATION REPORT V2--- ${device.displayName} sent ${cmd}"
def name = ""
def value = ""
def reportValue = cmd.configurationValue[0]
switch (cmd.parameterNumber) {
case 3:
name = "indicatorStatus"
value = reportValue == 1 ? "when on" : reportValue == 2 ? "never" : "when off"
break
case 4:
name = "inverted"
value = reportValue == 1 ? "true" : "false"
break
default:
break
}
createEvent([name: name, value: value, displayed: false])
}
def zwaveEvent(hubitat.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd) {
log.debug "---BINARY SWITCH REPORT V1--- ${device.displayName} sent ${cmd}"
createEvent(name: "switch", value: cmd.value ? "on" : "off", type: "digital")
}
def zwaveEvent(hubitat.zwave.commands.manufacturerspecificv2.ManufacturerSpecificReport cmd) {
log.debug "---MANUFACTURER SPECIFIC REPORT V2---"
log.debug "manufacturerId: ${cmd.manufacturerId}"
log.debug "manufacturerName: ${cmd.manufacturerName}"
state.manufacturer=cmd.manufacturerName
log.debug "productId: ${cmd.productId}"
log.debug "productTypeId: ${cmd.productTypeId}"
def msr = String.format("%04X-%04X-%04X", cmd.manufacturerId, cmd.productTypeId, cmd.productId)
updateDataValue("MSR", msr)
createEvent([descriptionText: "$device.displayName MSR: $msr", isStateChange: false])
}
def zwaveEvent(hubitat.zwave.commands.versionv1.VersionReport cmd) {
def fw = "${cmd.applicationVersion}.${cmd.applicationSubVersion}"
updateDataValue("fw", fw)
log.debug "---VERSION REPORT V1--- ${device.displayName} is running firmware version: $fw, Z-Wave version: ${cmd.zWaveProtocolVersion}.${cmd.zWaveProtocolSubVersion}"
}
def zwaveEvent(hubitat.zwave.Command cmd) {
log.warn "${device.displayName} received unhandled command: ${cmd}"
}
// handle commands
def configure() {
def cmds = []
// Get current config parameter values
cmds << zwave.configurationV2.configurationGet(parameterNumber: 3).format()
cmds << zwave.configurationV2.configurationGet(parameterNumber: 4).format()
// Add the hub to association group 3 to get double-tap notifications
cmds << zwave.associationV2.associationSet(groupingIdentifier: 3, nodeId: zwaveHubNodeId).format()
cmds << zwave.associationV2.associationGet(groupingIdentifier: 3).format()
delayBetween(cmds,500)
}
def updated() {
if (state.lastUpdated && now() <= state.lastUpdated + 3000) return
state.lastUpdated = now()
def nodes = []
def cmds = []
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
}
switch (ledIndicator) {
case "on":
indicatorWhenOn()
break
case "off":
indicatorWhenOff()
break
case "never":
indicatorNever()
break
default:
indicatorWhenOff()
break
}
switch (invertSwitch) {
case "false":
notInverted()
break
case "true":
inverted()
break
default:
notInverted()
}
sendEvent(name: "numberOfButtons", value: 2, displayed: false)
sendEvent(name: "supportedButtonValues", value:JsonOutput.toJson(["pushed","held"]), displayed:false)
sendHubCommand(cmds.collect{ new hubitat.device.HubAction(it.format()) }, 500)
log.debug "---Preferences Updated--- ${device.displayName} sent ${cmds}"
}
void indicatorWhenOn() {
sendEvent(name: "indicatorStatus", value: "when on", display: false)
sendHubCommand(new hubitat.device.HubAction(zwave.configurationV2.configurationSet(configurationValue: [1], parameterNumber: 3, size: 1).format()))
}
void indicatorWhenOff() {
sendEvent(name: "indicatorStatus", value: "when off", display: false)
sendHubCommand(new hubitat.device.HubAction(zwave.configurationV2.configurationSet(configurationValue: [0], parameterNumber: 3, size: 1).format()))
}
void indicatorNever() {
sendEvent(name: "indicatorStatus", value: "never", display: false)
sendHubCommand(new hubitat.device.HubAction(zwave.configurationV2.configurationSet(configurationValue: [2], parameterNumber: 3, size: 1).format()))
}
void inverted() {
sendEvent(name: "inverted", value: "inverted", display: false)
sendHubCommand(new hubitat.device.HubAction(zwave.configurationV2.configurationSet(configurationValue: [1], parameterNumber: 4, size: 1).format()))
}
void notInverted() {
sendEvent(name: "inverted", value: "not inverted", display: false)
sendHubCommand(new hubitat.device.HubAction(zwave.configurationV2.configurationSet(configurationValue: [0], parameterNumber: 4, size: 1).format()))
}
def doubleUp() {
sendEvent(name: "button", value: "pushed", data: [buttonNumber: 1], descriptionText: "Double-tap up (button 1) on $device.displayName", isStateChange: true, type: "digital")
}
def doubleDown() {
sendEvent(name: "button", value: "pushed", data: [buttonNumber: 2], descriptionText: "Double-tap down (button 2) on $device.displayName", isStateChange: true, type: "digital")
}
def poll() {
def cmds = []
cmds << zwave.switchBinaryV1.switchBinaryGet().format()
if (getDataValue("MSR") == null) {
cmds << zwave.manufacturerSpecificV1.manufacturerSpecificGet().format()
}
delayBetween(cmds,500)
}
def refresh() {
def cmds = []
cmds << zwave.switchBinaryV1.switchBinaryGet().format()
cmds << zwave.configurationV2.configurationGet(parameterNumber: 3).format()
cmds << zwave.configurationV2.configurationGet(parameterNumber: 4).format()
cmds << zwave.associationV2.associationGet(groupingIdentifier: 3).format()
if (getDataValue("MSR") == null) {
cmds << zwave.manufacturerSpecificV1.manufacturerSpecificGet().format()
}
delayBetween(cmds,500)
}
def on() {
delayBetween([
zwave.basicV1.basicSet(value: 0xFF).format(),
zwave.switchBinaryV1.switchBinaryGet().format()
], 100)
}
def off() {
delayBetween([
zwave.basicV1.basicSet(value: 0x00).format(),
zwave.switchBinaryV1.switchBinaryGet().format()
], 100)
}
def initialize() {
sendEvent(name: "numberOfButtons", value: 2, displayed: false)
sendEvent(name: "supportedButtonValues", value:JsonOutput.toJson(["pushed","held"]), displayed:false)
}
// Private Methods
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 (it would break double-tap)."
}
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
}