2 * Weather Station Controller
4 * Copyright 2014 SmartThings
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
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"
29 input "weatherDevices", "device.smartweatherStationTile"
34 log.debug "Installed with settings: ${settings}"
40 log.debug "Updated with settings: ${settings}"
50 def scheduledEvent() {
51 log.info "SmartWeather Station Controller / scheduledEvent terminated due to deprecation" // device handles this itself now -- Bob
53 log.trace "scheduledEvent()"
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?
59 if(!timeSinceLastRunMS || timeSinceLastRunMS > runAgainWindowMS){
60 runIn(delayTimeSecs, scheduledEvent, [overwrite: false])
61 state.lastRunTime = now()
62 weatherDevices.refresh()
64 log.trace "Trying to run smartweather-station-controller too soon. Has only been ${timeSinceLastRunMS} ms but needs to be at least ${runAgainWindowMS} ms"