2 * Copyright 2015 SmartThings
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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
13 * When It's Going To Rain
18 name: "When It's Going to Rain",
19 namespace: "smartthings",
20 author: "SmartThings",
21 description: "Is your shed closed? Are your windows shut? Is the grill covered? Are your dogs indoors? Will the lawn and plants need to be watered tomorrow?",
22 category: "Convenience",
23 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/text.png",
24 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/text@2x.png"
28 section("Zip code..."){
29 input "zipcode", "text", title: "Zipcode?"
31 // TODO: would be nice to cron this so we could check every hour or so
32 section("Check at..."){
33 input "time", "time", title: "When?"
35 section("Things to check..."){
36 input "sensors", "capability.contactSensor", multiple: true
38 section("Text me if I anything is open..."){
39 input("recipients", "contact", title: "Send notifications to") {
40 input "phone", "phone", title: "Phone number?"
47 log.debug "Installed: $settings"
48 schedule(time, "scheduleCheck")
52 log.debug "Updated: $settings"
54 schedule(time, "scheduleCheck")
58 def response = getWeatherFeature("forecast", zipcode)
59 if (isStormy(response)) {
60 def open = sensors.findAll { it?.latestValue("contact") == 'open' }
62 if (location.contactBookEnabled) {
63 sendNotificationToContacts("A storm is a coming and the following things are open: ${open.join(', ')}", recipients)
66 sendSms(phone, "A storm is a coming and the following things are open: ${open.join(', ')}")
72 private isStormy(json) {
73 def STORMY = ['rain', 'snow', 'showers', 'sprinkles', 'precipitation']
75 def forecast = json?.forecast?.txt_forecast?.forecastday?.first()
77 def text = forecast?.fcttext?.toLowerCase()
80 for (int i = 0; i < STORMY.size() && !result; i++) {
81 result = text.contains(STORMY[i])
88 log.warn "Did not get a forecast: $json"