I looked at it and this is a bit too complex for me to parse through and understand. I sat down for a bit this afternoon and came up with this, thus far. What I need is a way to tell the app to look at the last measurement and if the current measurement is > last measurement + x (being whatever I set) then change mode to…
Anyway, this is what I have thus far.
/**
*/
definition(
name: “Shower Time!”,
namespace: “”,
author: “Justin Bennett”,
description: “This will set the mode to ‘ShowerTime’ when the humidity in the bathroom will rise by more than X percentage between measurements.”,
category: “Convenience”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”,
iconX3Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”)
preferences {
section(“How much (percentage) must the humidity rise to trigger a mode change?”) {
input “humidity”, "capability.relativeHumidityMeasurement"
input “humidity1”, “number”, title: "How much?"
input “newMode”, “mode”, title: “What Mode Are You Changing To?”
// TODO: put inputs here
}
}
def installed(){
subscribe(humidity, “humidity”, humidityEvent)
}
def humidityEvent(evt){
log.trace "Current Humidity is ${evt.value} as of ${evt.date}"
log.trace “set point ${humidity1}“
def currentHumidity = Double.parseDouble(evt.value.replace(”%”, “”))
def deltaMinutes = 5
def timeAgo = new Date(now() - (1000 * 60 * deltaMinutes).toLong())
def recentEvents = humidity.eventsSince(timeAgo)
log.trace "Found ${recentEvents?.size() ?: 0} events in the last ${deltaMinutes} minutes"
if (currentHumidity >= tooHumid) {
log.debug "Checking how long the humidity sensor has been reporting >= ${tooHumid}"
if (currentHumidity <= tooHumid) {
log.debug "Checking how long the humidity sensor has been reporting <= ${tooHumid}"
} else {
log.debug "GOT HERE"
}
}
}
// how do I set the tooHumid definition to = the last humidity + x to indicate that if Current humidity is > current humidity + x then siwtch mode.