Update thermostat-mode-director.groovy
[smartapps.git] / official / turn-it-on-for-5-minutes.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  *  Turn It On For 5 Minutes
14  *  Turn on a switch when a contact sensor opens and then turn it back off 5 minutes later.
15  *
16  *  Author: SmartThings
17  */
18 definition(
19     name: "Turn It On For 5 Minutes",
20     namespace: "smartthings",
21     author: "SmartThings",
22     description: "When a SmartSense Multi is opened, a switch will be turned on, and then turned off after 5 minutes.",
23     category: "Safety & Security",
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 it opens..."){
30                 input "contact1", "capability.contactSensor"
31         }
32         section("Turn on a switch for 5 minutes..."){
33                 input "switch1", "capability.switch"
34         }
35 }
36
37 def installed() {
38         log.debug "Installed with settings: ${settings}"
39         subscribe(contact1, "contact.open", contactOpenHandler)
40 }
41
42 def updated(settings) {
43         log.debug "Updated with settings: ${settings}"
44         unsubscribe()
45         subscribe(contact1, "contact.open", contactOpenHandler)
46 }
47
48 def contactOpenHandler(evt) {
49         switch1.on()
50         def fiveMinuteDelay = 60 * 5
51         runIn(fiveMinuteDelay, turnOffSwitch)
52 }
53
54 def turnOffSwitch() {
55         switch1.off()
56 }