-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathaeonDimmer.groovy
334 lines (299 loc) · 11.4 KB
/
aeonDimmer.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
/* AEON specific micro driver 1.3
*
* Variation of the stock SmartThings "Dimmer-Switch" and twack's improved dimmer
* --auto re-configure after setting preferences
* --alarm indicator capability (using AEON hardware blink function)
* --up/down dimmer tiles, with configurable interval rates
*
* Includes:
* preferences tile for setting:
* reporting functions (parameter 80) [ 0:off, 1:hail, 2:report ] set to "Report" for fastest physical updates from the device
* control switch type (parameter 120) [ 0:momentary, 1:toggle, 2:three way ] (2 isn't tested, not sure how its suppposed to work)
* preconfigured blinker modes [ Blink, Flasher, Strobe ]
*
* Mike Maxwell
* madmax98087@yahoo.com
* 2014-12-06
*
change log
1.1 2014-12-08
-added light state restore to prevent alarm smartapps from turning off the light if it was on when the stobe request was made.
1.2 2014-12-10
-added flash command with parameters for smartapp integration
1.3 2014-12-14
-almost a complete parser re-write
AEON G2
0x20 Basic
0x25 Switch Binary
0x26 Switch Multilevel
0x2C Scene Actuator Conf
0x2B Scene Activation
0x70 Configuration
0x72 Manufacturer Specific
0x73 Powerlevel
0x77 Node Naming
0x85 Association
0x86 Version
0xEF MarkMark
0x82 Hail
*/
metadata {
definition (name: "aeonDimmer", namespace: "mmaxwell", author: "mike maxwell") {
capability "Actuator"
capability "Switch"
capability "Refresh"
capability "Sensor"
capability "Alarm"
capability "Switch Level"
command "levelUp"
command "levelDown"
command "flash", ["string"] //blink,flasher,strobe
//aeon S2 switch (DSC26103-ZWUS)
fingerprint deviceId: "0x1001", inClusters: "0x25,0x27,0x2C,0x2B,0x70,0x85,0x72,0x86,0xEF,0x82"
}
preferences {
input name: "param80", type: "enum", title: "State change notice:", description: "Type", required: true, options:["Off","Hail","Report"]
input name: "param120", type: "enum", title: "Set trigger mode:", description: "Switch type", required: true, options:["Momentary","Toggle","Three Way"]
input name: "blinker", type: "enum", title: "Set blinker mode:", description: "Blinker type", required: false, options:["Blink","Flasher","Strobe"]
input name: "dInterval", type: "enum", title: "Set dimmer button offset:", description: "Value per click", required: false, options:["1","5","10"]
}
// simulator metadata
simulator {
status "on": "command: 2003, payload: FF"
status "off": "command: 2003, payload: 00"
// reply messages
reply "2001FF,delay 100,2502": "command: 2503, payload: FF"
reply "200100,delay 100,2502": "command: 2503, payload: 00"
}
// tile definitions
tiles {
standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true, canChangeBackground: true) {
state "on", label:'${name}', action:"switch.off", backgroundColor:"#79b821", nextState:"turningOff"
state "off", label:'${name}', action:"switch.on", backgroundColor:"#ffffff", nextState:"turningOn"
state "turningOn", label:'${name}', backgroundColor:"#79b821"
state "turningOff", label:'${name}', backgroundColor:"#ffffff"
}
standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
}
standardTile("blink", "device.alarm", inactiveLabel: false, decoration: "flat") {
state "default", label:"", action:"alarm.strobe", backgroundColor: "#53a7c0", icon:"st.secondary.strobe"
}
valueTile("lValue", "device.level", inactiveLabel: true, height:1, width:1, decoration: "flat") {
state "levelValue", label:'${currentValue}%', unit:"", backgroundColor: "#53a7c0"
}
standardTile("lUp", "device.switchLevel", inactiveLabel: false,decoration: "flat", canChangeIcon: false) {
state "default", action:"levelUp", icon:"st.illuminance.illuminance.bright"
}
standardTile("lDown", "device.switchLevel", inactiveLabel: false,decoration: "flat", canChangeIcon: false) {
state "default", action:"levelDown", icon:"st.illuminance.illuminance.light"
}
main(["switch"])
details(["switch", "lUp", "lDown","blink","lValue","refresh"])
}
}
def parse(String description) {
def result = null
def cmd = zwave.parse(description, [0x20: 1, 0x70: 1])
//log.debug "cmd:${cmd.inspect()}"
def item1 = [
canBeCurrentState: false,
linkText: displyName,
isStateChange: false,
displayed: false,
descriptionText: description,
value: description
]
if (cmd.hasProperty("value")) {
result = createEvent(cmd, item1)
}
//log.debug "res:${result.inspect()}"
return result
}
def createEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd, Map item1) {
//aeons return this when in mode 2
//log.debug "basicReport:${cmd.inspect()}"
def result = [item1]
item1.name = "switch"
item1.value = cmd.value ? "on" : "off"
item1.handlerName = item1.value
item1.descriptionText = "${item1.linkText} was turned ${item1.value}"
item1.canBeCurrentState = true
item1.isStateChange = isStateChange(device, item1.name, item1.value)
item1.displayed = item1.isStateChange
if (cmd.value > 15) {
def item2 = new LinkedHashMap(item1)
item2.name = "level"
item2.value = cmd.value as String
item2.unit = "%"
item2.descriptionText = "${item1.linkText} dimmed ${item2.value} %"
item2.canBeCurrentState = true
item2.isStateChange = isStateChange(device, item2.name, item2.value)
item2.displayed = false
result << item2
}
//i still don't know what this is...
for (int i = 0; i < result.size(); i++) {
result[i].type = "physical"
}
return result
}
def zwaveEvent(physicalgraph.zwave.Command cmd) {
// Handles all Z-Wave commands we aren't interested in or don't know about
//log.debug "udf:${cmd.inspect()}"
return [:]
}
def levelUp(){
def int step = (settings.dInterval ?:10).toInteger() //set 10 as default
def int crntLevel = device.currentValue("level")
def int nextLevel = crntLevel - (crntLevel % step) + step
state.alarmTriggered = 0
if( nextLevel > 99) nextLevel = 99
//log.debug "crnt:${crntLevel} next:${nextLevel}"
//Don't request a config report when advanced reporting is enabled
if (settings.param80 in ["Hail","Report"]) zwave.basicV1.basicSet(value: nextLevel).format()
else delayBetween ([zwave.basicV1.basicSet(value: nextLevel).format(), zwave.basicV1.basicGet().format()], 5000)
}
def levelDown(){
def int step = (settings.dInterval ?:10).toInteger() //set 10 as default
def int crntLevel = device.currentValue("level")
def int nextLevel //= crntLevel - (crntLevel % step) - step
state.alarmTriggered = 0
if (crntLevel == 99) {
nextLevel = 100 - step
} else {
nextLevel = crntLevel - (crntLevel % step) - step
}
//log.debug "crnt:${crntLevel} next:${nextLevel}"
if (nextLevel == 0){
off()
}
else
{
//Don't request a config report when advanced reporting is enabled
if (settings.param80 in ["Hail","Report"]) zwave.basicV1.basicSet(value: nextLevel).format()
else delayBetween ([zwave.basicV1.basicSet(value: nextLevel).format(), zwave.basicV1.basicGet().format()], 5000)
}
}
def setLevel(value) {
//Don't request a config report when advanced reporting is enabled
if (settings.param80 in ["Hail","Report"]) zwave.basicV1.basicSet(value: value).format()
else delayBetween ([zwave.basicV1.basicSet(value: value).format(), zwave.basicV1.basicGet().format()], 5000)
}
def setLevel(value, duration) {
def dimmingDuration = duration < 128 ? duration : 128 + Math.round(duration / 60)
//Don't request a config report when advanced reporting is enabled
if (settings.param80 in ["Hail","Report"]) zwave.switchMultilevelV2.switchMultilevelSet(value: value, dimmingDuration: 0).format()
else delayBetween ([zwave.switchMultilevelV2.switchMultilevelSet(value: value, dimmingDuration: duration).format(), zwave.basicV1.basicGet().format()], 0)
}
def on() {
//reset alarm trigger
state.alarmTriggered = 0
//Don't request a config report when advanced reporting is enabled
if (settings.param80 in ["Hail","Report"]) zwave.basicV1.basicSet(value: 0xFF).format()
else delayBetween([zwave.basicV1.basicSet(value: 0xFF).format(), zwave.basicV1.basicGet().format()], 5000)
}
def off() {
//log.debug "at:${state.alarmTriggered} swf:${state.stateWhenFlashed}"
//override alarm off command from smartApps
if (state.alarmTriggered == 1 && state.stateWhenFlashed == 1) {
state.alarmTriggered = 0
} else {
//Don't request a config report when advanced reporting is enabled
if (settings.param80 in ["Hail","Report"]) zwave.basicV1.basicSet(value: 0x00).format()
else delayBetween ([zwave.basicV1.basicSet(value: 0x00).format(), zwave.basicV1.basicGet().format()], 5000)
}
}
def refresh() {
return zwave.basicV1.basicGet().format()
}
//built in flasher mode
def flash(type) {
if (!type) type = settings.blinker
//AEON blink parameters
//1: blink duration in seconds 1-255
//2: cycle time in .1 seconds (50% duty cycle) 1-255
def pBlink = []
if (device.currentValue("switch") == "on") state.stateWhenFlashed = 1
else state.stateWhenFlashed = 0
switch (settings.blinker) {
case "Flasher":
pBlink.add(10)
pBlink.add(10)
break
case "Strobe":
pBlink.add(3)
pBlink.add(2)
break
default: //Blink
pBlink.add(1)
pBlink.add(20)
break
}
//sendEvent (name: "alarm", value: "done",descriptionText: "Flasher activated.")
zwave.configurationV1.configurationSet(configurationValue: pBlink, parameterNumber: 2, size: 2).format()
}
//alarm methods
def strobe() {
state.alarmTriggered = 1
flash(settings.blinker)
}
def siren() {
state.alarmTriggered = 1
flash(settings.blinker)
}
def both() {
state.alarmTriggered = 1
flash(settings.blinker)
}
//capture preference changes
def updated() {
//log.debug "before settings: ${settings.inspect()}, state: ${state.inspect()}"
//get requested reporting preferences
Short p80
switch (settings.param80) {
case "Off":
p80 = 0
break
case "Hail":
p80 = 1
break
default:
p80 = 2 //Report
break
}
//get requested switch function preferences
Short p120
switch (settings.param120) {
case "Momentary":
p120 = 0
break
case "Three Way":
p120 = 2
break
default:
p120 = 1 //Toggle
break
}
//update if the settings were changed
if (p80 != state.param80) {
//log.debug "update 80:${p80}"
state.param80 = p80
return response(zwave.configurationV1.configurationSet(parameterNumber: 80, size: 1, configurationValue: [p80]).format())
}
if (p120 != state.param120) {
//log.debug "update 120:${p120}"
state.param120 = p120
return response(zwave.configurationV1.configurationSet(parameterNumber: 120, size: 1, configurationValue: [p120]).format())
}
//log.debug "after settings: ${settings.inspect()}, state: ${state.inspect()}"
}
def configure() {
settings.param80 = "Report"
settings.param120 = "Toggle"
settings.blinker = "Blink"
delayBetween([
zwave.configurationV1.configurationSet(parameterNumber: 80, size: 1, configurationValue: 2).format(),
zwave.configurationV1.configurationSet(parameterNumber: 120, size: 1, configurationValue: 1).format()
])
}