-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathgeSwitch.groovy
281 lines (252 loc) · 8.59 KB
/
geSwitch.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
/* GE driver 1.2
*
* Variation of the stock SmartThings "Dimmer-Switch" and twack's improved dimmer
* --auto re-configure after setting preferences
*
*
* 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)
*
* Mike Maxwell
* 2014-12-13
*
change log
GE 45609
0x20 Basic
0x25 Switch Binary
0x70 Configuration
0x72 Manufacturer Specific
0x73 Powerlevel
0x77 Node Naming
*/
metadata {
definition (name: "geSwitch", author: "mmaxwell") {
capability "Actuator"
capability "Switch"
capability "Sensor"
//capability "Alarm"
capability "Polling"
capability "Refresh"
capability "Indicator"
//command "flash", ["string"] //blink,flasher,strobe
//GE 45609
fingerprint deviceId: "0x1001", inClusters: "0x25, 0x27, 0x73, 0x70, 0x86, 0x72, 0x77"
}
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"]
//indicator param3, 1:follow light, 0:never
//on position param4 0:on is top 1: off is top
//
}
simulator {
status "on": "command: 2003, payload: FF"
status "off": "command: 2003, payload: 00"
// reply messages
reply "2001FF,delay 5000,2602": "command: 2603, payload: FF"
reply "200100,delay 5000,2602": "command: 2603, payload: 00"
reply "200119,delay 5000,2602": "command: 2603, payload: 19"
reply "200132,delay 5000,2602": "command: 2603, payload: 32"
reply "20014B,delay 5000,2602": "command: 2603, payload: 4B"
reply "200163,delay 5000,2602": "command: 2603, payload: 63"
}
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", icon:"st.secondary.strobe"
}
main(["switch"])
details(["switch","blink","refresh"])
}
}
def parse(String description) {
def item1 = [
canBeCurrentState: false,
linkText: getLinkText(device),
isStateChange: false,
displayed: false,
descriptionText: description,
value: description
]
def result
def cmd = zwave.parse(description, [0x20: 1, 0x25: 1, 0x70: 1, 0x72: 1, 0x73: 1])
if (cmd) {
result = createEvent(cmd, item1)
}
else {
item1.displayed = displayed(description, item1.isStateChange)
result = [item1]
}
if (result?.name == 'hail' && hubFirmwareLessThan("000.011.00602")) {
result = [result, response(zwave.basicV1.basicGet())]
log.debug "Was hailed: requesting state update"
}
//log.debug "Parse returned ${result?.descriptionText}"
return result
}
def zwaveEvent(physicalgraph.zwave.commands.hailv1.Hail cmd) {
[name: "hail", value: "hail", descriptionText: "Switch button was pressed", displayed: false]
//log.debug "hail called"
}
def createEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd, Map item1) {
def result = doCreateEvent(cmd, item1)
for (int i = 0; i < result.size(); i++) {
result[i].type = "physical"
}
result
}
def zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd) {
[name: "switch", value: cmd.value ? "on" : "off", type: "digital"]
}
def createEvent(physicalgraph.zwave.commands.switchmultilevelv1.SwitchMultilevelReport cmd, Map item1) {
def result = doCreateEvent(cmd, item1)
result[0].descriptionText = "${item1.linkText} is ${item1.value}"
result[0].handlerName = cmd.value ? "statusOn" : "statusOff"
for (int i = 0; i < result.size(); i++) {
result[i].type = "digital"
}
result
}
def doCreateEvent(physicalgraph.zwave.Command cmd, Map item1) {
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
result
}
def zwaveEvent(physicalgraph.zwave.commands.configurationv1.ConfigurationReport cmd) {
log.debug("Parameter number ${cmd.parameterNumber}, Value: ${cmd.configurationValue}")
}
def createEvent(physicalgraph.zwave.Command cmd, Map map) {
// Handles any Z-Wave commands we aren't interested in
//log.debug "$cmd"
[:]
}
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.switchMultilevelV1.switchMultilevelGet().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.switchMultilevelV1.switchMultilevelGet().format()], 5000)
//}
}
def poll() {
zwave.switchMultilevelV1.switchMultilevelGet().format()
}
def refresh() {
poll()
}
//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 = []
def boolean isOn = device.currentValue("switch") == "on"
if (isOn) state.stateWhenFlashed = 1
else state.stateWhenFlashed = 0
//switch (settings.blinker) {
switch (type) {
case "Flasher":
pBlink.add(10)
pBlink.add(10)
break
case "Strobe":
pBlink.add(3)
pBlink.add(2)
break
default: //Blink
if (isOn) {
pBlink.add(2)
pBlink.add(20)
}
else {
pBlink.add(1)
pBlink.add(20)
}
break
}
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(configurationValue: [p80], parameterNumber: 80, size: 1).format())
}
if (p120 != state.param120) {
//log.debug "update 120:${p120}"
state.param120 = p120
return response(zwave.configurationV1.configurationSet(configurationValue: [p120], parameterNumber: 120, size: 1).format())
}
//log.debug "after settings: ${settings.inspect()}, state: ${state.inspect()}"
}