Update beacon-control.groovy
[smartapps.git] / official / smartweather-station-controller.groovy
1 /**
2  *  Weather Station Controller
3  *
4  *  Copyright 2014 SmartThings
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7  *  in compliance with the License. You may obtain a copy of the License at:
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
12  *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
13  *  for the specific language governing permissions and limitations under the License.
14  *
15  */
16
17 definition(
18     name: "SmartWeather Station Controller",
19     namespace: "smartthings",
20     author: "SmartThings",
21     description: "Updates SmartWeather Station Tile devices every hour.",
22     category: "Convenience",
23     iconUrl: "https://s3.amazonaws.com/smartapp-icons/SafetyAndSecurity/App-MindYourHome.png",
24     iconX2Url: "https://s3.amazonaws.com/smartapp-icons/SafetyAndSecurity/App-MindYourHome@2x.png"
25 )
26
27 preferences {
28         section {
29                 input "weatherDevices", "device.smartweatherStationTile"
30         }
31 }
32
33 def installed() {
34         log.debug "Installed with settings: ${settings}"
35
36         initialize()
37 }
38
39 def updated() {
40         log.debug "Updated with settings: ${settings}"
41
42         unschedule()
43         initialize()
44 }
45
46 def initialize() {
47     scheduledEvent()
48 }
49
50 def scheduledEvent() {
51         log.info "SmartWeather Station Controller / scheduledEvent terminated due to deprecation" // device handles this itself now -- Bob
52 /*
53         log.trace "scheduledEvent()"
54
55         def delayTimeSecs = 60 * 60 // reschedule every 60 minutes
56         def runAgainWindowMS = 58 * 60 * 1000 // can run at most every 58 minutes
57         def timeSinceLastRunMS = state.lastRunTime ? now() - state.lastRunTime : null //how long since it last ran?
58
59         if(!timeSinceLastRunMS || timeSinceLastRunMS > runAgainWindowMS){
60                 runIn(delayTimeSecs, scheduledEvent, [overwrite: false])
61                 state.lastRunTime = now()
62                 weatherDevices.refresh()
63         } else {
64                 log.trace "Trying to run smartweather-station-controller too soon. Has only been ${timeSinceLastRunMS} ms but needs to be at least ${runAgainWindowMS} ms"
65         }
66     */
67 }