I am writing a custom app to control my humidity. I am using state variables to keep track of my state machine.
in my app settings I see the state variables, but they are not retaining their values.
my code initializes the state variables:
def installed() {
logDebug "Installed with settings: ${settings}"
unsubscribe()
initialize()
}def updated() {
logDebug "Installed with settings: ${settings}"
unsubscribe()
initialize()
}def initialize() {
state.relay = 0;
state.timer = 0;
runEvery1Minute(CalculateFeedback)
}
My state machine that uses the state variables, this is the only code that uses or references the state variables:
switch(state.relay) { case 0: if (averageIndoorHumidity < tempTargetHumidity) { state.relay = 1 state.timer = WaterOnTime; // Turn on the Water Relays humidifierSwitches.each { it.on() } logDebug "Turn On the Water Relay" } else { state.timer = 0 humidifierSwitches.each { it.off() } } break; case 1: if (state.timer > 0) { state.timer = state.timer - 1 humidifierSwitches.each { it.on() } } else { state.relay = 2 state.timer = WaterOffTime // Turn off the water relays humidifierSwitches.each { it.off() } logDebug "Turn off the Water Relay" } break; case 2: if (state.timer > 0) { state.timer = state.timer - 1 humidifierSwitches.each { it.off() } } else { state.relay = 0 } break; default: logDebug "Fell into the default state!!" state.relay = 0 state.timer = 0 break; }
These were working previously and now every iteration the state.relay and state.timer are equal to 0.
I don't know if it broke from a code change or from modifying settings. But I have removed the smart app and reinstalled it and it still isn't working. I have also tried to reboot the hub but I have the same experiance.
Any suggestions?