-
Notifications
You must be signed in to change notification settings - Fork 12
/
iblinds-zwave.groovy
395 lines (326 loc) · 15.7 KB
/
iblinds-zwave.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
/**
* Copyright 2021 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.
*
* Change Log
* V3.06+ - Added Parameters 7 - 11 - Chance H 6/11/21
*
*/
import groovy.json.JsonOutput
metadata {
definition (name: "iblinds Z-Wave", namespace: "iblinds", author: "HABHomeIntel", ocfDeviceType: "oic.d.blind", mnmn: "SmartThings", vid: "generic-shade-3") {
capability "Window Shade"
capability "Window Shade Preset"
capability "Switch Level"
capability "Battery"
capability "Refresh"
capability "Actuator"
capability "Health Check"
command "stop"
fingerprint mfr:"0287", prod:"0003", model:"000D", deviceJoinName: "iBlinds Window Treatment"
fingerprint mfr:"0287", prod:"0004", model:"0071", deviceJoinName: "iBlinds Window Treatment"
fingerprint mfr:"0287", prod:"0004", model:"0072", deviceJoinName: "iBlinds Window Treatment"
}
simulator {
status "open": "command: 2603, payload: FF"
status "closed": "command: 2603, payload: 00"
status "10%": "command: 2603, payload: 0A"
status "66%": "command: 2603, payload: 42"
status "99%": "command: 2603, payload: 63"
status "battery 100%": "command: 8003, payload: 64"
status "battery low": "command: 8003, payload: FF"
// reply messages
reply "2001FF,delay 1000,2602": "command: 2603, payload: 10 FF FE"
reply "200100,delay 1000,2602": "command: 2603, payload: 60 00 FE"
reply "200142,delay 1000,2602": "command: 2603, payload: 10 42 FE"
reply "200163,delay 1000,2602": "command: 2603, payload: 10 63 FE"
}
tiles(scale: 2) {
multiAttributeTile(name:"windowShade", type: "lighting", width: 6, height: 4){
tileAttribute ("device.windowShade", key: "PRIMARY_CONTROL") {
attributeState "open", label:'${name}', action:"close", icon:"http://i.imgur.com/4TbsR54.png", backgroundColor:"#79b821", nextState:"closing"
attributeState "closed", label:'${name}', action:"open", icon:"st.shades.shade-closed", backgroundColor:"#ffffff", nextState:"opening"
attributeState "partially open", label:'Open', action:"close", icon:"st.shades.shade-open", backgroundColor:"#79b821", nextState:"closing"
attributeState "opening", label:'${name}', action:"stop", icon:"st.shades.shade-opening", backgroundColor:"#79b821", nextState:"partially open"
attributeState "closing", label:'${name}', action:"stop", icon:"st.shades.shade-closing", backgroundColor:"#ffffff", nextState:"partially open"
}
tileAttribute ("device.level", key: "SLIDER_CONTROL") {
attributeState "level", action:"setLevel"
}
}
standardTile("home", "device.level", width: 2, height: 2, decoration: "flat") {
state "default", label: "home", action:"presetPosition", icon:"st.Home.home2"
}
standardTile("refresh", "device.refresh", width: 2, height: 2, inactiveLabel: false, decoration: "flat") {
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh", nextState: "disabled"
state "disabled", label:'', action:"", icon:"st.secondary.refresh"
}
valueTile("battery", "device.battery", decoration: "flat", inactiveLabel: false, width: 2, height: 2) {
state "battery", label:'${currentValue}% battery', unit:""
}
preferences {
// V3 configuration
input title: "V3 iBlinds Device Config", description: "Configuration options for newer V3 iBlinds devices", type: "paragraph", element: "paragraph", displayDuringSetup: false
input name: "NVM_TightLevel", type: "number", title: "Close Interval", defaultValue: 22, description: "Used for Large and Heavy blinds to set the close interval. A smaller value will make the blinds close tighter", required: true, displayDuringSetup: true
input name: "NVM_Direction", type: "bool", title: "Reverse", description: "Reverse Blind Direction", defaultValue: false
input name: "NVM_Target_Value", type: "number", title: "Default ON Value", defaultValue: 50, range: "1..100", description: "Used to set the default ON level when manual push button is pushed", required: true, displayDuringSetup:false
input name: "NVM_Device_Reset_Support", type: "bool", title: "Disable Reset Button", description: "Used for situations where the top motor buttons are being pushed accidentally via a tight installation space, etc.", defaultValue: false
input name: "Speed_Parameter", type: "number", title: "Open/Close Speed (seconds)", defaultValue: 0, range:"0..100", description: "To slow down the blinds, increase the value", required: true, displayDuringSetup: false
input name: "Init_Calib", type: "bool", title: "Initiate Calibration", defaultValue: false, description: "Will begin calibration after the next command is sent", displayDuringSetup: false
input name: "MinTilt",type: "number", title: "Lower close value",defaultValue: 0, range: "0..25", description: "Increase if lower interval is closing too tightly.",required: true, displayDuringSetup:false
input name: "MaxTilt",type: "number", title: "Upper close value",defaultValue: 100, range: "75..100", description: "Increase if upper interval is closing too tightly.",required: true, displayDuringSetup:false
input name: "ReMap",type: "bool", title: "Re-map to 0x63",defaultValue: false, description:"Not applicable to SmartThings",required: false, displayDuringSetup:false
input name: "MultiChange",type: "bool", title: "Allow MultiLevelStopChange",defaultValue: false, description: "Allows use of MultiLevelStopChange",required: true, displayDuringSetup:false
input title: "", description: "", type: "paragraph", element: "paragraph", displayDuringSetup: false
// V2 configuration
input title: "V2 iBlinds Device Config", description: "Configuration options for older V2 iBlinds devices", type: "paragraph", element: "paragraph", displayDuringSetup: false
input "preset", "number", title: "Preset position", description: "Set the window shade preset position", defaultValue: 50, range: "1..99", required: false, displayDuringSetup: false
input "reverse", "bool", title: "Reverse", description: "Reverse Blind Direction", defaultValue: false, required: false , displayDuringSetup: false
}
main(["windowShade"])
details(["windowShade", "home", "refresh", "battery"])
}
}
def parse(String description) {
def result = null
//if (description =~ /command: 2603, payload: ([0-9A-Fa-f]{6})/)
// TODO: Workaround manual parsing of v4 multilevel report
def cmd = zwave.parse(description, [0x20: 1, 0x26: 3]) // TODO: switch to SwitchMultilevel v4 and use target value
if (cmd) {
result = zwaveEvent(cmd)
}
log.debug "Parsed '$description' to ${result?.inspect()}"
return result
}
def getCheckInterval() {
// iblinds is a battery-powered device, and it's not very critical
// to know whether they're online or not – 12 hrs
12 * 60 * 60 //12 hours
}
def installed() {
sendEvent(name: "checkInterval", value: checkInterval, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
sendEvent(name: "supportedWindowShadeCommands", value: JsonOutput.toJson(["open", "close"]), displayed: false)
storeParamState()
response(initialize() + refresh())
}
def updated() {
def cmds = []
if (device.latestValue("checkInterval") != checkInterval) {
sendEvent(name: "checkInterval", value: checkInterval, displayed: false)
}
cmds += configureParams()
storeParamState()
cmds += initialize()
response(cmds)
}
def initialize() {
def cmds = []
if (isV3Device()) {
// Set up lifeline association
cmds << zwave.associationV1.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId).format()
}
// Schedule daily battery check
unschedule()
runIn(15, getBattery)
schedule("2020-01-01T12:01:00.000-0600", getBattery)
cmds
}
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd) {
handleLevelReport(cmd)
}
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) {
handleLevelReport(cmd)
}
def zwaveEvent(physicalgraph.zwave.commands.switchmultilevelv3.SwitchMultilevelReport cmd) {
handleLevelReport(cmd)
}
private handleLevelReport(physicalgraph.zwave.Command cmd) {
def level = cmd.value as Integer
def result = []
log.debug "handleLevelReport($level)"
if (!state.lastbatt || now() - state.lastbatt > 24 * 60 * 60 * 1000) {
log.debug "requesting battery"
state.lastbatt = (now() - 23 * 60 * 60 * 1000) // don't queue up multiple battery reqs in a row
result << response(["delay 15000", zwave.batteryV1.batteryGet().format()])
}
result
}
def zwaveEvent(physicalgraph.zwave.commands.switchmultilevelv3.SwitchMultilevelStopLevelChange cmd) {
[ createEvent(name: "windowShade", value: "partially open", displayed: false, descriptionText: "$device.displayName shade stopped"),
response(zwave.switchMultilevelV1.switchMultilevelGet().format()) ]
}
def zwaveEvent(physicalgraph.zwave.commands.batteryv1.BatteryReport cmd) {
def map = [ name: "battery", unit: "%" ]
if (cmd.batteryLevel == 0xFF) {
map.value = 1
map.descriptionText = "${device.displayName} has a low battery"
map.isStateChange = true
} else {
map.value = cmd.batteryLevel
}
state.lastbatt = now()
createEvent(map)
}
def zwaveEvent(physicalgraph.zwave.Command cmd) {
log.debug "unhandled $cmd"
return []
}
def open() {
Integer level = isV3Device() ? (NVM_Target_Value ?: 50) : 50 // Blinds fully open at 50%, NVM_Target_Value can't be 0%
log.debug "open()"
sendEvent(name: "windowShade", value: "open")
sendEvent(name: "level", value: level, unit: "%", displayed: true)
zwave.switchMultilevelV3.switchMultilevelSet(value: level).format()
}
def close() {
log.debug "close()"
Integer level = isV3Device() ? 0 : (reverse ? 99 : 0)
sendEvent(name: "windowShade", value: "closed")
sendEvent(name: "level", value: 0, unit: "%", displayed: true)
zwave.switchMultilevelV3.switchMultilevelSet(value: level).format()
}
def setLevel(value, duration = null) {
def descriptionText = null
log.debug "setLevel(${value.inspect()})"
Integer level = value as Integer
if (level < 0) level = 0
if (level > 99) level = 99
Integer tiltLevel = level as Integer // we will use this value to decide what level is sent to device (reverse or not reversed)
// For older devices, check to see if user wants blinds to operate in reverse direction
if (!isV3Device() && reverse) {
tiltLevel = 99 - level
}
if (level <= 0) {
sendEvent(name: "windowShade", value: "closed")
} else if (level >= 99) {
level = 99
sendEvent(name: "windowShade", value: "closed")
} else if (level == 50) {
sendEvent(name: "windowShade", value: "open")
} else {
descriptionText = "${device.displayName} tilt level is ${level}% open"
sendEvent(name: "windowShade", value: "partially open" , descriptionText: descriptionText) //, isStateChange: levelEvent.isStateChange )
}
//log.debug "Level - ${level}% & Tilt Level - ${tiltLevel}%"
sendEvent(name: "level", value: level, descriptionText: descriptionText)
zwave.switchMultilevelV3.switchMultilevelSet(value: tiltLevel).format()
}
def presetPosition() {
isV3Device() ? open() : setLevel(preset ?: 50)
}
def pause() {
log.debug "pause()"
stop()
}
def stop() {
log.debug "stop()"
zwave.switchMultilevelV3.switchMultilevelStopLevelChange().format()
}
def ping() {
refresh()
}
def refresh() {
log.debug "refresh()"
delayBetween([
zwave.switchMultilevelV1.switchMultilevelGet().format(),
zwave.batteryV1.batteryGet().format()
], 1500)
}
def configureParams() {
def cmds = []
if (isV3Device()) {
/*
Parameter No. Size Parameter Name Desc.
1 1 NVM_TightLevel Auto Calibration tightness
2 1 NVM_Direction Reverse the direction of iblinds
3 1 NVM_Target_Report Not used ****
4 1 NVM_Target_Value Default on position
5 1 NVM_Device_Reset_Support Turns off the reset button
6 1 Speed_Parameter Speed
7 1 Init_Calib Initiate Calibration (V3.06+)
8 1 MinTilt Minimum Tilt value
9 1 MaxTilt Maximum Tilt value
10 1 ReMap Remap 0xFF to 0x63 for certain hubs
11 1 MultiChange Allow for MultiLevelStopChange
*/
log.debug "Configuration Started"
// If paramater value has changed then add zwave configration command to cmds
if (NVM_TightLevel != null && state.param1 != NVM_TightLevel) {
cmds << zwave.configurationV1.configurationSet(parameterNumber: 1, size: 1, configurationValue: [NVM_TightLevel.toInteger()]).format()
}
if (NVM_Direction != null && state.param2 != NVM_Direction) {
def NVM_Direction_Val = boolToInteger(NVM_Direction)
cmds << zwave.configurationV1.configurationSet(parameterNumber: 2, size: 1, configurationValue: [NVM_Direction_Val.toInteger()]).format()
}
if (state.param3 != 0) {
cmds << zwave.configurationV1.configurationSet(parameterNumber: 3, size: 1, configurationValue: [0]).format()
}
if (NVM_Target_Value != null && state.param4 != NVM_Target_Value) {
cmds << zwave.configurationV1.configurationSet(parameterNumber: 4, size: 1, configurationValue: [NVM_Target_Value.toInteger()]).format()
}
if (NVM_Device_Reset_Support != null && state.param5 != NVM_Device_Reset_Support) {
def NVM_Device_Reset_Val = boolToInteger(NVM_Device_Reset_Support)
cmds << zwave.configurationV1.configurationSet(parameterNumber: 5, size: 1, configurationValue: [NVM_Device_Reset_Val.toInteger()]).format()
}
if (Speed_Parameter != null && state.param6 != Speed_Parameter) {
cmds << zwave.configurationV1.configurationSet(parameterNumber: 6, size: 1, configurationValue: [Speed_Parameter.toInteger()]).format()
}
if (Init_Calib != null && state.param7 != Init_Calib) {
def Init_Calib = boolToInteger(Init_Calib)
cmds << zwave.configurationV1.configurationSet(parameterNumber: 7, size: 1, configurationValue: [Init_Calib.toInteger()]).format()
}
if ( state.param8 != MinTilt ) {
cmds << zwave.configurationV1.configurationSet(parameterNumber: 8, size: 1, configurationValue: [MinTilt.toInteger()]).format()
}
if ( state.param9 != MaxTilt ) {
cmds << zwave.configurationV1.configurationSet(parameterNumber: 9, size: 1, configurationValue: [MaxTilt.toInteger()]).format()
}
if ( state.param10 != ReMap ) {
def ReMap = boolToInteger(ReMap)
cmds << zwave.configurationV1.configurationSet(parameterNumber: 10, size: 1, configurationValue: [ReMap.toInteger()]).format()
}
if ( state.param11 != MultiChange ) {
def MultiChange = boolToInteger(MultiChange)
cmds << zwave.configurationV1.configurationSet(parameterNumber: 11, size: 1, configurationValue: [MultiChange.toInteger()]).format()
}
log.debug "Configuration Complete"
}
delayBetween(cmds, 500)
}
private storeParamState() {
if (isV3Device()) {
log.debug "Storing Paramater Values"
state.param1 = NVM_TightLevel
state.param2 = NVM_Direction
state.param3 = 0 // Not used at the moment
state.param4 = NVM_Target_Value
state.param5 = NVM_Device_Reset_Support
state.param6 = Speed_Parameter
state.param7 = Init_Calib
state.param8 = MinTilt
state.param9 = MaxTilt
state.param10 = ReMap
state.param11 = MultiChange
}
}
def boolToInteger(boolValue) {
boolValue ? 1 : 0
}
def getBattery() {
log.debug "get battery level"
// Use sendHubCommand to get battery level
def cmd = []
cmd << new physicalgraph.device.HubAction(zwave.batteryV1.batteryGet().format())
sendHubCommand(cmd)
}
def isV3Device() {
zwaveInfo.mfr == "0287" && zwaveInfo.prod == "0004" && (zwaveInfo.model == "0071" || zwaveInfo.model == "0072")
}