forked from Nakmans/smartthings-zigbee-device-handlers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVesternet VES-ZB-MOT-019 Motor Controller.groovy
289 lines (268 loc) · 11.9 KB
/
Vesternet VES-ZB-MOT-019 Motor Controller.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
/**
* Vesternet VES-ZB-MOT-019 Motor Controller
*
*/
import groovy.json.JsonOutput
import physicalgraph.zigbee.zcl.DataType
metadata {
definition (name: "Vesternet VES-ZB-MOT-019 Motor Controller", namespace: "Vesternet", author: "Vesternet", mcdSync:true, ocfDeviceType: "oic.d.blind", mnmn: "SmartThings", vid: "generic-shade-3") {
capability "Window Shade"
capability "Window Shade Level"
capability "Switch Level"
capability "Actuator"
capability "Refresh"
capability "Configuration"
command "stop"
fingerprint profileId: "0104", endpointId:"01", inClusters: "0000,0003,0004,0005,0006,0008,0102,0B05,1000", outClusters: "0019", manufacturer: "Sunricher", model: "HK-ZCC-A", deviceJoinName: "Vesternet VES-ZB-MOT-019 Motor Controller"
}
preferences {
input name: "logEnable", type: "bool", title: "Debug"
}
}
def installed() {
device.updateSetting("logEnable", [value: "true", type: "bool"])
logDebug("installed called")
runIn(1800,logsOff)
}
def updated() {
logDebug("updated called")
log.warn("debug logging is: ${settings.logEnable != false}")
sendHubCommand(configureandrefresh())
state.clear()
unschedule()
if (settings.logEnable) runIn(1800,logsOff)
}
void parse(String description) {
logDebug("parse called")
logDebug("got description: ${description}")
def event
if (!(description.startsWith("catchall"))) {
event = zigbee.getEvent(description)
}
if (event) {
logDebug("got event: ${event}")
if (event.name == "switch") {
def type = "physical"
def descriptionText = "${device.displayName} was turned ${event.value}"
if (device.currentValue("switch") && event.value == device.currentValue("switch")) {
descriptionText = "${device.displayName} is ${event.value}"
}
if (action == "digitalsetlevel" || action == "digitalopen" || action == "digitalclose") {
logDebug("action is ${device.currentValue("action")}")
type = "digital"
sendEvent(getEvent([name: "action", value: "unknown", isStateChange: true, displayed: false]))
}
sendEvent(getEvent([name: "switch", value: event.value, type: type, descriptionText: descriptionText]))
}
else {
logDebug("skipped")
}
}
else {
def descriptionMap = zigbee.parseDescriptionAsMap(description)
if (description.startsWith("read attr")) {
descriptionMap.command = "01"
}
def events = []
getEvents(descriptionMap, events)
if (events) {
events.each {
if (it) {
sendEvent(getEvent(it))
}
}
}
else {
log.warn("Unhandled command: ${descriptionMap}")
}
}
}
def getEvents(descriptionMap, events) {
logDebug("getEvents called")
logDebug("got descriptionMap: ${descriptionMap}")
def command = "zigbee command ignored"
switch (descriptionMap.command) {
case "07":
command = "configure reporting response"
break
case "0B":
command = "default response"
break
case "01":
command = "read attributes response"
break
case "0A":
command = "report attributes"
break
}
def endpoint = descriptionMap.sourceEndpoint ?: descriptionMap.endpoint ?: "unknown"
logDebug("got endpoint: ${endpoint}")
if (endpoint == "01") {
if (descriptionMap.cluster == "0102" || descriptionMap.clusterId == "0102" || descriptionMap.clusterInt == 258) {
if (descriptionMap.command == "0A" || descriptionMap.command == "01") {
if (descriptionMap.attrId == "0007" || descriptionMap.attrInt == 0) {
logDebug("window covering (0000) window covering type report")
def levelValue = zigbee.convertHexToInt(descriptionMap.value)
logDebug("window covering type report is ${levelValue}")
def windowCoveringTypes = [ 0: "Rollershade", 1: "Rollershade - 2 Motor", 2: "Rollershade - Exterior", 3: "Rollershade - Exterior - 2 Motor", 4: "Drapery", 5: "Awning", 6: "Shutter", 7: "Tilt Blind - Tilt Only", 8: "Tilt Blind - Lift and Tilt", 9: "Projector Screen" ]
logDebug("window covering type is ${windowCoveringTypes[levelValue]}")
events.add(getEvent([name: "windowCoveringType", value: windowCoveringTypes[levelValue] ?: "unknown" , isStateChange: true, displayed: false]))
}
else if (descriptionMap.attrId == "0008" || descriptionMap.attrInt == 8) {
logDebug("window covering (0008) current position lift percentage report")
def levelValue = zigbee.convertHexToInt(descriptionMap.value)
logDebug("current position lift percentage report is ${levelValue}")
def descriptionText = "${device.displayName} was set to ${levelValue}%"
def currentValue = device.currentValue("shadeLevel") ?: "unknown"
if (levelValue == currentValue) {
descriptionText = "${device.displayName} is ${levelValue}%"
}
def type = "physical"
def action = device.currentValue("action") ?: "standby"
if (action == "digitalsetlevel" || action == "digitalopen" || action == "digitalclose") {
logDebug("action is ${action}")
type = "digital"
events.add(getEvent([name: "action", value: "standby", isStateChange: true, displayed: false]))
logDebug("action set to standby")
}
events.add(getEvent([name: "shadeLevel", value: levelValue, unit: "%", type: type, descriptionText: descriptionText]))
events.add(getEvent([name: "level", value: levelValue, unit: "%", type: type, descriptionText: descriptionText]))
if (levelValue == 0) {
events.add(getEvent([name: "windowShade", value: "closed", type: type, descriptionText: "${device.displayName} is closed"]))
}
else if (levelValue == 100) {
events.add(getEvent([name: "windowShade", value: "open", type: type, descriptionText: "${device.displayName} is open"]))
}
else {
events.add(getEvent([name: "windowShade", value: "partially open", type: type, descriptionText: "${device.displayName} is partially open"]))
}
}
else {
logDebug("window covering (0102) attribute skipped")
}
}
else {
logDebug("window covering (0102) command (${command}) skipped")
}
}
else {
logDebug("skipped")
}
}
else {
logDebug("skipped")
}
if (descriptionMap.additionalAttrs) {
logDebug("got additionalAttrs: ${descriptionMap.additionalAttrs}")
descriptionMap.additionalAttrs.each {
it.sourceEndpoint = descriptionMap.endpoint
it.endpoint = descriptionMap.endpoint
it.clusterInt = descriptionMap.clusterInt
it.cluster = descriptionMap.cluster
it.clusterId = descriptionMap.clusterId
it.command = descriptionMap.command
events.add(getEvents(it, events))
}
}
}
def configure() {
logDebug("configure called")
def cmds = zigbee.configureReporting(0x0102, 0x0008, DataType.UINT8, 0, 0x0E10, 1) + zigbee.configureReporting(0x0102, 0x0009, DataType.UINT8, 0, 0x0E10, 1)
logDebug("sending ${cmds}")
return cmds
}
def refresh() {
logDebug("refresh called")
def cmds = zigbee.readAttribute(0x0102, 0x0000) + zigbee.readAttribute(0x0102, 0x0007) + zigbee.readAttribute(0x0102, 0x0008) + zigbee.readAttribute(0x0102, 0x0009)
logDebug("sending ${cmds}")
return cmds
}
def configureandrefresh() {
logDebug("configureandrefresh called")
def cmds = zigbee.configureReporting(0x0102, 0x0008, DataType.UINT8, 0, 0x0E10, 1) + zigbee.configureReporting(0x0102, 0x0009, DataType.UINT8, 0, 0x0E10, 1) + zigbee.readAttribute(0x0102, 0x0000) + zigbee.readAttribute(0x0102, 0x0007) + zigbee.readAttribute(0x0102, 0x0008) + zigbee.readAttribute(0x0102, 0x0009)
logDebug("sending ${cmds}")
return cmds
}
def open() {
logDebug("open called")
def cmd = zigbee.command(0x0102, 0x0)
logDebug("sending ${cmd}")
sendEvent(getEvent([name: "action", value: "digitalopen", isStateChange: true, displayed: false]))
sendEvent(getEvent([name: "windowShade", value: "opening", type: "digital", descriptionText: "${device.displayName} is opening"]))
return cmd
}
def close() {
logDebug("close called")
def cmd = zigbee.command(0x0102, 0x1)
logDebug("sending ${cmd}")
sendEvent(getEvent([name: "action", value: "digitalclose", isStateChange: true, displayed: false]))
sendEvent(getEvent([name: "windowShade", value: "closing", type: "digital", descriptionText: "${device.displayName} is closing"]))
return cmd
}
def setLevel(level, duration = 1) {
logDebug("setLevel called")
if(level > 99) level = 99
if(level < 0) level = 99
def cmd = zigbee.command(0x0102, 0x5, intTo8bitUnsignedHex(level.toInteger()))
logDebug("sending ${cmd}")
sendEvent(getEvent([name: "action", value: "digitalsetlevel", isStateChange: true, displayed: false]))
def currentValue = device.currentValue("shadeLevel") ?: "unknown"
if (level < currentValue) {
sendEvent(getEvent([name: "windowShade", value: "closing", type: "digital", descriptionText: "${device.displayName} is closing"]))
}
else if (level > currentValue) {
sendEvent(getEvent([name: "windowShade", value: "opening", type: "digital", descriptionText: "${device.displayName} is opening"]))
}
return cmd
}
def startLevelChange(direction, duration = 30) {
logDebug("startLevelChange called")
def upDown = direction == "down" ? 1 : 0
def cmd = zigbee.command(0x0102, intTo8bitUnsignedHex(upDown.toInteger()))
logDebug("sending ${cmd}")
sendEvent(getEvent([name: "action", value: "digitalsetlevel", isStateChange: true, displayed: false]))
def currentValue = device.currentValue("shadeLevel") ?: "unknown"
if (level < currentValue) {
sendEvent(getEvent([name: "windowShade", value: "closing", type: "digital", descriptionText: "${device.displayName} is closing"]))
}
else if (level > currentValue) {
sendEvent(getEvent([name: "windowShade", value: "opening", type: "digital", descriptionText: "${device.displayName} is opening"]))
}
return cmd
}
def stopLevelChange() {
logDebug("stopLevelChange called")
def cmd = zigbee.command(0x0102, 0x2)
logDebug("sending ${cmd}")
sendEvent(getEvent([name: "action", value: "digitalsetlevel", isStateChange: true, displayed: false]))
sendEvent(getEvent([name: "windowShade", value: "partially open", type: "digital", descriptionText: "${device.displayName} is stopping"]))
return cmd
}
def pause() {
logDebug("pause called")
stopLevelChange()
}
def stop() {
logDebug("stop called")
stopLevelChange()
}
def getEvent(event) {
logDebug("getEvent called data: ${event}")
return createEvent(event)
}
def logDebug(msg) {
if (settings.logEnable != false) {
log.debug("${msg}")
}
}
def logsOff() {
log.warn("debug logging disabled")
device.updateSetting("logEnable", [value: "false", type: "bool"])
}
def intTo16bitUnsignedHex(value) {
def hexStr = zigbee.convertToHexString(value.toInteger(),4)
return new String(hexStr.substring(2, 4) + hexStr.substring(0, 2))
}
def intTo8bitUnsignedHex(value) {
return zigbee.convertToHexString(value.toInteger(), 2)
}