Update step-notifier.groovy
[smartapps.git] / official / let-there-be-light.groovy
1 /**
2  *  Copyright 2015 SmartThings
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  *  in compliance with the License. You may obtain a copy of the License at:
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
10  *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
11  *  for the specific language governing permissions and limitations under the License.
12  *
13  *  Let There Be Light!
14  *  Turn your lights on when an open/close sensor opens and off when the sensor closes.
15  *
16  *  Author: SmartThings
17  */
18 definition(
19     name: "Let There Be Light!",
20     namespace: "smartthings",
21     author: "SmartThings",
22     description: "Turn your lights on when a SmartSense Multi is opened and turn them off when it is closed.",
23     category: "Convenience",
24     iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_contact-outlet.png",
25     iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/light_contact-outlet@2x.png"
26 )
27
28 preferences {
29         section("When the door opens/closes...") {
30                 input "contact1", "capability.contactSensor", title: "Where?"
31         }
32         section("Turn on/off a light...") {
33                 input "switch1", "capability.switch"
34         }
35 }
36
37 def installed() {
38         subscribe(contact1, "contact", contactHandler)
39 }
40
41 def updated() {
42         unsubscribe()
43         subscribe(contact1, "contact", contactHandler)
44 }
45
46 def contactHandler(evt) {
47         log.debug "$evt.value"
48         if (evt.value == "open") {
49                 switch1.on()
50         } else if (evt.value == "closed") {
51                 switch1.off()
52         }
53 }