forked from twack/smarthings-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Turn-on-Police-Light-When-It-Opens.groovy
49 lines (43 loc) · 1.24 KB
/
Turn-on-Police-Light-When-It-Opens.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
/**
* Turn on Police Light When It Opens
*
* Author: SmartThings
*/
definition(
name: "Turn on Police Light When It Opens",
namespace: "smartthings",
author: "SmartThings",
description: "Turn something on when an open/close sensor opens.",
category: "My Apps",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_contact-outlet.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/light_contact-outlet@2x.png"
)
preferences {
section("When the door opens..."){
input "contact1", "capability.contactSensor", title: "Where?"
}
section("Turn on the Fibaro Police Light..."){
input "switches", "capability.switch", multiple: false
}
}
def installed()
{
subscribe(contact1, "contact.open", contactOpenHandler)
subscribe(contact1, "contact.closed", contactClosedHandler)
}
def updated()
{
unsubscribe()
subscribe(contact1, "contact.open", contactOpenHandler)
subscribe(contact1, "contact.closed", contactclosedHandler)
}
def contactOpenHandler(evt) {
log.debug "$evt.value: $evt, $settings"
log.trace "Turning on switches: $switches"
switches.police()
}
def contactclosedHandler(evt) {
log.debug "$evt.value: $evt, $settings"
log.trace "Turning on switches: $switches"
switches.off()
}