-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFLEXiDimmer_example_device
516 lines (426 loc) · 16.3 KB
/
FLEXiDimmer_example_device
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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
/* FLEXiDimmer DEVICE TYPE (EXAMPLE using Aeon Micro G2 Dimmer)
*
* This is a variation of Mike Maxwell's specific micro driver 1.3 for Aeon Micro G2
* --ADDED: custom attributes (lines 40-45) and commands (lines 53-63 and lines 221-348) related to storage of scene setting information (see remarks below)
*
*
*
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: "flexidimmer", namespace: "info_fiend", author: "anthony pastor") {
capability "Actuator"
capability "Switch"
capability "Refresh"
capability "Sensor"
capability "Alarm"
capability "Switch Level"
capability "Energy Meter"
capability "Power Meter"
capability "Test Capability"
// "FLEXI"-Related Attributes Added
attribute "sceneLevel", "number"
attribute "sceneSwitch", "string"
attribute "sceneName", "string"
attribute "offTime", "number"
// -------------------------------
command "levelUp"
command "levelDown"
command "flash", ["string"] //blink,flasher,strobe
command "reset"
// "FLEXI"-Related Commands Added
command "setOffTime"
command "setScName"
command "saveScene"
command "setScSwitch", ["string"]
command "sceneManual"
command "sceneFree"
command "sceneSlave"
command "sceneMaster"
command "setLevelFromThing"
// ------------------------------
//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"
for (int i = 0; i <= 10000; i += 1000) {
status "power ${i} W": new physicalgraph.zwave.Zwave().meterV1.meterReport(
scaledMeterValue: i, precision: 3, meterType: 4, scale: 2, size: 4).incomingMessage()
}
for (int i = 0; i <= 100; i += 10) {
status "energy ${i} kWh": new physicalgraph.zwave.Zwave().meterV1.meterReport(
scaledMeterValue: i, precision: 3, meterType: 0, scale: 0, size: 4).incomingMessage()
}
// 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"
}
valueTile("power", "device.power", decoration: "flat") {
state "default", label:'${currentValue} W'
}
valueTile("energy", "device.energy", decoration: "flat") {
state "default", label:'${currentValue} kWh1'
}
standardTile("reset", "device.energy", inactiveLabel: false, decoration: "flat") {
state "default", label:'reset kWh', action:"reset"
}
controlTile("levelSliderControl", "device.level", "slider", height: 1, width: 2) {
state "level", action:"setLevelFromThing"
}
valueTile("level", "device.level", decoration: "flat") {
state "level", label: 'Level ${currentValue}%'
}
// FLEXI-related Tiles Added
valueTile("sceneName", "device.sceneName", decoration: "flat") {
state "sceneName", label: 'Scene: ${currentValue}'
}
valueTile("offTime", "device.offTime") {
state "offTime", label: 'OffTime: ${currentValue}'
}
standardTile("sceneSwitch", "device.sceneSwitch", width: 1, height: 1, canChangeIcon: true, decoration: "flat", defaultState: "Manual") {
state "Manual", label: 'Manual', icon:"https://dl.dropboxusercontent.com/u/2403292/STIcons/manualSettings-large.png"
state "Master", label: '${name}', icon:"https://dl.dropboxusercontent.com/u/2403292/STIcons/MCP-large.png"
state "Slave", label: 'Slave', action:"sceneFree", icon:"https://dl.dropboxusercontent.com/u/2403292/STIcons/slave-large.png", nextState: "Freebie"
state "Freebie", action:"sceneSlave", icon:"https://dl.dropboxusercontent.com/u/2403292/STIcons/free-large.png", nextState: "Slave"
}
main(["switch", "lUp"])
details(["switch", "offTime", "sceneSwitch", "level", "levelSliderControl", "lUp", "lDown","blink","lValue","refresh", "energy", "power", "reset"])
}
}
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 [:]
}
//
//
// "FLEXI"-Related Commands (either added or modified)
def setScSwitch(inState) {
log.debug "FlexiAeonDimmer: Executing 'setScSwitch(${inState})'"
sendEvent (name: "sceneSwitch", value: inState, isStateChange: true)
}
def sceneManual() {
// log.debug "FlexiAeonDimmer: sceneManual setting sceneSwitch to: MANUAL."
def curLevel = device.currentValue("level")
setScLevel(curLevel)
def curSat = device.currentValue("saturation")
setScSat(curSat)
def curHue = device.currentValue("hue")
setScHue(curHue)
def newValue = "Manual" as String
setScSwitch(newValue)
}
def sceneFree() {
// log.debug "FlexiAeonDimmer: sceneFree setting sceneSwitch to: FREEEEEE."
def newValue = "Freebie" as String
setScSwitch(newValue)
refresh()
}
def sceneSlave() {
// log.debug "FlexiAeonDimmer: sceneSlave setting sceneSwitch to: SLAVE."
def newValue = "Slave" as String
setScSwitch(newValue)
refresh()
}
def saveScene(Number inValue, String inMode, Number inOffTime) {
log.debug "FlexiAeonDimmer: saveScene:"
if ( inMode ) {
log.debug "sceneName to: ${inMode}"
sendEvent(name: "sceneName", value: inMode, isStateChange: true)
}
if ( inOffTime ) {
if ( inOffTime == 0 ) {
log.debug "Setting offTime to: default 30 b/c inOffTime is 0."
sendEvent(name: "offTime", value: 30, isStateChange: true)
} else {
log.debug "Setting offTime to: ${inOffTime}"
sendEvent(name: "offTime", value: inOffTime, isStateChange: true)
}
}
if ( inValue ) {
sendEvent(name: "sceneLevel", value: inValue.level)
log.debug "Setting sceneLevel to: ${inValue}."
}
}
def setLevel(Number value) {
setLevel(value, 3)
//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 setLevelFromThing(Number inValue) {
// log.debug "FlexiAeonDimmer: setLevelfromThing setting sceneSwitch to: Manual."
def newValue = "Manual" as String
setScSwitch(newValue)
setLevel(inValue, 3)
}
def setLevel(Number inValue, duration) {
if (device.latestValue("switch") == "off" ) {
sendEvent(name: "switch", value: "on", isStateChange: true)
}
sendEvent(name: "level", value: inValue, isStateChange: true)
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: inValue, dimmingDuration: 0).format()
else delayBetween ([zwave.switchMultilevelV2.switchMultilevelSet(value: inValue, dimmingDuration: duration).format(), zwave.basicV1.basicGet().format()], 0)
}
def on() {
//reset alarm trigger
state.alarmTriggered = 0
def level = device.currentValue("level")
if(level == null)
{
level = 99
}
if (device.latestValue("switch") == "off" ) {
sendEvent(name: "switch", value: "on", isStateChange: true)
}
//Don't request a config report when advanced reporting is enabled
if (settings.param80 in ["Hail","Report"]) zwave.basicV1.basicSet(value: level).format() //value: 0xFF
else delayBetween([zwave.basicV1.basicSet(value: level).format(), zwave.basicV1.basicGet().format()], 5000) //value: 0xFF
}
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 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 refresh() {
return zwave.basicV1.basicGet().format()
}
def createEvent(physicalgraph.zwave.commands.meterv2.MeterReport cmd, Map item1)
{
if (cmd.scale == 0) {
createEvent([name: "energy", value: cmd.scaledMeterValue, unit: "kWh"])
} else if (cmd.scale == 1) {
createEvent([name: "energy", value: cmd.scaledMeterValue, unit: "kVAh"])
}
else {
createEvent([name: "power", value: Math.round(cmd.scaledMeterValue), unit: "W"])
}
}
def reset() {
return [
zwave.meterV2.meterReset().format(),
zwave.meterV2.meterGet().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()
])
}