Update 01-control-lights-and-locks-with-contact-sensor.groovy
[smartapps.git] / official / once-a-day.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  *  Once a Day
14  *
15  *  Author: SmartThings
16  *
17  *  Turn on one or more switches at a specified time and turn them off at a later time.
18  */
19
20 definition(
21     name: "Once a Day",
22     namespace: "smartthings",
23     author: "SmartThings",
24     description: "Turn on one or more switches at a specified time and turn them off at a later time.",
25     category: "Convenience",
26     iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet.png",
27     iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet@2x.png"
28 )
29
30 preferences {
31         section("Select switches to control...") {
32                 input name: "switches", type: "capability.switch", multiple: true
33         }
34         section("Turn them all on at...") {
35                 input name: "startTime", title: "Turn On Time?", type: "time"
36         }
37         section("And turn them off at...") {
38                 input name: "stopTime", title: "Turn Off Time?", type: "time"
39         }
40 }
41
42 def installed() {
43         log.debug "Installed with settings: ${settings}"
44         schedule(startTime, "startTimerCallback")
45         schedule(stopTime, "stopTimerCallback")
46
47 }
48
49 def updated(settings) {
50         unschedule()
51         schedule(startTime, "startTimerCallback")
52         schedule(stopTime, "stopTimerCallback")
53 }
54
55 def startTimerCallback() {
56         log.debug "Turning on switches"
57         switches.on()
58
59 }
60
61 def stopTimerCallback() {
62         log.debug "Turning off switches"
63         switches.off()
64 }