4 * Copyright 2014 Sheikh Dawood
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: "Smart Humidifier",
18 namespace: "Sheikhsphere",
19 author: "Sheikh Dawood",
20 description: "Turn on/off humidifier based on relative humidity from a sensor.",
21 category: "Convenience",
22 iconUrl: "https://graph.api.smartthings.com/api/devices/icons/st.Weather.weather12-icn",
23 iconX2Url: "https://graph.api.smartthings.com/api/devices/icons/st.Weather.weather12-icn?displaySize=2x"
28 section("Monitor the humidity of:") {
29 input "humiditySensor1", "capability.relativeHumidityMeasurement"
31 section("When the humidity rises above:") {
32 input "humidityHigh", "number", title: "Percentage ?"
34 section("When the humidity drops below:") {
35 input "humidityLow", "number", title: "Percentage ?"
37 section("Control Humidifier:") {
38 input "switch1", "capability.switch"
40 section( "Notifications" ) {
41 input "sendPushMessage", "enum", title: "Send a push notification?", metadata:[values:["Yes","No"]], required:false
42 input "phone1", "phone", title: "Send a Text Message?", 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 high point: $humidityHigh"
58 log.trace "set low point: $humidityLow"
60 def currentHumidity = Double.parseDouble(evt.value.replace("%", ""))
61 def humidityHigh1 = humidityHigh
62 def humidityLow1 = humidityLow
63 def mySwitch = settings.switch1
65 if (currentHumidity >= humidityHigh1) {
66 log.debug "Checking how long the humidity sensor has been reporting >= $humidityHigh1"
68 // Don't send a continuous stream of text messages
70 def timeAgo = new Date(now() - (1000 * 60 * deltaMinutes).toLong())
71 def recentEvents = humiditySensor1.eventsSince(timeAgo)
72 log.trace "Found ${recentEvents?.size() ?: 0} events in the last $deltaMinutes minutes"
73 def alreadySentSms1 = recentEvents.count { Double.parseDouble(it.value.replace("%", "")) >= humidityHigh1 } > 1
75 if (alreadySentSms1) {
76 log.debug "Notification already sent within the last $deltaMinutes minutes"
79 if (state.lastStatus != "off") {
80 log.debug "Humidity Rose Above $humidityHigh1: sending SMS and deactivating $mySwitch"
81 send("${humiditySensor1.label} sensed high humidity level of ${evt.value}, turning off ${switch1.label}")
83 state.lastStatus = "off"
87 else if (currentHumidity <= humidityLow1) {
88 log.debug "Checking how long the humidity sensor has been reporting <= $humidityLow1"
90 // Don't send a continuous stream of text messages
92 def timeAgo = new Date(now() - (1000 * 60 * deltaMinutes).toLong())
93 def recentEvents = humiditySensor1.eventsSince(timeAgo)
94 log.trace "Found ${recentEvents?.size() ?: 0} events in the last $deltaMinutes minutes"
95 def alreadySentSms2 = recentEvents.count { Double.parseDouble(it.value.replace("%", "")) <= humidityLow1 } > 1
97 if (alreadySentSms2) {
98 log.debug "Notification already sent within the last $deltaMinutes minutes"
101 if (state.lastStatus != "on") {
102 log.debug "Humidity Dropped Below $humidityLow1: sending SMS and activating $mySwitch"
103 send("${humiditySensor1.label} sensed low humidity level of ${evt.value}, turning on ${switch1.label}")
105 state.lastStatus = "on"
110 //log.debug "Humidity remained in threshold: sending SMS to $phone1 and activating $mySwitch"
111 //send("${humiditySensor1.label} sensed humidity level of ${evt.value} is within threshold, keeping on ${switch1.label}")
117 if ( sendPushMessage != "No" ) {
118 log.debug( "sending push message" )
123 log.debug( "sending text message" )
124 sendSms( phone1, msg )