Running following code:
rule "WSRainCounter update"
when
Item WSRainCounter changed or
Time cron " 0 0/1 * 1/1 * ? *"
then
try{
logInfo("WSRainCounter update Rule", "triggered")
val lastDelta = WSRainCounter.previousState(false, "influxdb").state
val lastHour = WSRainCounter.deltaSince(now.minusHours(1), "influxdb")
val last24h = WSRainCounter.deltaSince(now.minusHours(24), "influxdb")
val last7d = WSRainCounter.deltaSince(now.minusHours(7*24), "influxdb")
val last30d = WSRainCounter.deltaSince(now.minusHours(30*24), "influxdb")
logInfo("WSRainCounter update Rule", String.valueOf(lastDelta))
logInfo("WSRainCounter update Rule", String.valueOf(lastHour))
logInfo("WSRainCounter update Rule", String.valueOf(last24h))
// logInfo("WSRainCounter update Rule", String.valueOf(last7d))
// logInfo("WSRainCounter update Rule", String.valueOf(last30d))
if (WSRainLastHour.state as Number != lastHour as Number)
WSRainLastHour.postUpdate(lastHour as Number)
if (WSRainLast24h.state as Number != last24h as Number)
WSRainLast24h.postUpdate(last24h as Number)
if (WSRainLast7d.state as Number != last7d as Number)
WSRainLast7d.postUpdate(last7d as Number)
if (WSRainLast30d.state as Number != last30d as Number)
WSRainLast30d.postUpdate(last30d as Number)
if (WSRainLastDelta.state as Number != lastDelta as Number)
WSRainLastDelta.postUpdate(lastDelta as Number)
} catch(Exception e) {
// initiate items
logInfo("WSRainCounter update Rule", "exception")
WSRainLastDelta.postUpdate(0.0)
WSRainLastHour.postUpdate(0.0)
WSRainLast24h.postUpdate(0.0)
WSRainLast7d.postUpdate(0.0)
WSRainLast30d.postUpdate(0.0)
}
logInfo("WSRainCounter update Rule", "exit")
end
the log shows:
2018-05-25 09:09:00.019 [INFO ] [del.script.WSRainCounter update Rule] - triggered
2018-05-25 09:09:00.288 [INFO ] [del.script.WSRainCounter update Rule] - 556.959999
2018-05-25 09:09:00.293 [INFO ] [del.script.WSRainCounter update Rule] - 3.834999
2018-05-25 09:09:00.297 [INFO ] [del.script.WSRainCounter update Rule] - 13.275000
2018-05-25 09:09:00.324 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'WSRainCounter update': Could not cast NULL to java.lang.Number; line 27, column 13, length 31
That means that exception section is not executed