-
Notifications
You must be signed in to change notification settings - Fork 90.1k
/
qubino-flush-shutter.groovy
501 lines (457 loc) · 17.7 KB
/
qubino-flush-shutter.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
/**
* Copyright 2020 SmartThings
*
* 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: "Qubino Flush Shutter", namespace: "qubino", author: "SmartThings", ocfDeviceType: "oic.d.blind", mcdSync: true) {
capability "Window Shade"
capability "Window Shade Level"
capability "Power Meter"
capability "Energy Meter"
capability "Refresh"
capability "Health Check"
capability "Configuration"
//zw:L type:1107 mfr:0159 prod:0003 model:0052 ver:1.01 zwv:4.05 lib:03 cc:5E,86,72,5A,73,20,27,25,26,32,60,85,8E,59,70 ccOut:20,26 epc:2
fingerprint mfr: "0159", prod: "0003", model: "0052", deviceJoinName: "Qubino Window Treatment" // Qubino Flush Shutter (110-230 VAC)
//zw:L type:1107 mfr:0159 prod:0003 model:0053 ver:1.01 zwv:4.05 lib:03 cc:5E,86,72,5A,73,20,27,25,26,32,85,8E,59,70 ccOut:20,26
fingerprint mfr: "0159", prod: "0003", model: "0053", deviceJoinName: "Qubino Window Treatment" // Qubino Flush Shutter DC
}
tiles(scale: 2) {
multiAttributeTile(name:"windowShade", type: "generic", width: 6, height: 4) {
tileAttribute("device.windowShade", key: "PRIMARY_CONTROL") {
attributeState "open", label: 'Open', action: "close", icon: "http://www.ezex.co.kr/img/st/window_open.png", backgroundColor: "#00A0DC", nextState: "closing"
attributeState "closed", label: 'Closed', action: "open", icon: "http://www.ezex.co.kr/img/st/window_close.png", backgroundColor: "#ffffff", nextState: "opening"
attributeState "partially open", label: 'Partially open', action: "close", icon: "http://www.ezex.co.kr/img/st/window_open.png", backgroundColor: "#d45614", nextState: "closing"
attributeState "opening", label: 'Opening', action: "pause", icon: "http://www.ezex.co.kr/img/st/window_open.png", backgroundColor: "#00A0DC", nextState: "partially open"
attributeState "closing", label: 'Closing', action: "pause", icon: "http://www.ezex.co.kr/img/st/window_close.png", backgroundColor: "#ffffff", nextState: "partially open"
}
}
valueTile("shadeLevel", "device.level", width: 4, height: 1) {
state "shadeLevel", label: 'Shade is ${currentValue}% up', defaultState: true
}
controlTile("levelSliderControl", "device.level", "slider", width:2, height: 1, inactiveLabel: false) {
state "shadeLevel", action:"switch level.setLevel"
}
valueTile("power", "device.power", decoration: "flat", width: 2, height: 2) {
state "default", label:'${currentValue} W'
}
valueTile("energy", "device.energy", decoration: "flat", width: 2, height: 2) {
state "default", label:'${currentValue} kWh'
}
standardTile("refresh", "device.power", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
}
main "windowShade"
details(["windowShade", "shadeLevel", "levelSliderControl", "power", "energy", "refresh"])
}
preferences {
parameterMap.each {
input (title: it.name, description: it.description, type: "paragraph", element: "paragraph")
switch (it.type) {
case "enum":
input(name: it.key, title: "Select", type: "enum", options: it.values, defaultValue: it.defaultValue, required: false)
break
case "range":
input(name: it.key, type: "number", title: "Set value (range ${it.range})", defaultValue: it.defaultValue, range: it.range, required: false)
break
}
}
}
}
def installed() {
state.currentMode = null
state.childDevices = [:]
state.venetianBlindDni = null
state.temperatureSensorDni = null
sendHubCommand(encap(zwave.configurationV2.configurationGet(parameterNumber: 71)))
sendEvent(name: "checkInterval", value: 2 * 60 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
// Preferences template begin
state.currentPreferencesState = [:]
parameterMap.each {
state.currentPreferencesState."$it.key" = [:]
state.currentPreferencesState."$it.key".value = getPreferenceValue(it)
def preferenceName = it.key + "Boolean"
settings."$preferenceName" = true
state.currentPreferencesState."$it.key".status = "synced"
}
// Preferences template end
sendEvent(name: "supportedWindowShadeCommands", value: ["open", "close", "pause"])
}
def updated() {
// Preferences template begin
parameterMap.each {
if (isPreferenceChanged(it)) {
log.debug "Preference ${it.key} has been updated from value: ${state.currentPreferencesState."$it.key".value} to ${settings."$it.key"}"
state.currentPreferencesState."$it.key".status = "syncPending"
} else if (!state.currentPreferencesState."$it.key".value) {
log.warn "Preference ${it.key} no. ${it.parameterNumber} has no value. Please check preference declaration for errors."
}
}
syncConfiguration()
// Preferences template end
}
private syncConfiguration() {
def commands = []
parameterMap.each {
try {
if (state.currentPreferencesState."$it.key".status == "syncPending") {
commands += encap(zwave.configurationV2.configurationSet(scaledConfigurationValue: getCommandValue(it), parameterNumber: it.parameterNumber, size: it.size))
commands += encap(zwave.configurationV2.configurationGet(parameterNumber: it.parameterNumber))
} else if (state.currentPreferencesState."$it.key".status == "disablePending") {
commands += encap(zwave.configurationV2.configurationSet(scaledConfigurationValue: it.disableValue, parameterNumber: it.parameterNumber, size: it.size))
commands += encap(zwave.configurationV2.configurationGet(parameterNumber: it.parameterNumber))
}
} catch (e) {
log.warn "There's been an issue with preference: ${it.key}"
}
}
sendHubCommand(commands)
}
def zwaveEvent(physicalgraph.zwave.commands.configurationv2.ConfigurationReport cmd) {
// Preferences template begin
log.debug "Configuration report: ${cmd}"
def preference = parameterMap.find( {it.parameterNumber == cmd.parameterNumber} )
def key = preference.key
def preferenceValue = getPreferenceValue(preference, cmd.scaledConfigurationValue)
if (settings."$key" == preferenceValue) {
state.currentPreferencesState."$key".value = settings."$key"
state.currentPreferencesState."$key".status = "synced"
handleConfigurationChange(cmd)
} else {
state.currentPreferencesState."$key"?.status = "syncPending"
runIn(5, "syncConfiguration", [overwrite: true])
}
// Preferences template end
handleConfigurationChange(cmd)
}
private getPreferenceValue(preference, value = "default") {
def integerValue = value == "default" ? preference.defaultValue : value.intValue()
switch (preference.type) {
case "enum":
return String.valueOf(integerValue)
default:
return integerValue
}
}
private getCommandValue(preference) {
def parameterKey = preference.key
switch (preference.type) {
case "range":
return settings."$parameterKey"
default:
return Integer.parseInt(settings."$parameterKey")
}
}
private isPreferenceChanged(preference) {
if (settings."$preference.key" != null) {
def value = state.currentPreferencesState."$preference.key"
return state.currentPreferencesState."$preference.key".value != settings."$preference.key"
} else {
return false
}
}
def handleConfigurationChange(confgurationReport) {
switch (confgurationReport.parameterNumber) {
case 71: //Operating mode
switch (confgurationReport.scaledConfigurationValue) {
case 0: // Shutter
checkAndTriggerModeChange("windowShade")
break
case 1: // Venetian
checkAndTriggerModeChange("windowShadeVenetian")
break
}
log.info "Current device's mode is: ${state.currentMode}"
break
case 72:
state.timeOfVenetianMovement = confgurationReport.scaledConfigurationValue
break
default:
log.info "Parameter no. ${confgurationReport.parameterNumber} has no specific handler"
break
}
}
private checkAndTriggerModeChange(reportedMode) {
if (state.currentMode != reportedMode) {
state.currentMode = reportedMode
createVenetianBlindsChildDeviceIfNeeded()
}
}
def parse(String description) {
def result = null
def cmd = zwave.parse(description)
if (cmd) {
result = zwaveEvent(cmd)
} else {
log.warn "${device.displayName} - no-parsed event: ${description}"
}
log.debug "Parse returned: ${result}"
return result
}
def multilevelChildInstalled(childDni) {
state.timeOfVenetianMovement = 150
sendHubCommand(encap(zwave.switchMultilevelV3.switchMultilevelGet(), 2))
}
def close() {
setShadeLevel(0x64)
}
def open() {
setShadeLevel(0x00)
}
def pause() {
def currentShadeState = device.currentState("windowShade").value
if (currentShadeState == "opening" || currentShadeState == "closing") {
encap(zwave.switchMultilevelV3.switchMultilevelStopLevelChange())
} else {
encap(zwave.switchMultilevelV3.switchMultilevelGet())
}
}
def setLevelChild(level, childDni) {
setSlats(level)
}
def setLevel(level) {
setShadeLevel(level)
}
def setShadeLevel(level) {
log.debug "Setting shade level: ${level}"
encap(zwave.switchMultilevelV3.switchMultilevelSet(value: Math.min(0x63, level)))
}
def setSlats(level) {
def time = (int) (state.timeOfVenetianMovement * 1.1)
sendHubCommand([
encap(zwave.switchMultilevelV3.switchMultilevelSet(value: Math.min(0x63, level)), 2),
"delay ${time}",
encap(zwave.switchMultilevelV3.switchMultilevelGet(), 2)
])
}
def refresh() {
[
encap(zwave.switchMultilevelV3.switchMultilevelGet()),
encap(zwave.meterV3.meterGet(scale: 0x00)),
]
}
def ping() {
response(refresh())
}
def configure() {
def configurationCommands = []
configurationCommands += encap(zwave.associationV1.associationSet(groupingIdentifier: 7, nodeId: [zwaveHubNodeId]))
configurationCommands += encap(zwave.meterV3.meterGet(scale: 0x00))
configurationCommands += encap(zwave.meterV3.meterGet(scale: 0x02))
configurationCommands += encap(zwave.switchMultilevelV3.switchMultilevelGet())
configurationCommands += encap(zwave.configurationV2.configurationSet(scaledConfigurationValue: 1, parameterNumber: 40, size: 1))
delayBetween(configurationCommands)
}
def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) {
def encapsulatedCommand = cmd.encapsulatedCommand()
if (encapsulatedCommand) {
zwaveEvent(encapsulatedCommand)
} else {
log.warn "unable to extract secure command from $cmd"
createEvent(descriptionText: cmd.toString())
}
}
def zwaveEvent(physicalgraph.zwave.commands.multichannelv3.MultiChannelCmdEncap cmd, ep = null) {
def encapsulatedCommand = cmd.encapsulatedCommand()
zwaveEvent(encapsulatedCommand, cmd.sourceEndPoint as Integer)
}
def zwaveEvent(physicalgraph.zwave.commands.switchmultilevelv3.SwitchMultilevelReport cmd, ep = null) {
log.debug "SwitchMultilevelReport ${cmd} from endpoint: ${ep}"
if (cmd.value != 0xFE) {
if (ep != 2) {
shadeEvent(cmd.value)
} else {
def event = [name: "level", value: cmd.value != 0x63 ? cmd.value : 100]
sendEventsToVenetianBlind([event])
}
} else {
log.warn "Something went wrong with calibration, position of blind is unknown"
if (ep == 2) {
sendEventsToVenetianBlind([[name: "level", value: 0]])
} else {
[
createEvent([name: "windowShade", value: "unknown"]),
createEvent([name: "shadeLevel", value: 0])
]
}
}
}
def zwaveEvent(physicalgraph.zwave.commands.switchmultilevelv3.SwitchMultilevelSet cmd, ep = null) {
def currentLevel = Integer.parseInt(device.currentState("shadeLevel").value)
state.blindsLastCommand = currentLevel > cmd.value ? "opening" : "closing"
state.shadeTarget = cmd.value
sendHubCommand(encap(zwave.meterV3.meterGet(scale: 0x02)))
}
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd, ep = null) {
log.debug "BasicReport ${cmd}"
if (cmd.value != 0xFE && ep != 2) {
shadeEvent(cmd.value)
} else {
log.warn "Something went wrong with calibration, position of blind is unknown"
}
}
private shadeEvent(value) {
def shadeValue
def events = []
if (!value) {
shadeValue = "open"
} else if (value == 0x63) {
shadeValue = "closed"
} else {
shadeValue = "partially open"
}
events += createEvent([name: "windowShade", value: shadeValue])
events += createEvent([name: "shadeLevel", value: value != 0x63 ? value : 100])
events
}
def zwaveEvent(physicalgraph.zwave.commands.meterv3.MeterReport cmd, ep = null) {
def events = []
if (cmd.meterType == 0x01) {
def eventMap = [:]
if (cmd.scale == 0x00) {
eventMap.name = "energy"
eventMap.value = cmd.scaledMeterValue
eventMap.unit = "kWh"
events += createEvent(eventMap)
} else if (cmd.scale == 0x02) {
eventMap.name = "power"
eventMap.value = Math.round(cmd.scaledMeterValue)
eventMap.unit = "W"
events += createEvent(eventMap)
if (Math.round(cmd.scaledMeterValue)) {
events += createEvent([name: "windowShade", value: state.blindsLastCommand])
events += createEvent([name: "shadeLevel", value: state.shadeTarget, displayed: false])
} else {
events += response([
encap(zwave.switchMultilevelV3.switchMultilevelGet()),
"delay 500",
encap(zwave.meterV3.meterGet(scale: 0x00))
])
}
}
}
events
}
def zwaveEvent(physicalgraph.zwave.commands.sensormultilevelv5.SensorMultilevelReport cmd, ep = null) {
log.debug "SensorMultilevelReport ${cmd}" + (ep ? " from endpoint $ep" : "")
def map = [:]
switch (cmd.sensorType) {
case 1:
map.name = "temperature"
def cmdScale = cmd.scale == 1 ? "F" : "C"
map.value = convertTemperatureIfNeeded(cmd.scaledSensorValue, cmdScale, cmd.precision)
map.unit = getTemperatureScale()
break
default:
map.descriptionText = cmd.toString()
}
def child = childDevices.find { it.deviceNetworkId == state.temperatureSensorDni }
if (!child) {
child = createChildDevice("qubinoTemperatureSensor", "Qubino Temperature Sensor", "Qubino Temperature Sensor", 3, "qubino", false)
state.temperatureSensorDni = child.deviceNetworkId
}
child?.sendEvent(map)
createEvent(map)
}
def zwaveEvent(physicalgraph.zwave.Command cmd, ep = null) {
log.warn "Unhandled ${cmd}" + (ep ? " from endpoint $ep" : "")
}
private encap(cmd, endpoint = null) {
if (cmd) {
if (endpoint) {
cmd = zwave.multiChannelV3.multiChannelCmdEncap(destinationEndPoint: endpoint).encapsulate(cmd)
}
if (zwaveInfo.zw.contains("s")) {
zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format()
} else {
cmd.format()
}
}
}
private sendEventsToVenetianBlind(events) {
if (state.venetianBlindDni) {
def child = childDevices.find { it.deviceNetworkId == state.venetianBlindDni }
events.each {
child.sendEvent(it)
}
createEvent(descriptionText: "Venetian Blinds level has been updated")
} else {
log.warn "There's no venetian child device to send events to"
}
}
private createChildDevice(componentName, componentLabel, dthName, childIt, namespace = "smartthings", isComponent = true) {
try {
def childDni = "${device.deviceNetworkId}:$childIt"
def child = addChildDevice(namespace, dthName, childDni, device.getHub().getId(), [
completedSetup: true,
label : componentLabel,
isComponent : isComponent,
componentName : componentName,
componentLabel: componentLabel
])
return child
} catch(Exception e) {
log.debug "Exception: ${e}"
}
}
private createVenetianBlindsChildDeviceIfNeeded() {
if (state.currentMode.contains("Venetian")) {
state.venetianBlindDni = createChildDevice("venetianBlind", "Venetian Blind", "Child Switch Multilevel", 2).deviceNetworkId
}
}
private getParameterMap() {[
[
name: "Operating modes", key: "operatingModes", type: "enum",
parameterNumber: 71, size: 1, defaultValue: 0,
values: [
0: "Shutter mode",
1: "Venetian mode (up/down and slate rotation)"
],
description: "Set the device's operating mode."
],
[
name: "Slats tilting full turn time", key: "slatsTiltingFullTurnTime", type: "range",
parameterNumber: 72, size: 2, defaultValue: 150,
range: "0..32767",
description: "Specify the time required to rotate the slats 180 degrees. (100 = 1 second)"
],
[
name: "Slats position", key: "slatsPosition", type: "enum",
parameterNumber: 73, size: 1, defaultValue: 1,
values: [
0: "Slats return to previously set position only in case of Z-wave control (not valid for limit switch positions)",
1: "Slats return to previously set position in case of Z-wave control, push-button operation or when the lower limit switch is reached"
],
description: "This parameter defines slats position after up/down movement through Z-wave or push-buttons."
],
[
name: "Motor moving up/down time", key: "motorMovingUp/DownTime", type: "range",
parameterNumber: 74, size: 2, defaultValue: 0,
range: "0..32767",
description: "Set the amount of time it takes to completely open or close shutter. Check manual for more detailed guidance."
],
[
name: "Motor operation detection", key: "motorOperationDetection", type: "range",
parameterNumber: 76, size: 1, defaultValue: 30,
range: "0..127",
description: "Power usage threshold which will be interpreted as motor reaching the limit switch."
],
[
name: "Forced Shutter calibration", key: "forcedShutterCalibration", type: "enum",
parameterNumber: 78, size: 1, defaultValue: 0,
values: [
0: "0: Calibration finished or not started",
1: "1: Start calibration process"
],
description: "By modifying the parameters setting from 0 to 1 a Shutter enters the calibration mode. When calibration process is finished, completing full cycle - up, down and up, set this parameter value back to 0."
]
]}