I'm simply trying to read and write some hub variables in an app. I'm getting this error:
2021-12-20 02:17:00.060 pm errororg.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'null' with class 'null' to class 'int'. Try 'java.lang.Integer' instead on line 92 (method midnightTask)
I have set the variable to a value in the Hub Variables page. I must have something very basic wrong. Code below. I have commented where line 92 is. I appreciate any help with this, or with anything you see that could be done better! Thanks!
definition(
...)preferences {
page(name: "pageConfig")
}def pageConfig() {
dynamicPage(name: "", title: "", install: true, uninstall: true, refreshInterval:0) {section("Inputs") { input "pauseSchedule", "capability.switch", title: "Pause Schedule", required: true input "inShopToday", "capability.switch", title: "In Shop Today", required: true input "inOfficeToday", "capability.switch", title: "In Office Today", required: true input "runningNightShift", "capability.switch", title: "Running Night Shift", required: true input "daysToResume", "capability.variable", title: "Days To Resume", required: true input "officeThermostat", "capability.thermostat", title: "Office Thermostat", required: true input "eastShopThermostat", "capability.thermostat", title: "East Shop Thermostat", required: true input "westShopThermostat", "capability.thermostat", title: "West Shop Thermostat", required: true input "outsideTemperature", "capability.temperatureMeasurement", title: "Outside Temperature", required: true }
}
}def installed(switchInstance) {
log.debug "installed"
initialize()
}
def updated() {
log.debug "updated"
unsubscribe()
initialize()
}
def initialize() {
log.debug "initialize"
unschedule()
unsubscribe()subscribe(location, "mode", modeEvent)
runEvery1Minute(checkDevices)
schedule("0 * * ? * *", midnightTask)//Refresh devices
runRefresh()
}def uninstalled() {
log.debug "uninstalled"
}// Schedule refresh
def modeEvent(evt) {
log.info "New mode at " + now() + " is " + location.mode
// Force Refresh now!
refresh()
}def checkDevices() {
log.debug "checkDevices " + pauseSchedule.currentValue("switch")
res = officeThermostat.currentValue("heatingSetpoint")
log.debug "office setpoint " + res
log.debug "outside temp " + outsideTemperature.currentValue("temperature")
log.debug "runningNightShift = " + runningNightShift.currentValue("switch")
log.debug "daysToResume = " + daysToResume.currentValue("variable")
}def midnightTask() {
log.debug "midnight task start"
//THIS IS LINE 92:
int res = daysToResume.currentValue("variable")
log.debug "res = " + res //+ daysToResume.currentValue("variable")
if (res > 0) {
res = res - 1
daysToResume = res //.setVariable(res)
}
}def refresh() {
log.debug "refresh"
}def runRefresh() {
log.debug "runRefresh"
checkDevices()
}