-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAxisGear
More file actions
388 lines (330 loc) · 12.9 KB
/
Copy pathAxisGear
File metadata and controls
388 lines (330 loc) · 12.9 KB
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
import groovy.json.JsonOutput
metadata {
definition (name: "AXIS Gear Hubitat", namespace: "axis", author: "AXIS Labs", ocfDeviceType: "oic.d.blind", vid: "generic-shade-3") {
capability "Window Shade"
// capability "Window Shade Level"
// capability "Window Shade Preset"
capability "Switch Level"
if (batteryEnable) capability "Battery"
capability "Refresh"
capability "Health Check"
capability "Actuator"
capability "Configuration"
// added in for Google Assistant Operability
capability "Switch"
//Custom Commandes to achieve 25% increment control
command "ShadesUp"
command "ShadesDown"
// command to stop blinds
command "stop"
command "getversion"
fingerprint profileID: "0104", manufacturer: "AXIS", model: "Gear", deviceJoinName: "AXIS Window Treatment" //AXIS Gear
fingerprint profileId: "0104", deviceId: "0202", inClusters: "0000, 0003, 0006, 0008, 0102, 0020, 0001", outClusters: "0019", manufacturer: "AXIS", model: "Gear", deviceJoinName: "AXIS Window Treatment" //AXIS Gear
// fingerprint endpointID: "01, C4", profileId: "0104, C25D", deviceId: "0202", inClusters: "0000, 0003, 0006, 0008, 0102, 0020, 0001", outClusters: "0019", manufacturer: "AXIS", model: "Gear", deviceJoinName: "AXIS Window Treatment" //AXIS Gear
//ClusterIDs: 0000 - Basic; 0006 - On/Off; 0008 - Level Control; 0102 - Window Covering;
//Updated 2017-06-21
//Updated 2017-08-24 - added power cluster 0001 - added battery, level, reporting, & health check
//Updated 2018-01-04 - Axis Inversion & Increased Battery Reporting interval to 1 hour (previously 5 mins)
//Updated 2018-01-08 - Updated battery conversion from [0-100 : 00 - 64] to [0-100 : 00-C8] to reflect firmware update
//Updated 2018-11-01 - added in configure reporting for refresh button, close when press on partial shade icon, update handler to parse between 0-254 as a percentage
//Updated 2019-06-03 - modified to use Window Covering Cluster Commands and versioning tile and backwards compatibility (firmware and app), fingerprinting enabled
//Updated 2019-08-09 - minor changes and improvements, onoff state reporting fixed
//Updated 2019-11-11 - minor changes
}
preferences {
input "preset", "number", title: "Preset position", description: "Set the window shade preset position", defaultValue: 50, required: false, displayDuringSetup: true, range:"1..100"
input("batteryEnable", "bool", title: "Enable battery reporting?")
input("debugEnable", "bool", title: "Enable debug logging?")
}
}
//Declare Clusters
private getCLUSTER_BASIC() {0x0000}
private getBASIC_ATTR_SWBUILDID() {0x4000}
private getCLUSTER_POWER() {0x0001}
private getPOWER_ATTR_BATTERY() {0x0021}
private getCLUSTER_ONOFF() {0x0006}
private getONOFF_ATTR_ONOFFSTATE() {0x0000}
private getCLUSTER_LEVEL() {0x0008}
private getLEVEL_ATTR_LEVEL() {0x0000}
private getLEVEL_CMD_STOP() {0x03}
private getCLUSTER_WINDOWCOVERING() {0x0102}
private getWINDOWCOVERING_ATTR_LIFTPERCENTAGE() {0x0008}
private getWINDOWCOVERING_CMD_OPEN() {0x00}
private getWINDOWCOVERING_CMD_CLOSE() {0x01}
private getWINDOWCOVERING_CMD_STOP() {0x02}
private getWINDOWCOVERING_CMD_GOTOLIFTPERCENTAGE() {0x05}
private getMIN_WINDOW_COVERING_VERSION() {1093}
def getLastShadeLevel() {
device.currentState("shadeLevel") ? device.currentValue("shadeLevel") : (device.currentState("level") ? device.currentValue("level") : 0) // Try shadeLevel, if not use level, if not 0
}
//Custom command to increment blind position by 25 %
def ShadesUp() {
def shadeValue = lastShadeLevel as Integer
if (shadeValue < 100) {
shadeValue = Math.min(25 * (Math.round(shadeValue / 25) + 1), 100) as Integer
}
else {
shadeValue = 100
}
//sendEvent(name:"level", value:shadeValue)
setShadeLevel(shadeValue)
//sendEvent(name: "windowShade", value: "opening")
}
//Custom command to decrement blind position by 25 %
def ShadesDown() {
def shadeValue = lastShadeLevel as Integer
if (shadeValue > 0) {
shadeValue = Math.max(25 * (Math.round(shadeValue / 25) - 1), 0) as Integer
}
else {
shadeValue = 0
}
//sendEvent(name:"level", value:shadeValue)
setShadeLevel(shadeValue)
//sendEvent(name: "windowShade", value: "closing")
}
def stop() {
if (debugEnable) log.info "stop()"
def shadeState = device.latestValue("windowShade")
if (shadeState == "opening" || shadeState == "closing") {
if (state.currentVersion >= MIN_WINDOW_COVERING_VERSION) {
sendEvent(name: "windowShade", value: "stopping")
return zigbee.command(CLUSTER_WINDOWCOVERING, WINDOWCOVERING_CMD_STOP)
}
else {
sendEvent(name: "windowShade", value: "stoppingNS")
return zigbee.readAttribute(CLUSTER_LEVEL, LEVEL_ATTR_LEVEL, [delay:5000])
}
}
else {
if (state.currentVersion >= MIN_WINDOW_COVERING_VERSION) {
return zigbee.readAttribute(CLUSTER_WINDOWCOVERING, WINDOWCOVERING_ATTR_LIFTPERCENTAGE)
}
else {
sendEvent(name: "windowShade", value: "stoppingNS")
return zigbee.readAttribute(CLUSTER_LEVEL, LEVEL_ATTR_LEVEL, [delay:5000])
}
}
}
def pause() {
stop()
}
//Send Command through setLevel()
def on() {
if (debugEnable) log.info "on()"
sendEvent(name: "switch", value: "on")
open()
}
//Send Command through setLevel()
def off() {
if (debugEnable) log.info "off()"
sendEvent(name: "switch", value: "off")
close()
}
//Command to set the blind position (%) and log the event
def setLevel(value, rate=null) {
if (debugEnable) log.info "setLevel ($value)"
setShadeLevel(value)
}
def setShadeLevel(value) {
if (debugEnable) log.info "setShadeLevel ($value)"
Integer currentLevel = state.level
def i = value as Integer
sendEvent(name:"level", value: value, unit:"%", displayed: false)
sendEvent(name:"shadeLevel", value: value, unit:"%")
if (i == 0) {
sendEvent(name: "switch", value: "off")
}
else {
sendEvent(name: "switch", value: "on")
}
if (i > currentLevel) {
sendEvent(name: "windowShade", value: "opening")
}
else if (i < currentLevel) {
sendEvent(name: "windowShade", value: "closing")
}
//setWindowShade(i)
if (state.currentVersion >= MIN_WINDOW_COVERING_VERSION) {
zigbee.command(CLUSTER_WINDOWCOVERING,WINDOWCOVERING_CMD_GOTOLIFTPERCENTAGE, zigbee.convertToHexString(100-i,2))
}
else {
zigbee.setLevel(i)
}
}
//Send Command through setLevel()
def open() {
if (debugEnable) log.info "open()"
sendEvent(name: "windowShade", value: "opening")
if (state.currentVersion >= MIN_WINDOW_COVERING_VERSION) {
zigbee.command(CLUSTER_WINDOWCOVERING, WINDOWCOVERING_CMD_OPEN)
}
else {
setShadeLevel(100)
}
}
//Send Command through setLevel()
def close() {
if (debugEnable) log.info "close()"
sendEvent(name: "windowShade", value: "closing")
if (state.currentVersion >= MIN_WINDOW_COVERING_VERSION) {
zigbee.command(CLUSTER_WINDOWCOVERING, WINDOWCOVERING_CMD_CLOSE)
}
else {
setShadeLevel(0)
}
}
def presetPosition() {
if (debugEnable) log.info "presetPosition()"
setShadeLevel(preset ?: state.preset ?: 50)
}
//Reporting of Battery & position levels
def ping(){
if (debugEnable) log.debug "Ping() "
return refresh()
}
//Set blind State based on position (which shows appropriate image)
def setWindowShade(value) {
if ((value>0)&&(value<99)) {
sendEvent(name: "windowShade", value: "partially open")
}
else if (value >= 99) {
sendEvent(name: "windowShade", value: "open")
}
else {
sendEvent(name: "windowShade", value: "closed")
}
}
//Refresh command
def refresh() {
if (debugEnable) log.debug "parse() refresh"
def cmds_refresh = null
if (state.currentVersion >= MIN_WINDOW_COVERING_VERSION) {
cmds_refresh = zigbee.readAttribute(CLUSTER_WINDOWCOVERING, WINDOWCOVERING_ATTR_LIFTPERCENTAGE)
}
else {
cmds_refresh = zigbee.readAttribute(CLUSTER_LEVEL, LEVEL_ATTR_LEVEL)
}
cmds_refresh = cmds_refresh +
zigbee.readAttribute(CLUSTER_POWER, POWER_ATTR_BATTERY) +
zigbee.readAttribute(CLUSTER_BASIC, BASIC_ATTR_SWBUILDID)
if (debugEnable) log.info "refresh() --- cmds: $cmds_refresh"
return cmds_refresh
}
def getversion () {
//state.currentVersion = 0
sendEvent(name: "version", value: "Checking Version ... ")
return zigbee.readAttribute(CLUSTER_BASIC, BASIC_ATTR_SWBUILDID)
}
//configure reporting
def configure() {
state.currentVersion = 0
sendEvent(name: "windowShade", value: "unknown")
if (debugEnable) log.debug "Configuring Reporting and Bindings."
sendEvent(name: "checkInterval", value: (2 * 60 * 60 + 10 * 60), displayed: true, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
sendEvent(name: "supportedWindowShadeCommands", value: JsonOutput.toJson(["open", "close", "pause"]), displayed: false)
def attrs_refresh = zigbee.readAttribute(CLUSTER_BASIC, BASIC_ATTR_SWBUILDID) +
zigbee.readAttribute(CLUSTER_WINDOWCOVERING, WINDOWCOVERING_ATTR_LIFTPERCENTAGE) +
zigbee.readAttribute(CLUSTER_ONOFF, ONOFF_ATTR_ONOFFSTATE) +
zigbee.readAttribute(CLUSTER_LEVEL, LEVEL_ATTR_LEVEL) +
zigbee.readAttribute(CLUSTER_POWER, POWER_ATTR_BATTERY)
def cmds = zigbee.configureReporting(CLUSTER_WINDOWCOVERING, WINDOWCOVERING_ATTR_LIFTPERCENTAGE, 0x20, 1, 3600, 0x00) +
zigbee.configureReporting(CLUSTER_ONOFF, ONOFF_ATTR_ONOFFSTATE, 0x10, 1, 3600, 0x00) +
zigbee.configureReporting(CLUSTER_LEVEL, LEVEL_ATTR_LEVEL, 0x20, 1, 3600, 0x00) +
zigbee.configureReporting(CLUSTER_POWER, POWER_ATTR_BATTERY, 0x20, 1, 3600, 0x01)
if (debugEnable) log.info "configure() --- cmds: $cmds"
return attrs_refresh + cmds
}
def parse(String description) {
if (debugEnable) log.trace "parse() --- description: $description"
Map map = [:]
// if (device.currentValue("shadeLevel") == null && device.currentValue("level") != null) {
// sendEvent(name: "shadeLevel", value: device.currentValue("level"), unit: "%")
// }
def event = zigbee.getEvent(description)
if (event && description?.startsWith('on/off')) {
if (debugEnable) log.trace "sendEvent(event)"
sendEvent(event)
}
else if ((description?.startsWith('read attr -')) || (description?.startsWith('attr report -'))) {
map = parseReportAttributeMessage(description)
def result = map ? createEvent(map) : null
if (map.name == "level") {
result = [result, createEvent([name: "shadeLevel", value: map.value, unit: map.unit])]
}
if (debugEnable) log.debug "parse() --- returned: $result"
return result
}
}
private Map parseReportAttributeMessage(String description) {
Map descMap = zigbee.parseDescriptionAsMap(description)
Map resultMap = [:]
if (descMap.clusterInt == CLUSTER_POWER && descMap.attrInt == POWER_ATTR_BATTERY) {
if (batteryEnable){
resultMap.name = "battery"
def batteryValue = Math.round((Integer.parseInt(descMap.value, 16))/2)
if (debugEnable) log.debug "parseDescriptionAsMap() --- Battery: $batteryValue"
if ((batteryValue >= 0)&&(batteryValue <= 100)) {
resultMap.value = batteryValue
}
else {
resultMap.value = 0
}
}
}
else if (descMap.clusterInt == CLUSTER_WINDOWCOVERING && descMap.attrInt == WINDOWCOVERING_ATTR_LIFTPERCENTAGE && state.currentVersion >= MIN_WINDOW_COVERING_VERSION) {
//if (debugEnable) log.debug "parse() --- returned windowcovering :$state.currentVersion "
resultMap.name = "level"
def levelValue = 100 - Math.round(Integer.parseInt(descMap.value, 16))
//Set icon based on device feedback for the open, closed, & partial configuration
resultMap.value = levelValue
state.level = levelValue
resultMap.unit = "%"
resultMap.displayed = false
setWindowShade(levelValue)
}
else if (descMap.clusterInt == CLUSTER_LEVEL && descMap.attrInt == LEVEL_ATTR_LEVEL) {
//if (debugEnable) log.debug "parse() --- returned level :$state.currentVersion "
def currentLevel = state.level
resultMap.name = "level"
def levelValue = Math.round(Integer.parseInt(descMap.value, 16))
def levelValuePercent = Math.round((levelValue/255)*100)
//Set icon based on device feedback for the open, closed, & partial configuration
resultMap.value = levelValuePercent
state.level = levelValuePercent
resultMap.unit = "%"
resultMap.displayed = false
if (state.currentVersion >= MIN_WINDOW_COVERING_VERSION) {
//Integer currentLevel = state.level
sendEvent(name:"level", value: levelValuePercent, unit: "%", displayed: false)
if (levelValuePercent > currentLevel) {
sendEvent(name: "windowShade", value: "opening")
} else if (levelValuePercent < currentLevel) {
sendEvent(name: "windowShade", value: "closing")
}
}
else {
setWindowShade(levelValuePercent)
}
}
else if (descMap.clusterInt == CLUSTER_BASIC && descMap.attrInt == BASIC_ATTR_SWBUILDID) {
resultMap.name = "version"
def versionString = descMap.value
StringBuilder output = new StringBuilder("")
StringBuilder output2 = new StringBuilder("")
for (int i = 0; i < versionString.length(); i += 2) {
String str = versionString.substring(i, i + 2)
output.append((char) (Integer.parseInt(str, 16)))
if (i > 19) {
output2.append((char) (Integer.parseInt(str, 16)))
}
}
def current = Integer.parseInt(output2.toString())
state.currentVersion = current
resultMap.value = output.toString()
}
else {
if (debugEnable) log.debug "parseReportAttributeMessage() --- ignoring attribute"
}
return resultMap
}