-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPerimeterCheck smartapp
44 lines (38 loc) · 1.12 KB
/
PerimeterCheck smartapp
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
definition(
name: "Perimeter Check",
namespace: "dzelenka",
author: "Chris Hanson",
description: "Turn on a light when the perimeter is secure, and turn it off when the perimeter is broken.",
category: "Safety & Security",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")
preferences {
section ("Perimeter devices:") {
input "contacts", "capability.contactSensor", title: "Which?", multiple: true
}
section ("Turn on light:") {
input "perimeterSwitch", "capability.switch"
}
}
def installed() {
initialize()
}
def updated() {
unsubscribe()
initialize()
}
def initialize() {
subscribe(contacts, "contact", contactsHandler)
}
def contactsHandler(evt) {
log.debug "EV $evt.value"
if (evt.value == "open") {
perimeterSwitch.off()
} else if ( ! anyOpen(contacts) ) {
perimeterSwitch.on()
}
}
def anyOpen(obj) {
return obj.currentValue("contact").toString().contains("open")
}