Hi there,
I am pretty new to SmartThings. I created below smart app doing some copy and paste from other users smart apps.
The idea behind this smart app is to turn on a Dehumidifier, connected to a smart switch, if the humidity from a sensor exceed a certain value. Thereafter turn it off when the humidity goes below a lower humidity value. This is because I do not want the Dehumidifier keeping on going on and off every hour around a single humidity value but I want it to “suck” humidity away up to a lower value so that it will take longer to reach the high humidity value and start the Dehumidifier again.
So far so good. The app is working (although probably is not perfectly written).
Now, to save on the energy bills, I would like to ensure that the dehumidifier goes on if the humidity is above a certain value but only with-in a specific time of the day (my plan is to get the dehumidifier going only at night between 2AM and 6AM when electricity is cheaper in my area).
I put in the start time and the end time but I have no idea how to create the event handler and other items needed to work.
Here below is the code. Any help?
/**
* SMART Dehumidifier
* Date: 2015-05-14
*/
definition(
name: "SMART Dehumidifier",
namespace: "SMART-D",
author: "CMP",
description: "When the humidity level goes above a certain value, turn on a switched dehumidifier. When that value drops below a separate threshold, turn off the dehumidifier.",
category: "Convenience",
iconUrl: "https://graph.api.smartthings.com/api/devices/icons/st.Weather.weather12-icn",
iconX2Url: "https://graph.api.smartthings.com/api/devices/icons/st.Weather.weather12-icn?displaySize=2x"
)
preferences
{
section("Monitor the humidity...")
{
input "humiditySensor1", "capability.relativeHumidityMeasurement", title: "Humidity Sensor?", required: true
}
section("Choose a Switch that controls a dehumidifier...")
{
input "fanSwitch1", "capability.switch", title: "Dehumidifier Location?", required: true
}
section("Turn dehumidifier on when the humidity is above:")
{
input "humidityUP", "number", title: "Humidity Upper Threshold (%)?"
}
section("Turn dehumidifier off when the humidity returns below:")
{
input "humidityDW", "number", title: "Humidity Lower Threshold (%)?"
}
section("Turn on only during this timeframe")
{
input "starting", "time", title: "Start time", required: true
input "ending", "time", title: "End time", required: true
}
section("Send this message (optional, sends standard status message if not specified)")
{
input "messageText", "text", title: "Message Text", required: false
}
section("Via a push notification and/or an SMS message")
{
input("recipients", "contact", title: "Send notifications to")
{
input "pushAndPhone", "enum", title: "Both Push and SMS?", required: false, options: ["Yes", "No"]
input "phone", "phone", title: "Main Phone Number (use sign + for country code)", required: true
}
}
}
def installed()
{
subscribe(humiditySensor1, "humidity", humidityHandler)
log.debug "Installed with settings: ${settings}"
}
def updated()
{
unsubscribe()
subscribe(humiditySensor1, "humidity", humidityHandler)
log.debug "Updated with settings: ${settings}"
}
def humidityHandler(evt)
{
log.debug "Humidity: $evt.value, $evt.unit, $evt.name, $evt"
def humNum = Double.parseDouble(evt.value.replace("%", ""))
def tooHumidNum = humidityUP
double tooHumid = tooHumidNum
def OKHumidNum = humidityDW
double OKHumid = OKHumidNum
def mySwitch = settings.fanSwitch1
log.debug "Current Humidity: $humNum, Humidity Setting: $tooHumid"
def msg = messageText ?: defaultText(evt)
log.debug "$evt.name:$evt.value, pushAndPhone:$pushAndPhone, '$msg'"
// ********************************************************************** def time interval *****************************************************
if (humNum >= tooHumid)
{
// ********************************************************************** def if time is between x and y *****************************************************
log.debug "Humidity is very high"
if ( fanSwitch1.currentValue("switch") == "off" )
{
if (location.contactBookEnabled)
{
sendNotificationToContacts(msg, recipients)
}
else
{
if (!phone || pushAndPhone != "No")
{
log.debug "sending push"
sendPush(msg)
}
if (phone)
{
log.debug "sending SMS"
sendSms(phone, msg)
}
}
fanSwitch1.on()
}
}
else
{
if (humNum <= OKHumid)
{
log.debug "Humidity is back to normal"
if ( fanSwitch1.currentValue("switch") == "on" )
{
if (location.contactBookEnabled)
{
sendNotificationToContacts("Humidity is back to normal", recipients)
}
else
{
if (!phone || pushAndPhone != "No")
{
log.debug "sending push"
sendPush("Humidity is back to normal")
}
if (phone)
{
log.debug "sending SMS"
sendSms(phone, "Humidity is back to normal")
}
}
fanSwitch1.off()
}
}
}
}