-
Notifications
You must be signed in to change notification settings - Fork 0
/
Econet-EV100-Vent-Driver.groovy
273 lines (240 loc) · 8.27 KB
/
Econet-EV100-Vent-Driver.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
/**
* Econet EV100 Vent
*
* Copyright 2014 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.
*
* SANdood' fixes:
* - longer delays for complex commands so that status is returned in a timely manner
* - fixed lastbatt (2 trailing t's) (no longer requests battery state every refresh/poll
* - added log.debug/info support
*
*/
metadata {
// Automatically generated. Make future change here.
definition (name: "EcoNet Vent", namespace: "smartthings", author: "SmartThings") {
capability "Switch Level"
capability "Actuator"
capability "Switch"
capability "Battery"
capability "Refresh"
capability "Sensor"
capability "Polling"
capability "Configuration"
capability "Health Check"
command "open"
command "close"
fingerprint deviceId: "0x1100", inClusters: "0x26,0x72,0x86,0x77,0x80,0x20"
fingerprint mfr:"0157", prod:"0100", model:"0100", deviceJoinName: "EcoNet Controls Z-Wave Vent"
}
simulator {
status "on": "command: 2603, payload: FF"
status "off": "command: 2603, payload: 00"
status "09%": "command: 2603, payload: 09"
status "10%": "command: 2603, payload: 0A"
status "33%": "command: 2603, payload: 21"
status "66%": "command: 2603, payload: 42"
status "99%": "command: 2603, payload: 63"
// reply messages
reply "2001FF,delay 100,2602": "command: 2603, payload: FF"
reply "200100,delay 100,2602": "command: 2603, payload: 00"
reply "200119,delay 100,2602": "command: 2603, payload: 19"
reply "200132,delay 100,2602": "command: 2603, payload: 32"
reply "20014B,delay 100,2602": "command: 2603, payload: 4B"
reply "200163,delay 100,2602": "command: 2603, payload: 63"
}
preferences {
input name: "debugOutput", type: "bool", title: "Enable debug logging?", defaultValue: true
input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true
}
tiles {
standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
state "on", action:"switch.off", icon:"st.vents.vent-open-text", backgroundColor:"#00a0dc"
state "off", action:"switch.on", icon:"st.vents.vent-closed", backgroundColor:"#ffffff"
}
valueTile("battery", "device.battery", inactiveLabel: false, decoration: "flat") {
state "battery", label:'${currentValue}% battery', unit:""
}
controlTile("levelSliderControl", "device.level", "slider", height: 1, width: 3, inactiveLabel: false, range:"(0..100)") {
state "level", action:"switch level.setLevel"
}
standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
}
main(["switch"])
details(["switch","battery","refresh","levelSliderControl"])
}
}
def parse(String description) {
def result = []
logDebug "parse description: ${description}"
def cmd = description ? zwave.parse(description, [0x20: 1, 0x26: 3, 0x70: 1, 0x32:3]) : null
if (cmd) {
result = zwaveEvent(cmd)
logDebug("'$description' parsed to $result")
} else {
logDebug("Couldn't zwave.parse '$description'")
}
return result
}
def installed() {
// Device-Watch simply pings if no device events received for 32min(checkInterval)
// sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
updated()
}
//send the command to stop polling
def updated() {
// Device-Watch simply pings if no device events received for 32min(checkInterval)
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
log.warn "debug logging is: ${debugOutput == true}"
log.warn "description logging is: ${txtEnable == true}"
if (debugOutput) runIn(1800,logsOff)
if (state.lastbat) state.lastbat = null // old state variable (misspelled)
state.lastbatt = null
refresh()
return "poll stop"
}
def zwaveEvent(hubitat.zwave.commands.basicv1.BasicReport cmd) {
dimmerEvents(cmd) + [ response("poll stop") ] // we get a BasicReport when the hub starts polling
}
//parse manufacture name and store it
def zwaveEvent(hubitat.zwave.commands.manufacturerspecificv2.ManufacturerSpecificReport cmd) {
if (state.manufacturer != cmd.manufacturerName) {
updateDataValue("manufacturer", cmd.manufacturerName)
}
}
def zwaveEvent(hubitat.zwave.commands.basicv1.BasicSet cmd) {
dimmerEvents(cmd)
}
def zwaveEvent(hubitat.zwave.commands.switchmultilevelv1.SwitchMultilevelReport cmd) {
dimmerEvents(cmd)
}
def zwaveEvent(hubitat.zwave.commands.switchmultilevelv3.SwitchMultilevelReport cmd) {
dimmerEvents(cmd)
}
def dimmerEvents(hubitat.zwave.Command cmd) {
def text = "${device.displayName} is ${cmd.value ? "open" : "closed"}"
logInfo(text)
def switchEvent = createEvent(name: "switch", value: (cmd.value ? "on" : "off"), descriptionText: text)
def levelEvent = createEvent(name:"level", value: cmd.value == 99 ? 100 : cmd.value , unit:"%")
[switchEvent, levelEvent]
}
def zwaveEvent(hubitat.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"
logInfo(map.descriptionText)
map.isStateChange = true
} else {
map.value = cmd.batteryLevel
}
logInfo("${device.displayName} battery is ${map.value}%")
state.lastbatt = new Date().time
createEvent(map)
}
def zwaveEvent(hubitat.zwave.Command cmd) {
def linkText = device.label ?: device.name
[linkText: linkText, descriptionText: "$linkText: $cmd", displayed: false]
}
def on() {
delayBetween([
zwave.basicV1.basicSet(value: 0xFF).format(),
zwave.switchMultilevelV1.switchMultilevelGet().format()
], 4400)
}
def open() {
on()
}
def off() {
delayBetween([
zwave.basicV1.basicSet(value: 0x00).format(),
zwave.switchMultilevelV1.switchMultilevelGet().format()
], 4400)
}
def close() {
off()
}
def setLevel(value) {
delayBetween([
zwave.basicV1.basicSet(value: value).format(),
zwave.switchMultilevelV1.switchMultilevelGet().format()
], 6600)
}
def setLevel(value, duration) {
setLevel(value)
}
/**
* PING is used by Device-Watch in attempt to reach the Device
* */
def ping() {
refresh()
}
def refresh() {
if (secondsPast(state.lastbatt, 23*60*60)) {
//poll for battery once a day
logDebug "battery poll (refresh)"
delayBetween([
zwave.switchMultilevelV1.switchMultilevelGet().format(),
zwave.batteryV1.batteryGet().format()
], 2200)
} else {
zwave.switchMultilevelV1.switchMultilevelGet().format()
}
}
//poll for battery once a day
def poll() {
if (secondsPast(state.lastbatt, 23*60*60)) {
logDebug "battery poll (poll)"
return zwave.batteryV1.batteryGet().format()
} else {
return zwave.switchMultilevelV1.switchMultilevelGet().format()
}
}
def configure() {
[
zwave.manufacturerSpecificV1.manufacturerSpecificGet().format()
]
refresh()
}
//check last message so battery poll doesn't happen all the time
private Boolean secondsPast(timestamp, seconds) {
if (!(timestamp instanceof Number)) {
if (timestamp instanceof Date) {
timestamp = timestamp.time
} else if ((timestamp instanceof String) && timestamp.isNumber()) {
timestamp = timestamp.toLong()
} else {
return true
}
}
return (new Date().time - timestamp) > (seconds * 1000)
}
//Warn message for unkown events
def createEvents(hubitat.zwave.Command cmd) {
log.warn "UNEXPECTED COMMAND: $cmd"
}
def logsOff(){
log.warn "debug logging disabled..."
device.updateSetting("debugOutput",[value:"false",type:"bool"])
}
private logDebug(msg) {
if (settings?.debugOutput || settings?.debugOutput == null) log.debug "$msg"
}
private logInfo(msg) {
if (settings?.txtEnable || settings?.txtEnable == null) {
if (state.msg != msg) {
// Don't print redundant messages
log.info "$msg"
state.msg = msg
}
}
}