-
Notifications
You must be signed in to change notification settings - Fork 14
/
aeonrangev7.groovy
350 lines (296 loc) · 11.7 KB
/
aeonrangev7.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
//
// Copyright (c) 2020, Denny Page
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Version 1.0.0 Initial release
// Version 1.0.1 Fix incorrect event name when no range test has been run
// Version 1.1.0 Don't indicate range test as in progress until the device
// responds. Provide feedback on the count of frames received
// as an attribute.
// Version 1.2.0 Power level set is a temporary setting for testing and
// requires a timeout value.
// Version 1.2.1 Clarify that node for range test needs to be decimal
// Version 1.3.0 Use zwaveSecureEncap method introduced in Hubitat 2.2.3.
// Version 1.3.1 Mark seconds as a required input for power test
// Version 1.4.0 Normalize logging
//
metadata
{
definition (
name: "Aeotec Range Extender 7", namespace: "cococafe", author: "Denny Page"
)
{
capability "Configuration"
capability "Refresh"
attribute "indicator", "string"
attribute "powerLevel", "string"
attribute "rangeTest", "string"
attribute "rangeTestReceived", "string"
attribute "lastUpdate", "string"
command "powerTest", [[name: "seconds*", type: "NUMBER", defaultValue: "0",
description: "Seconds before returning to normal power"],
[name: "power", type: "ENUM", constraints: ["normal",
"-1dBm", "-2dBm", "-3dBm",
"-4dBm", "-5dBm", "-6dBm",
"-7dBm", "-8dBm", "-9dBm"]]]
command "rangeTest", [[name: "node*", type: "NUMBER", description: "Node to test against (decimal)"],
[name: "power", type: "ENUM", constraints: ["normal",
"-1dBm", "-2dBm", "-3dBm",
"-4dBm", "-5dBm", "-6dBm",
"-7dBm", "-8dBm", "-9dBm"]]]
fingerprint mfr:"0371", prod:"0104", deviceId:"00BD",
inClusters: "0x5E,0x85,0x8E,0x59,0x55,0x86,0x72,0x5A,0x87,0x73,0x9F,0x6C,0x7A"
// 0x55 COMMAND_CLASS_TRANSPORT_SERVICE_V2
// 0x59 COMMAND_CLASS_ASSOCIATION_GRP_INFO
// 0x5A COMMAND_CLASS_DEVICE_RESET_LOCALLY
// 0x5E COMMAND_CLASS_ZWAVEPLUS_INFO_V2
// 0x6C COMMAND_CLASS_SUPERVISION_V1
// 0x72 COMMAND_CLASS_MANUFACTURER_SPECIFIC_V2
// 0x73 COMMAND_CLASS_POWERLEVEL
// 0x7A COMMAND_CLASS_FIRMWARE_UPDATE_MD_V2
// 0x85 COMMAND_CLASS_ASSOCIATION_V2
// 0x86 COMMAND_CLASS_VERSION_V3
// 0x87 COMMAND_CLASS_INDICATOR_V3
// 0x8E COMMAND_CLASS_MULTICHANNEL_ASSOCIATION_V3
// 0x9F COMMAND_CLASS_SECURITY_2
}
}
preferences
{
input name: "indicator", title: "Indicator light",
type: "bool", defaultValue: "0"
input name: "testFrames", title: "Frame count for range testing",
type: "number", defaultValue: "10", range: "1..255"
input name: "logEnable", title: "Enable debug logging", type: "bool", defaultValue: true
input name: "txtEnable", title: "Enable descriptionText logging", type: "bool", defaultValue: true
input name: "enableScheduledRefresh", title: "Enable daily scheduled refresh", type: "bool", defaultValue: false
}
void logsOff()
{
device.updateSetting("logEnable", [value:"false", type:"bool"])
log.warn "debug logging disabled"
}
void installed()
{
runIn(1800, logsOff)
}
def refresh()
{
if (logEnable) log.debug "Refresh"
def cmds = []
cmds.add(zwaveSecureEncap(zwave.indicatorV3.indicatorGet()))
cmds.add(zwaveSecureEncap(zwave.versionV3.versionGet()))
//cmds.add(zwaveSecureEncap(zwave.powerlevelV1.powerlevelGet()))
//cmds.add(zwaveSecureEncap(zwave.powerlevelV1.powerlevelTestNodeGet()))
delayBetween(cmds, 200)
}
def scheduledRefresh()
{
if (logEnable) log.debug "Scheduled Refresh"
if (enableScheduledRefresh)
{ if (logEnable) log.debug "Scheduled Refresh is true, re-scheduling for one day."
unschedule()
runIn(86400,"scheduledRefresh")
}
runIn(5,"refresh")
}
def configure()
{
if (logEnable) log.debug "Configure"
Integer indicatorValue = indicator ? 0xFF : 0
def cmds = []
cmds.add(zwaveSecureEncap(zwave.indicatorV3.indicatorSet(value: indicatorValue)))
cmds.add(zwaveSecureEncap(zwave.indicatorV3.indicatorGet()))
delayBetween(cmds, 200)
}
def updated()
{
if (logEnable) log.debug "Updated preferences"
log.warn "debug logging is ${logEnable}"
log.warn "description logging is ${txtEnable}"
if (enableScheduledRefresh)
{
if (logEnable) log.debug "Scheduled Refresh is true, scheduling for one day."
unschedule()
runIn(86400,"scheduledRefresh")
}
runIn(1, configure)
if (logEnable) runIn(1800, logsOff)
}
static String powerLevelToString(Number power)
{
return power ? "-${power}dBm" : "normal"
}
static Integer stringToPowerLevel(String string)
{
def match = (string =~ /-([0-9]+)dBm/)
if (match.find()) return match.group(1).toInteger()
return 0
}
def powerTest(Number seconds, String powerString)
{
if (seconds < 0 || seconds > 255)
{
log.error "Invalid powerTest seconds ${seconds}"
return null
}
def power = stringToPowerLevel(powerString)
def cmds = []
cmds.add(zwaveSecureEncap(zwave.powerlevelV1.powerlevelSet(powerLevel: power, timeout: seconds)))
cmds.add(zwaveSecureEncap(zwave.powerlevelV1.powerlevelGet()))
delayBetween(cmds, 200)
}
def rangeTest(Number node, String powerString)
{
if (node < 1)
{
log.error "Invalid test node ${node}"
return null
}
def power = stringToPowerLevel(powerString)
def frames = testFrames ? testFrames.toInteger() : 10
def map = [:]
map.name = "rangeTest"
map.value = "pending"
map.descriptionText = "${device.displayName}: range test pending - sending ${frames} frames to node ${node} at power level ${powerString}"
sendEvent(map)
if (txtEnable) log.info "${map.descriptionText}"
def cmds = []
cmds.add(zwaveSecureEncap(zwave.powerlevelV1.powerlevelTestNodeSet(powerLevel: power,
testFrameCount: frames,
testNodeid: node)))
cmds.add(zwaveSecureEncap(zwave.powerlevelV1.powerlevelTestNodeGet()))
delayBetween(cmds, 100)
}
def requestPowerLevel()
{
zwaveSecureEncap(zwave.powerlevelV1.powerlevelGet())
}
def requestTestNode()
{
zwaveSecureEncap(zwave.powerlevelV1.powerlevelTestNodeGet())
}
def parse(String description)
{
hubitat.zwave.Command cmd = zwave.parse(description,commandClassVersions)
if (cmd)
{
def now = new Date().format('MM/dd/yyyy h:mm a',location.timeZone)
sendEvent(name: "lastUpdate", value: now, descriptionText: "Last Update: $now")
return zwaveEvent(cmd)
}
if (logEnable) log.debug "Non Z-Wave parse event: ${description}"
return null
}
void zwaveEvent(hubitat.zwave.commands.indicatorv3.IndicatorReport cmd)
{
if (logEnable) log.debug "IndicatorReport: ${cmd.toString()}"
String status = cmd.value ? "on" : "off"
def map = [:]
map.name = "indicator"
map.value = "${status}"
map.descriptionText = "${device.displayName}: indicator light is ${status}"
sendEvent(map)
if (txtEnable) log.info "${map.descriptionText}"
}
def zwaveEvent(hubitat.zwave.commands.powerlevelv1.PowerlevelReport cmd)
{
unschedule(requestPowerLevel)
if (logEnable) log.debug "PowerLevelReport: ${cmd.toString()}"
power = powerLevelToString(cmd.powerLevel)
def map = [:]
map.name = "powerLevel"
map.value = "${power}"
map.descriptionText = "${device.displayName}: transmit power level is ${power}, timeout ${cmd.timeout} seconds"
sendEvent(map)
if (txtEnable) log.info "${map.descriptionText}"
if (cmd.timeout)
{
runIn(cmd.timeout, requestPowerLevel)
}
}
def zwaveEvent(hubitat.zwave.commands.powerlevelv1.PowerlevelTestNodeReport cmd)
{
unschedule(requestTestNode)
if (logEnable) log.debug "PowerLevelTestNodeReport: ${cmd.toString()}"
// Check test validity
if (cmd.testNodeid == 0)
{
sendEvent(name: "rangeTest", value: "none")
return
}
def Boolean inProgress = false
switch (cmd.statusOfOperation)
{
case 0: // ZW_TEST_FAILED
status = "failed"
break
case 1: // ZW_TEST_SUCCES
status = "succeeded"
break
case 2: // ZW_TEST_INPROGRESS
inProgress = true
status = "in progress"
break
}
def map = [:]
map.name = "rangeTest"
map.value = "${status}"
map.descriptionText = "${device.displayName}: range test ${status}"
sendEvent(map)
if (txtEnable) log.info "${map.descriptionText}"
map.name = "rangeTestReceived"
map.value = "${cmd.testFrameCount}"
map.descriptionText = "${device.displayName}: received ${cmd.testFrameCount} frames from node ${cmd.testNodeid}"
sendEvent(map)
if (txtEnable) log.info "${map.descriptionText}"
if (inProgress)
{
runIn(2, requestTestNode)
}
}
void zwaveEvent(hubitat.zwave.commands.versionv3.VersionReport cmd)
{
if (logEnable) log.debug "VersionReport: ${cmd}"
device.updateDataValue("firmwareVersion", "${cmd.firmware0Version}.${cmd.firmware0SubVersion}")
device.updateDataValue("protocolVersion", "${cmd.zWaveProtocolVersion}.${cmd.zWaveProtocolSubVersion}")
device.updateDataValue("hardwareVersion", "${cmd.hardwareVersion}")
}
def zwaveEvent(hubitat.zwave.commands.securityv1.SecurityMessageEncapsulation cmd)
{
encapCmd = cmd.encapsulatedCommand()
if (encapCmd)
{
return zwaveEvent(encapCmd)
}
log.warn "Unable to extract encapsulated cmd: ${cmd.toString()}"
return null
}
def zwaveEvent(hubitat.zwave.Command cmd)
{
if (logEnable) log.debug "Unhandled cmd: ${cmd.toString()}"
return null
}