-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path8-way-relay.groovy
316 lines (291 loc) · 12.7 KB
/
8-way-relay.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
/**
* Arduino + 8-way relay board Device Type for SmartThings
*
* Author: [email protected]
* Code: https://github.com/jwsf/device-type.arduino-8-way-relay
*
* Copyright (C) 2014 Jonathan Wilson <[email protected]>
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following
* conditions: The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
metadata {
preferences {
input("autorelayoff1", "number", title: "Relay 1 auto-off", description: "Minutes until auto switch off?", required: false)
input("autorelayoff2", "number", title: "Relay 2 auto-off", description: "Minutes until auto switch off?", required: false)
input("autorelayoff3", "number", title: "Relay 3 auto-off", description: "Minutes until auto switch off?", required: false)
input("autorelayoff4", "number", title: "Relay 4 auto-off", description: "Minutes until auto switch off?", required: false)
input("autorelayoff5", "number", title: "Relay 5 auto-off", description: "Minutes until auto switch off?", required: false)
input("autorelayoff6", "number", title: "Relay 6 auto-off", description: "Minutes until auto switch off?", required: false)
input("autorelayoff7", "number", title: "Relay 7 auto-off", description: "Minutes until auto switch off?", required: false)
input("autorelayoff8", "number", title: "Relay 8 auto-off", description: "Minutes until auto switch off?", required: false)
}
// Automatically generated. Make future change here.
definition (name: "Arduino Relay Board", author: "[email protected]") {
capability "Polling"
capability "Refresh"
command "RelayOn1"
command "RelayOff1"
command "RelayOn2"
command "RelayOff2"
command "RelayOn3"
command "RelayOff3"
command "RelayOn4"
command "RelayOff4"
command "RelayOn5"
command "RelayOff5"
command "RelayOn6"
command "RelayOff6"
command "RelayOn7"
command "RelayOff7"
command "RelayOn8"
command "RelayOff8"
command "Push1"
command "Push2"
command "Push3"
command "Push4"
command "Push5"
command "Push6"
command "Push7"
command "Push8"
}
// tile definitions
tiles {
standardTile("relay1", "device.relay1", canChangeIcon: true, canChangeBackground: true) {
state "on", label: '${name}', action: "RelayOff1", icon: "st.switches.switch.on", backgroundColor: "#79b821", nextState:"switching"
state "off", label: '${name}', action: "RelayOn1", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState:"switching"
state "switching", label: '${name}', action: "RelayOff1", icon: "st.switches.switch.on", backgroundColor: "#ff8d00"
}
standardTile("relay2", "device.relay2", canChangeIcon: true, canChangeBackground: true) {
state "on", label: '${name}', action: "RelayOff2", icon: "st.switches.switch.on", backgroundColor: "#79b821", nextState:"switching"
state "off", label: '${name}', action: "RelayOn2", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState:"switching"
state "switching", label: '${name}', action: "RelayOff2", icon: "st.switches.switch.on", backgroundColor: "#ff8d00"
}
standardTile("relay3", "device.relay3", canChangeIcon: true, canChangeBackground: true) {
state "on", label: '${name}', action: "RelayOff3", icon: "st.switches.switch.on", backgroundColor: "#79b821", nextState:"switching"
state "off", label: '${name}', action: "RelayOn3", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState:"switching"
state "switching", label: '${name}', action: "RelayOff3", icon: "st.switches.switch.on", backgroundColor: "#ff8d00"
}
standardTile("relay4", "device.relay4", canChangeIcon: true, canChangeBackground: true) {
state "on", label: '${name}', action: "RelayOff4", icon: "st.switches.switch.on", backgroundColor: "#79b821", nextState:"switching"
state "off", label: '${name}', action: "RelayOn4", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState:"switching"
state "switching", label: '${name}', action: "RelayOff4", icon: "st.switches.switch.on", backgroundColor: "#ff8d00"
}
standardTile("relay5", "device.relay5", canChangeIcon: true, canChangeBackground: true) {
state "on", label: '${name}', action: "RelayOff5", icon: "st.switches.switch.on", backgroundColor: "#79b821", nextState:"switching"
state "off", label: '${name}', action: "RelayOn5", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState:"switching"
state "switching", label: '${name}', action: "RelayOff5", icon: "st.switches.switch.on", backgroundColor: "#ff8d00"
}
standardTile("relay6", "device.relay6", canChangeIcon: true, canChangeBackground: true) {
state "on", label: '${name}', action: "RelayOff6", icon: "st.switches.switch.on", backgroundColor: "#79b821", nextState:"switching"
state "off", label: '${name}', action: "RelayOn6", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState:"switching"
state "switching", label: '${name}', action: "RelayOff6", icon: "st.switches.switch.on", backgroundColor: "#ff8d00"
}
standardTile("relay7", "device.relay7", canChangeIcon: true, canChangeBackground: true) {
state "on", label: '${name}', action: "RelayOff7", icon: "st.switches.switch.on", backgroundColor: "#79b821", nextState:"switching"
state "off", label: '${name}', action: "RelayOn7", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState:"switching"
state "switching", label: '${name}', action: "RelayOff7", icon: "st.switches.switch.on", backgroundColor: "#ff8d00"
}
standardTile("relay8", "device.relay8", canChangeIcon: true, canChangeBackground: true) {
state "on", label: '${name}', action: "RelayOff8", icon: "st.switches.switch.on", backgroundColor: "#79b821", nextState:"switching"
state "off", label: '${name}', action: "RelayOn8", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState:"switching"
state "switching", label: '${name}', action: "RelayOff8", icon: "st.switches.switch.on", backgroundColor: "#ff8d00"
}
standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
}
main "relay1"
details(["relay1", "relay2", "relay3", "relay4", "relay5", "relay6", "relay7", "relay8", "refresh"])
}
simulator {
status "on": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6E"
status "off": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6666"
// reply messages
reply "raw 0x0 { 00 00 0a 0a 6f 6e }": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6E"
reply "raw 0x0 { 00 00 0a 0a 6f 66 66 }": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6666"
}
}
// Commands
// =====================
def RelayOn1() {
log.debug "Turning on relay 1"
String msg = "relayon:1:"+settings.autorelayoff1
zigbee.smartShield(text: msg).format()
}
def RelayOff1() {
log.debug "Turning off relay 1"
zigbee.smartShield(text: "relayoff:1").format()
}
def RelayOn2() {
log.debug "Turning on: relay 2"
String msg = "relayon:2:"+settings.autorelayoff2
zigbee.smartShield(text: msg).format()
}
def RelayOff2() {
log.debug "Turning off relay 2"
zigbee.smartShield(text: "relayoff:2").format()
}
def RelayOn3() {
log.debug "Turning on relay 3"
String msg = "relayon:3:"+settings.autorelayoff3
zigbee.smartShield(text: msg).format()
}
def RelayOff3() {
log.debug "Turning off relay 3"
zigbee.smartShield(text: "relayoff:3").format()
}
def RelayOn4() {
log.debug "Turning on relay 4"
String msg = "relayon:4:"+settings.autorelayoff4
zigbee.smartShield(text: msg).format()
}
def RelayOff4() {
log.debug "Turning off relay 4"
zigbee.smartShield(text: "relayoff:4").format()
}
def RelayOn5() {
log.debug "Turning on relay 5"
String msg = "relayon:5:"+settings.autorelayoff5
zigbee.smartShield(text: msg).format()
}
def RelayOff5() {
log.debug "Turning off relay 5"
zigbee.smartShield(text: "relayoff:5").format()
}
def RelayOn6() {
log.debug "Turning on relay 6"
String msg = "relayon:6:"+settings.autorelayoff6
zigbee.smartShield(text: msg).format()
}
def RelayOff6() {
log.debug "Turning off relay 6"
zigbee.smartShield(text: "relayoff:6").format()
}
def RelayOn7() {
log.debug "Turning on relay 7"
String msg = "relayon:7:"+settings.autorelayoff7
zigbee.smartShield(text: msg).format()
}
def RelayOff7() {
log.debug "Turning off relay 7"
zigbee.smartShield(text: "relayoff:7").format()
}
def RelayOn8() {
log.debug "Turning on relay 8"
String msg = "relayon:8:"+settings.autorelayoff8
zigbee.smartShield(text: msg).format()
}
def RelayOff8() {
log.debug "Turning off relay 8"
zigbee.smartShield(text: "relayoff:8").format()
}
def Push1() {
log.debug "Pushing relay 1"
zigbee.smartShield(text: "push:1").format()
}
def Push2() {
log.debug "Pushing relay 2"
zigbee.smartShield(text: "push:2").format()
}
def Push3() {
log.debug "Pushing relay 3"
zigbee.smartShield(text: "push:3").format()
}
def Push4() {
log.debug "Pushing relay 4"
zigbee.smartShield(text: "push:4").format()
}
def Push5() {
log.debug "Pushing relay 5"
zigbee.smartShield(text: "push:5").format()
}
def Push6() {
log.debug "Pushing relay 6"
zigbee.smartShield(text: "push:6").format()
}
def Push7() {
log.debug "Pushing relay 7"
zigbee.smartShield(text: "push:7").format()
}
def Push8() {
log.debug "Pushing relay 8"
zigbee.smartShield(text: "push:8").format()
}
def poll()
{
log.debug "Poll - getting state of all relays"
zigbee.smartShield(text: "relaystateall").format()
}
def refresh()
{
log.debug "Refresh - getting state of all relays"
zigbee.smartShield(text: "relaystateall").format()
}
// Arduino event handlers
// =================================
def parse(String description) {
def value = zigbee.parse(description)?.text
log.debug "Received: " + value
if (value == "relayon1") {
createEvent (name:"relay1", value:"on", isStateChange:true)
} else
if (value == "relayoff1") {
createEvent (name:"relay1", value:"off", isStateChange:true)
} else
if (value == "relayautooff1") {
sendEvent (name: "alert", value: "Relay auto switchoff")
} else
if (value == "relayon2") {
createEvent (name:"relay2", value:"on", isStateChange:true)
} else
if (value == "relayoff2") {
createEvent (name:"relay2", value:"off", isStateChange:true)
} else
if (value == "relayon3") {
createEvent (name:"relay3", value:"on", isStateChange:true)
} else
if (value == "relayoff3") {
createEvent (name:"relay3", value:"off", isStateChange:true)
} else
if (value == "relayon4") {
createEvent (name:"relay4", value:"on", isStateChange:true)
} else
if (value == "relayoff4") {
createEvent (name:"relay4", value:"off", isStateChange:true)
} else
if (value == "relayon5") {
createEvent (name:"relay5", value:"on", isStateChange:true)
} else
if (value == "relayoff5") {
createEvent (name:"relay5", value:"off", isStateChange:true)
} else
if (value == "relayon6") {
createEvent (name:"relay6", value:"on", isStateChange:true)
} else
if (value == "relayoff6") {
createEvent (name:"relay6", value:"off", isStateChange:true)
} else
if (value == "relayon7") {
createEvent (name:"relay7", value:"on", isStateChange:true)
} else
if (value == "relayoff7") {
createEvent (name:"relay7", value:"off", isStateChange:true)
} else
if (value == "relayon8") {
createEvent (name:"relay8", value:"on", isStateChange:true)
} else
if (value == "relayoff8") {
createEvent (name:"relay8", value:"off", isStateChange:true)
}
}