QuantityType to be used in Timer

Hi there,

I’ve got an Item of type Number:Time (Unit h) and I need to use it’s value for creating a Timer => createTimer(now.plusSeconds(timerVal))
But all I get are exceptions :wink:
I tried it using the state of the item. I did convert it to seconds - no luck. I also struggle to make sense of the exception thrown:

Could not invoke method: java.time.ZonedDateTime.plusSeconds(long) on instance: 2023-12-28T19:51:20.063208513+01:00[Europe/Berlin]

So how do I do it correctly?

I assume this is Rules DSL?

In JS Scripting it’s as simple as using createTimer(time.toZDT(items.MyTimeItem), () => ...).

Because your unit is hours, why are you using plusSeconds() instead of plusHours()?

Either way, you need to get down to the value without units.

    val seconds = (MyItem.state as QuantityType<Time>).toUnit('s').intValue
    createTimer(now.plusSeconds(seconds), [ | ... ])

timerVal appears to be a ZonedDateTime, not a primitive int or long.

“I assume this is Rules DSL?”
Yes.

" why are you using plusSeconds() instead of plusHours()"
I got an exception and thought it might be because it didn’t like ‘plusHours’.

I’m now back on hours using this :point_down: to get to the value.

var int timerVal = (PoolDesiredDuration.state as QuantityType<Number>).intValue

Thank you for getting me back on track.