Update WindowOrDoorOpen.groovy
[smartapps.git] / official / camera-power-scheduler.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  *  Schedule the Camera Power
14  *
15  *  Author: danny@smartthings.com
16  *  Date: 2013-10-07
17  */
18
19 definition(
20     name: "Camera Power Scheduler",
21     namespace: "smartthings",
22     author: "SmartThings",
23     description: "Turn the power on and off at a specific time. ",
24     category: "Available Beta Apps",
25     iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/dropcam-on-off-schedule.png",
26     iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/dropcam-on-off-schedule@2x.png"
27 )
28
29 preferences {
30         section("Camera power..."){
31                 input "switch1", "capability.switch", multiple: true
32         }
33         section("Turn the Camera On at..."){
34                 input "startTime", "time", title: "Start Time", required:false
35         }
36         section("Turn the Camera Off at..."){
37                 input "endTime", "time", title: "End Time", required:false
38         }    
39 }
40
41 def installed()
42 {
43         initialize()
44 }
45
46 def updated()
47 {
48         unschedule()
49         initialize()
50 }
51
52 def initialize() {
53     /*
54         def tz = location.timeZone
55     
56     //if it's after the startTime but before the end time, turn it on
57     if(startTime && timeToday(startTime,tz).time > timeToday(now,tz).time){
58     
59       if(endTime && timeToday(endTime,tz).time < timeToday(now,tz).time){
60         switch1.on()
61       }
62       else{
63         switch1.off()
64       }
65     }
66     else if(endTime && timeToday(endtime,tz).time > timeToday(now,tz).time)
67     {
68       switch1.off()
69     }
70     */
71     
72     if(startTime)
73       runDaily(startTime, turnOnCamera)
74     if(endTime)
75       runDaily(endTime,turnOffCamera)
76 }
77
78 def turnOnCamera()
79 {
80   log.info "turned on camera"
81   switch1.on()
82 }
83
84 def turnOffCamera()
85 {
86   log.info "turned off camera"
87   switch1.off()
88 }