-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVirtualUniversalDevice.groovy
390 lines (353 loc) · 15 KB
/
VirtualUniversalDevice.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
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
/*
Universal virtual DTH
Copyright 2016 Mike Maxwell
1.0.7 2016-09-22 added smoke, water and sound thanks Scott
added not used option to each device tile
fixed bug in illuminance not working
1.0.5 2016-08-29 added sensor and actuator capabilities per Alex
1.0.4 2016-05-21 added LUX capability
1.0.3 2016-05-18 added optional auto off
1.0.2 2016-05-15 ignore duplicate input requests
added version info
This software if free for Private Use. You may use and modify the software without distributing it.
This software and derivatives may not be used for commercial purposes.
You may not distribute or sublicense this software.
You may not grant a sublicense to modify and distribute this software to third parties not included in the license.
Software is provided without warranty and the software author/license owner cannot be held liable for damages.
*/
metadata {
definition (name: "uDTH", namespace: "castlecole", author: "mike maxwell") {
capability "Sensor"
capability "Actuator"
//inputs
capability "Switch" //on, off
capability "Lock" //lock, unlock
//outputs
capability "Contact Sensor" //"open","closed"
capability "Motion Sensor" //"active", "inactive"
capability "Presence Sensor" //"present", "not present"
capability "Acceleration Sensor" //"active", "inactive"
capability "Illuminance Measurement"
capability "Smoke Detector" //"detected", "clear", "tested"
capability "Water Sensor" //"dry", "wet"
capability "Sound Sensor" //"detected", "not detected"
//both
capability "Door Control" //listen for "open", "close" respond with "open" "closed"
capability "Garage Door Control" //listen for "open", "close" respond with "open" "closed"
command "localOff"
command "localOn"
attribute "version", "string"
}
preferences {
def s1
def s2
def d
//paragraph input
input(
title : "uDTH version: ${getVersion()}"
,description : null
,type : "paragraph"
)
input(
title : "Device inputs\nRespond to these events/commands."
,description : null
,type : "icon"
,required : false
,defaultValue : "st.illuminance.illuminance.dark"
)
input(
name : "inSwitchOn"
,title : "Switch (on, off)"
,type : "bool"
,defaultValue : true
)
input(
name : "inDoorOn"
,title : "Door Control (open, close)"
,type : "bool"
,defaultValue : false
)
input(
name : "inGDoorOn"
,title : "Garge Door Control (open, close)"
,type : "bool"
,defaultValue : false
)
input(
name : "inLockOn"
,title : "Lock (lock, unlock)"
,type : "bool"
,defaultValue : false
)
input(
name : "autoOff"
,title : "Delayed device turn off (optional)"
,type : "enum"
,required : false
,options : [["5":"5 seconds"],["30":"30 seconds"],["60":"1 Minute"],["300":"5 Minutes"]]
)
input(
title : "Device outputs\nSend the events listed below."
,description : null
,type : "icon"
,required : false
,defaultValue : "st.illuminance.illuminance.dark"
)
d = "Contact"
s1 = "open"
s2 = "closed"
input(
name : "contactOn"
,title : buildTitle(d,s1,s2)
,type : "enum"
,options : buildOptions(d,s1,s2)
,description : contactOn ?: "Not Used"
)
d = "Motion"
s1 = "active"
s2 = "inactive"
input(
name : "motionOn"
,title : buildTitle(d,s1,s2)
,type : "enum"
,options : buildOptions(d,s1,s2)
,description : motionOn ?: "Not Used"
)
d = "Smoke"
s1 = "detected"
s2 = "clear"
input(
name : "smokeOn"
,title : buildTitle(d,s1,s2)
,type : "enum"
,options : buildOptions(d,s1,s2)
,description : smokeOn ?: "Not Used"
)
d = "Water"
s1 = "wet"
s2 = "dry"
input(
name : "waterOn"
,title : buildTitle(d,s1,s2)
,type : "enum"
,options : buildOptions(d,s1,s2)
,description : waterOn ?: "Not Used"
)
d = "Sound"
s1 = "detected"
s2 = "not detected"
input(
name : "soundOn"
,title : buildTitle(d,s1,s2)
,type : "enum"
,options : buildOptions(d,s1,s2)
,description : soundOn ?: "Not Used, Tap to enable..."
)
d = "Presence"
s1 = "present"
s2 = "not present"
input(
name : "presenceOn"
,title : buildTitle(d,s1,s2)
,type : "enum"
,options : buildOptions(d,s1,s2)
,description : presenceOn ?: "Not Used"
)
d = "Door"
s1 = "open"
s2 = "closed"
input(
name : "doorOn"
,title : buildTitle(d,s1,s2)
,type : "enum"
,options : buildOptions(d,s1,s2)
,description : doorOn ?: "Not Used"
)
d = "Acceleration"
s1 = "active"
s2 = "inactive"
input(
name : "accelOn"
,title : buildTitle(d,s1,s2)
,type : "enum"
,options : buildOptions(d,s1,s2)
,description : accelOn ?: "Not Used"
)
d = "Illuminance"
s1 = "0 Lux"
s2 = "50 Lux"
input(
name : "luxOn"
,title : buildTitle(d,s1,s2)
,type : "enum"
,options : buildOptions(d,s1,s2)
,description : luxOn ?: "Not Used"
)
}
simulator {
}
// tile definitions
tiles (scale:1) {
multiAttributeTile(name:"switch", type: "generic", width: 6, height: 2, canChangeIcon: true){
tileAttribute ("device.uDTH", key: "PRIMARY_CONTROL") {
attributeState "on", label: '${name}', action: "localOff", icon: "st.switches.switch.on", backgroundColor: "#53a7c0"
attributeState "off", label: '${name}', action: "localOn", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
}
}
standardTile("contact", "device.contact", inactiveLabel: false, height:2, width:2, canChangeIcon: false) {
state "default", label:"contact\nnot used" //, backgroundColor: "#ffffff"
state "closed", label:'${name}', backgroundColor: "#ffffff", icon:"st.contact.contact.closed"
state "open", label:'${name}', backgroundColor: "#53a7c0", icon:"st.contact.contact.open"
}
standardTile("motion", "device.motion", inactiveLabel: false, height:2, width:2, canChangeIcon: false) {
state "default", label: "motion\nnot used" //, icon:"st.motion.motion.inactive"
state "inactive", label:'${name}', backgroundColor: "#ffffff", icon:"st.motion.motion.inactive"
state "active", label:'${name}', backgroundColor: "#53a7c0", icon:"st.motion.motion.active"
}
standardTile("smoke", "device.smoke", inactiveLabel: false, height:2, width:2, canChangeIcon: false) {
state "default", label: "smoke\nnot used" //, icon:"st.alarm.smoke.clear"
state "clear", label:'${name}', backgroundColor: "#ffffff", icon:"st.alarm.smoke.clear"
state "detected", label:'${name}', backgroundColor: "#e86d13", icon:"st.alarm.smoke.smoke"
}
standardTile("water", "device.water", inactiveLabel: false, height:2, width:2, canChangeIcon: false) {
state "default", label: "water\nnot used" //, icon:"st.alarm.water.dry"
state "dry", label:'${name}', backgroundColor: "#ffffff", icon:"st.alarm.water.dry"
state "wet", label:'${name}', backgroundColor: "#53a7c0", icon:"st.alarm.water.wet"
}
standardTile("sound", "device.sound", inactiveLabel: false, height:2, width:2, canChangeIcon: false) {
state "default", label: "sound\nnot used" //, icon:"st.quirky.spotter.quirky-spotter-sound-off"
state "not detected", label:'${name}', backgroundColor: "#ffffff", icon:"st.quirky.spotter.quirky-spotter-sound-off"
state "detected", label:'${name}', backgroundColor: "#53a7c0", icon:"st.quirky.spotter.quirky-spotter-sound-on"
}
standardTile("present", "device.presence", inactiveLabel: false, height:2, width:2, canChangeIcon: false) {
state "default", label: "presence\nnot used"
state "not present", label:'${name}', backgroundColor: "#ffffff", icon:"st.presence.tile.presence-default"
state "present", label:'${name}', backgroundColor: "#53a7c0", icon:"st.presence.tile.presence-default"
}
standardTile("door", "device.door", inactiveLabel: false, height:2, width:2, canChangeIcon: false) {
state "default", label: "door\nnot used"
state "closed", label:'${name}', backgroundColor: "#ffffff", icon:"st.doors.garage.garage-closed"
state "open", label:'${name}', backgroundColor: "#53a7c0", icon:"st.doors.garage.garage-open"
}
standardTile("accel", "device.acceleration", inactiveLabel: false, height:2, width:2, canChangeIcon: false) {
state "default", label: "acceleration\nnot used"
state "inactive", label:'${name}', backgroundColor: "#ffffff", icon:"st.motion.acceleration.inactive"
state "active", label:'${name}', backgroundColor: "#53a7c0", icon:"st.motion.acceleration.active"
}
standardTile("lux", "device.lux", inactiveLabel: false, height:2, width:2, canChangeIcon: false) {
state "default", label: "illuminance\nnot used"
state "dark", label:'${name}', backgroundColor: "#ffffff", icon:"st.illuminance.illuminance.dark"
state "bright", label:'${name}', backgroundColor: "#ecf23a", icon:"st.illuminance.illuminance.bright"
}
main(["switch"])
details(["switch","contact","motion","smoke","water","sound","present","door","accel","lux"])
}
}
def open(){
if (inDoorOn || inGDoorOn) localOn()
}
def close(){
if (inDoorOn || inGDoorOn) localOff()
}
def lock(){
if (inLockOn) localOn()
}
def unlock(){
if (inLockOn) localOff()
}
def on(){
if (inSwitchOn) localOn()
}
def off(){
if (inSwitchOn) localOff()
}
def buildTitle(d,s1,s2){
return "${d} (${s1}, ${s2})"
}
def buildOptions(d,s1,s2){
def sOn = "on"
def sOff = "off"
def options = []
options.add(["1":"when ${sOn} set ${d} to '${s1}'\nwhen ${sOff} set ${d} to '${s2}'"])
options.add(["0":"when ${sOn} set ${d} to '${s2}'\nwhen ${sOff} set ${d} to '${s1}'"])
options.add(["-1":"Not Used"])
return options
}
def syncDevices(cmd){
if (cmd == null) cmd = device.currentValue("uDTH") == "on" ? "1" : "0"
//log.debug "cmd: ${cmd}"
if (contactOn in ["0","1"]){
if (contactOn == cmd) sendEvent(name: "contact", value: "open") //"when on send 'open'\nwhen off send 'closed'"
else sendEvent(name: "contact", value: "closed") //"when on send 'closed'\nwhen off send 'open'"
} else sendEvent(name: "contact", value: null, displayed : false)
if (motionOn in ["0","1"]){
if (motionOn == cmd) sendEvent(name: "motion", value: "active") //"when on send 'active'\nwhen off send 'inactive'"
else sendEvent(name: "motion", value: "inactive") //"when on send 'inactive'\nwhen off send 'active'"
} else sendEvent(name: "motion", value: null, displayed : false)
if (smokeOn in ["0","1"]){
if (smokeOn == cmd) sendEvent(name: "smoke", value: "detected") //"when on send 'detected'\nwhen off send 'clear'"
else sendEvent(name: "smoke", value: "clear") //"when on send 'clear'\nwhen off send 'detected'"
} else sendEvent(name: "smoke", value: null, displayed : false)
if (waterOn in ["0","1"]){
if (waterOn == cmd) sendEvent(name: "water", value: "wet") //"when on send 'wet'\nwhen off send 'dry'"
else sendEvent(name: "water", value: "dry") //"when on send 'dry'\nwhen off send 'wet'"
} else sendEvent(name: "water", value: null, displayed : false)
if (soundOn in ["0","1"]){
if (soundOn == cmd) sendEvent(name: "sound", value: "detected") //"when on send 'detected'\nwhen off send 'not detected'"
else sendEvent(name: "sound", value: "not detected") //"when on send 'not detected'\nwhen off send 'detected'"
} else sendEvent(name: "sound", value: null, displayed : false)
if (presenceOn in ["0","1"]){
if (presenceOn == cmd) sendEvent(name: "presence", value: "present") //"when on send 'present'\nwhen off send 'not present'"
else sendEvent(name: "presence", value: "not present") //"when on send 'not present'\nwhen off send 'present'"
} else sendEvent(name: "presence", value: null, displayed : false)
if (doorOn in ["0","1"]){
if (doorOn == cmd) sendEvent(name: "door", value: "open") //"when on send 'active'\nwhen off send 'inactive'"
else sendEvent(name: "door", value: "closed") //"when on send 'inactive'\nwhen off send 'active'"
} else sendEvent(name: "door", value: null, displayed : false)
if (accelOn in ["0","1"]){
if (accelOn == cmd) sendEvent(name: "acceleration", value: "active")
else sendEvent(name: "acceleration", value: "inactive")
} else sendEvent(name: "acceleration", value: null, displayed : false)
if (luxOn in ["0","1"]){
if (luxOn == cmd){
sendEvent(name: "illuminance", value: 50)
sendEvent(name: "lux", value: "bright", displayed : false)
} else {
sendEvent(name: "illuminance", value: 0)
sendEvent(name: "lux", value: "dark", displayed : false)
}
} else {
sendEvent(name: "illuminance", value: null, displayed : false)
sendEvent(name: "lux", value: null, displayed : false)
}
}
def localOn() {
if (device.currentValue("uDTH") != "on"){
log.info "on request: OK"
sendEvent(name: "uDTH", value: "on" ,displayed: false)
syncDevices("1")
if (autoOff) runIn(autoOff.toInteger(),localOff)
} else {
log.info "on request: duplicate, ignored"
}
}
def localOff() {
if (device.currentValue("uDTH") != "off"){
log.info "off request: OK"
sendEvent(name: "uDTH", value: "off" ,displayed: false)
syncDevices("0")
} else {
log.info "off request: duplicate, ignored"
}
}
def getVersion(){
return "1.0.7"
}
//capture preference changes
def updated() {
sendEvent( name: "version", value: getVersion(), displayed: false)
//log.debug "syncDevices"
syncDevices(null)
}
def configure() {
}