Hey all! I’m trying to create a simple timer using a Number Item like so:
Item:
Number TimerItem "Timer Tester"
Rule:
var Timer timer = null
rule "Test Timer Set"
when
Item TimerItem received update
then
val int hours = TimerItem.state
logInfo("Event logging", "Starting timer for " + hours + " hours, ending at " + now.plusHours(hours))
timer = createTimer(now.plusHours(hours), [|
logInfo("Event logging", "Timer ended")
timer = null // reset the timer
])
end
But createTimer doesn’t seem to like whatever format the item’s value is in, it errors with “Could not invoke method: org.joda.time.DateTime.plusHours(int) on instance: 2019-12-05T12:03:03.857-08:00”.
It works if I set 'hours" to a static int, e.g. “val int hours = 5”
So how can I convert a Number item’s value to an integer that createTimer will accept?