4 * Copyright 2014 Brian Critchlow
5 * Based on Its too cold code by 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.
17 name: "Humidity Alert!",
18 namespace: "docwisdom",
19 author: "Brian Critchlow",
20 description: "Notify me when the humidity rises above or falls below the given threshold. It will turn on a switch when it rises above the first threshold and off when it falls below the second threshold.",
21 category: "Convenience",
22 iconUrl: "https://graph.api.smartthings.com/api/devices/icons/st.Weather.weather9-icn",
23 iconX2Url: "https://graph.api.smartthings.com/api/devices/icons/st.Weather.weather9-icn?displaySize=2x"
28 section("Monitor the humidity of:") {
29 input "humiditySensor1", "capability.relativeHumidityMeasurement"
31 section("When the humidity rises above:") {
32 input "humidity1", "number", title: "Percentage ?"
34 section("When the humidity falls below:") {
35 input "humidity2", "number", title: "Percentage ?"
37 section( "Notifications" ) {
38 input "sendPushMessage", "enum", title: "Send a push notification?", metadata:[values:["Yes","No"]], required:false
39 input "phone1", "phone", title: "Send a Text Message?", required: false
41 section("Control this switch:") {
42 input "switch1", "capability.switch", required: false
47 subscribe(humiditySensor1, "humidity", humidityHandler)
52 subscribe(humiditySensor1, "humidity", humidityHandler)
55 def humidityHandler(evt) {
56 log.trace "humidity: ${evt.value}"
57 log.trace "set point: ${humidity1}"
59 def currentHumidity = Double.parseDouble(evt.value.replace("%", ""))
60 def tooHumid = humidity1
61 def notHumidEnough = humidity2
62 def mySwitch = settings.switch1
65 def timeAgo = new Date(now() - (1000 * 60 * deltaMinutes).toLong())
66 def recentEvents = humiditySensor1.eventsSince(timeAgo)
67 log.trace "Found ${recentEvents?.size() ?: 0} events in the last ${deltaMinutes} minutes"
68 def alreadySentSms = recentEvents.count { Double.parseDouble(it.value.replace("%", "")) >= tooHumid } > 1 || recentEvents.count { Double.parseDouble(it.value.replace("%", "")) <= notHumidEnough } > 1
70 if (currentHumidity >= tooHumid) {
71 log.debug "Checking how long the humidity sensor has been reporting >= ${tooHumid}"
73 // Don't send a continuous stream of text messages
78 log.debug "Notification already sent within the last ${deltaMinutes} minutes"
81 log.debug "Humidity Rose Above ${tooHumid}: sending SMS and activating ${mySwitch}"
82 send("${humiditySensor1.label} sensed high humidity level of ${evt.value}")
87 if (currentHumidity <= notHumidEnough) {
88 log.debug "Checking how long the humidity sensor has been reporting <= ${notHumidEnough}"
91 log.debug "Notification already sent within the last ${deltaMinutes} minutes"
94 log.debug "Humidity Fell Below ${notHumidEnough}: sending SMS and activating ${mySwitch}"
95 send("${humiditySensor1.label} sensed high humidity level of ${evt.value}")
102 if ( sendPushMessage != "No" ) {
103 log.debug( "sending push message" )
108 log.debug( "sending text message" )
109 sendSms( phone1, msg )