forked from SmartThingsCommunity/SmartThingsPublic
/
ws100-switch.groovy
445 lines (383 loc) · 16.2 KB
/
ws100-switch.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
/**
* HomeSeer HS-WS100+
*
* Copyright 2016, 2017 DarwinsDen.com
*
* For button mappings, device parameter information and images, questions or to provide feedback on this device handler,
* please visit:
*
* darwinsden.com/homeseer100plus/
*
* 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: Darwin@DarwinsDen.com
* Date: 2016-04-08
*
*
* Changelog:
*
* 1.05 (03/29/2021) - Update to support new button values (Tim Grimley)
* 1.04 (08/13/2020) - Merge pull request from mikerossman for updates to better support new SmartThings app
* 1.03 (11/14/2017) - Turn off firmware event log, correct physical button setting for some presses, remove 100ms delay in instant status
* 1.02 (06/25/2017) - Pulled in @stephack's changes to include button 7/8 events when triggered remotely
* 1.01 (01/16/2017) - Corrected advertised number of buttons (8)
* 1.00 (01/14/2017) - Added button 7 (single tap up) and button 8 (single tap down). Added firmware version display.
* 0.12 (06/03/2016) - Added press type indicator to display last tap/hold press status
* 0.11 (05/28/2016) - Set numberOfButtons attribute for ease of use with CoRE and other SmartApps. Corrected physical/digital states.
* 0.10 (04/08/2016) - Initial 0.1 Beta
*
*
* Button Mappings NOTE - THIS IS A BREAKING CHANGE from any other DTH and uses a single button.
* ALL prior automations will need to be re-programmed or updated when updating this DTH from other versions:
*
* ACTION BUTTON# BUTTON ACTION
* Single-Tap Up 1 up
* Single-Tap Down 1 down
* Double-Tap Up 1 up_2x
* Double-Tap Down 1 down_2x
* Triple-Tap Up 1 up_3x
* Triple-Tap Down 1 down_3x
* Hold Up 1 up_hold
* Hold Down 1 down_hold
*/
import groovy.transform.Field
import groovy.json.JsonOutput
metadata {
definition (name: "WS100 Switch", namespace: "darwinsden", author: "darwin@darwinsden.com") {
capability "Actuator"
capability "Indicator"
capability "Switch"
capability "Button"
capability "Polling"
capability "Refresh"
capability "Sensor"
capability "Configuration"
capability "Health Check"
command "tapUp2"
command "tapDown2"
command "tapUp3"
command "tapDown3"
command "holdUp"
command "holdDown"
fingerprint mfr: "000C", prod: "4447", model: "3033"
// fingerprint deviceId: "0x1001", inClusters: "0x5E, 0x86, 0x72, 0x5A, 0x85, 0x59, 0x73, 0x25, 0x27, 0x70, 0x2C, 0x2B, 0x5B, 0x7A", outClusters: "0x5B"
}
// simulator metadata
simulator {
status "on": "command: 2003, payload: FF"
status "off": "command: 2003, payload: 00"
// reply messages
reply "2001FF,delay 100,2502": "command: 2503, payload: FF"
reply "200100,delay 100,2502": "command: 2503, payload: 00"
}
preferences {
input "forceupdate", "bool", title: "Force Settings Update/Refresh?", description: "Toggle to force settings update", requied: false
}
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.Home.home30", backgroundColor: "#79b821"
attributeState "off", label: '${name}', action: "switch.on", icon: "st.Home.home30", backgroundColor: "#ffffff"
}
tileAttribute("device.status", key: "SECONDARY_CONTROL") {
attributeState("default", label:'${currentValue}', unit:"")
}
}
standardTile("tapUp2", "device.button", width: 2, height: 2, decoration: "flat") {
state "default", label: "Tap Up x2", backgroundColor: "#ffffff", action: "tapUp2", icon: "st.Home.home30"
}
standardTile("tapDown2", "device.button", width: 2, height: 2, decoration: "flat") {
state "default", label: "Tap Down x2", backgroundColor: "#ffffff", action: "tapDown2", icon: "st.Home.home30"
}
standardTile("tapUp3", "device.button", width: 2, height: 2, decoration: "flat") {
state "default", label: "Tap Up x3", backgroundColor: "#ffffff", action: "tapUp3", icon: "st.Home.home30"
}
standardTile("tapDown3", "device.button", width: 2, height: 2, decoration: "flat") {
state "default", label: "Tap Down x3", backgroundColor: "#ffffff", action: "tapDown3", icon: "st.Home.home30"
}
standardTile("holdUp", "device.button", width: 2, height: 2, decoration: "flat") {
state "default", label: "Hold Up", backgroundColor: "#ffffff", action: "holdUp", icon: "st.Home.home30"
}
standardTile("holdDown", "device.button", width: 2, height: 2, decoration: "flat") {
state "default", label: "Hold Down", backgroundColor: "#ffffff", action: "holdDown", icon: "st.Home.home30"
}
standardTile("indicator", "device.indicatorStatus", width: 2, height: 2, inactiveLabel: false, decoration: "flat") {
state "when off", action:"indicator.indicatorWhenOn", icon:"st.indicators.lit-when-off"
state "when on", action:"indicator.indicatorNever", icon:"st.indicators.lit-when-on"
state "never", action:"indicator.indicatorWhenOff", icon:"st.indicators.never-lit"
}
standardTile("refresh", "device.switch", width: 2, height: 2, inactiveLabel: false, decoration: "flat") {
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
}
valueTile("firmwareVersion", "device.firmwareVersion", width:2, height: 2, decoration: "flat", inactiveLabel: false) {
state "default", label: '${currentValue}'
}
main "switch"
details(["switch","tapUp2","tapUp3","holdUp","tapDown2","tapDown3","holdDown","indicator","firmwareVersion","refresh"])
}
}
def parse(String description) {
def result = null
def cmd = zwave.parse(description, [0x20: 1, 0x70: 1])
if (cmd) {
result = zwaveEvent(cmd)
}
if (!result){
log.debug "Parse returned ${result} for command ${cmd}"
}
else {
log.debug "Parse returned ${result}"
}
return result
}
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) {
createEvent([name: "switch", value: cmd.value ? "on" : "off", type: "physical"])
}
def zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd) {
createEvent([name: "switch", value: cmd.value ? "on" : "off", type: "digital"])
}
def zwaveEvent(physicalgraph.zwave.commands.configurationv1.ConfigurationReport cmd) {
def value = "when off"
if (cmd.configurationValue[0] == 1) {value = "when on"}
if (cmd.configurationValue[0] == 2) {value = "never"}
createEvent([name: "indicatorStatus", value: value, display: false])
}
def zwaveEvent(physicalgraph.zwave.commands.hailv1.Hail cmd) {
createEvent([name: "hail", value: "hail", descriptionText: "Switch button was pressed", displayed: false])
}
def zwaveEvent(physicalgraph.zwave.commands.manufacturerspecificv2.ManufacturerSpecificReport cmd) {
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)
setFirmwareVersion()
createEvent([descriptionText: "$device.displayName MSR: $msr", isStateChange: false])
}
def zwaveEvent(physicalgraph.zwave.commands.versionv1.VersionReport cmd) {
log.debug ("received Version Report")
log.debug "applicationVersion: ${cmd.applicationVersion}"
log.debug "applicationSubVersion: ${cmd.applicationSubVersion}"
state.firmwareVersion=cmd.applicationVersion+'.'+cmd.applicationSubVersion
log.debug "zWaveLibraryType: ${cmd.zWaveLibraryType}"
log.debug "zWaveProtocolVersion: ${cmd.zWaveProtocolVersion}"
log.debug "zWaveProtocolSubVersion: ${cmd.zWaveProtocolSubVersion}"
setFirmwareVersion()
createEvent([descriptionText: "Firmware V"+state.firmwareVersion, isStateChange: false])
}
def zwaveEvent(physicalgraph.zwave.Command cmd) {
// Handles all Z-Wave commands we aren't interested in
log.debug (cmd)
createEvent([:])
}
def on() {
sendEvent(tapUp1Response("digital"))
delayBetween([
zwave.basicV1.basicSet(value: 0xFF).format(),
zwave.switchBinaryV1.switchBinaryGet().format()
])
}
def off() {
sendEvent(tapDown1Response("digital"))
delayBetween([
zwave.basicV1.basicSet(value: 0x00).format(),
zwave.switchBinaryV1.switchBinaryGet().format()
])
}
def poll() {
delayBetween([
zwave.switchBinaryV1.switchBinaryGet().format(),
zwave.manufacturerSpecificV1.manufacturerSpecificGet().format()
])
}
def setFirmwareVersion() {
def versionInfo = ''
if (state.manufacturer)
{
versionInfo=state.manufacturer+' '
}
if (state.firmwareVersion)
{
versionInfo=versionInfo+"Firmware V"+state.firmwareVersion
}
else
{
versionInfo=versionInfo+"Firmware unknown"
}
sendEvent(name: "firmwareVersion", value: versionInfo, isStateChange: true, displayed: false)
}
def indicatorWhenOn() {
sendEvent(name: "indicatorStatus", value: "when on", display: false)
zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 3, size: 1).format()
}
def indicatorWhenOff() {
sendEvent(name: "indicatorStatus", value: "when off", display: false)
zwave.configurationV1.configurationSet(configurationValue: [0], parameterNumber: 3, size: 1).format()
}
def indicatorNever() {
sendEvent(name: "indicatorStatus", value: "never", display: false)
zwave.configurationV1.configurationSet(configurationValue: [2], parameterNumber: 3, size: 1).format()
}
def invertSwitch(invert=true) {
if (invert) {
zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 4, size: 1).format()
}
else {
zwave.configurationV1.configurationSet(configurationValue: [0], parameterNumber: 4, size: 1).format()
}
}
def zwaveEvent(physicalgraph.zwave.commands.centralscenev1.CentralSceneNotification cmd) {
log.debug("sceneNumber: ${cmd.sceneNumber} keyAttributes: ${cmd.keyAttributes}")
def result = []
switch (cmd.sceneNumber) {
case 1:
// Up
switch (cmd.keyAttributes) {
case 0:
// Press Once
result += createEvent(tapUp1Response("physical"))
result += createEvent([name: "switch", value: "on", type: "physical"])
break
case 1:
result=createEvent([name: "switch", value: "on", type: "physical"])
break
case 2:
// Hold
result += createEvent(holdUpResponse("physical"))
result += createEvent([name: "switch", value: "on", type: "physical"])
break
case 3:
// 2 Times
result=createEvent(tapUp2Response("physical"))
break
case 4:
// 3 Three times
result=createEvent(tapUp3Response("physical"))
break
default:
log.debug ("unexpected up press keyAttribute: $cmd.keyAttributes")
}
break
case 2:
// Down
switch (cmd.keyAttributes) {
case 0:
// Press Once
result += createEvent(tapDown1Response("physical"))
result += createEvent([name: "switch", value: "off", type: "physical"])
break
case 1:
result=createEvent([name: "switch", value: "off", type: "physical"])
break
case 2:
// Hold
result += createEvent(holdDownResponse("physical"))
result += createEvent([name: "switch", value: "off", type: "physical"])
break
case 3:
// 2 Times
result=createEvent(tapDown2Response("physical"))
break
case 4:
// 3 Times
result=createEvent(tapDown3Response("physical"))
break
default:
log.debug ("unexpected down press keyAttribute: $cmd.keyAttributes")
}
break
default:
// unexpected case
log.debug ("unexpected scene: $cmd.sceneNumber")
}
return result
}
def tapUp1Response(String buttonType) {
sendEvent(name: "status" , value: "Tap ▲")
[name: "button", value: "up", data: [buttonNumber: "1"], descriptionText: "$device.displayName Tap-Up-1 pressed",
isStateChange: true, type: "$buttonType"]
}
def tapDown1Response(String buttonType) {
sendEvent(name: "status" , value: "Tap ▼")
[name: "button", value: "down", data: [buttonNumber: "1"], descriptionText: "$device.displayName Tap-Down-1 pressed",
isStateChange: true, type: "$buttonType"]
}
def tapUp2Response(String buttonType) {
sendEvent(name: "status" , value: "Tap ▲▲")
[name: "button", value: "up_2x", data: [buttonNumber: "1"], descriptionText: "$device.displayName Tap-Up-2 pressed",
isStateChange: true, type: "$buttonType"]
}
def tapDown2Response(String buttonType) {
sendEvent(name: "status" , value: "Tap ▼▼")
[name: "button", value: "down_2x", data: [buttonNumber: "1"], descriptionText: "$device.displayName Tap-Down-2 pressed",
isStateChange: true, type: "$buttonType"]
}
def tapUp3Response(String buttonType) {
sendEvent(name: "status" , value: "Tap ▲▲▲")
[name: "button", value: "up_3x", data: [buttonNumber: "1"], descriptionText: "$device.displayName Tap-Up-3 pressed",
isStateChange: true, type: "$buttonType"]
}
def tapDown3Response(String buttonType) {
sendEvent(name: "status" , value: "Tap ▼▼▼")
[name: "button", value: "down_3x", data: [buttonNumber: "1"], descriptionText: "$device.displayName Tap-Down-3 pressed",
isStateChange: true, type: "$buttonType"]
}
def holdUpResponse(String buttonType) {
sendEvent(name: "status" , value: "Hold ▲")
[name: "button", value: "up_hold", data: [buttonNumber: "1"], descriptionText: "$device.displayName Hold-Up pressed",
isStateChange: true, type: "$buttonType"]
}
def holdDownResponse(String buttonType) {
sendEvent(name: "status" , value: "Hold ▼")
[name: "button", value: "down_hold", data: [buttonNumber: "1"], descriptionText: "$device.displayName Hold-Down pressed",
isStateChange: true, type: "$buttonType"]
}
def tapUp2() {
sendEvent(tapUp2Response("digital"))
}
def tapDown2() {
sendEvent(tapDown2Response("digital"))
}
def tapUp3() {
sendEvent(tapUp3Response("digital"))
}
def tapDown3() {
sendEvent(tapDown3Response("digital"))
}
def holdUp() {
sendEvent(holdUpResponse("digital"))
}
def holdDown() {
sendEvent(holdDownResponse("digital"))
}
def configure() {
sendEvent(name: "numberOfButtons", value: 1, displayed: false)
sendEvent(name: "supportedButtonValues", value:JsonOutput.toJson(["up","down","up_hold","down_hold","up_2x","down_2x","up_3x","down_3x"]), displayed:false)
def commands = []
commands << zwave.manufacturerSpecificV1.manufacturerSpecificGet().format()
commands << zwave.versionV1.versionGet().format()
commands << zwave.switchBinaryV1.switchBinaryGet().format()
delayBetween(commands,500)
log.debug "---Configure Called--- ${device.displayName} sent ${commands}"
}
def refresh() {
configure()
}
def updated() {
configure()
}
def initialize() {
configure()
}