Item state as a Timer

Hi, i have an item and want its state to define a timer

Number myTimerItem "Timer"

It stores its value like “11.0”

val Timer timer = null
// rule stuff
    timer = createTimer(now.plusSeconds(myTimerItem.state)

I tested different methods but i did not figure it out.
i tried:
myTimerItem.state as Number
myTimerItem.state as Integer

Nothing works. What am i doing wrong? The timer works correctly, if i just put in a random digit

try myTimerItem.state.intValue. The “plusSeconds” need a integer and state is a String AFAIR.

Does not work.

Script execution of rule with UID 'ZigBee-3' failed: 'intValue' is not a member of 'org.openhab.core.types.State'

was untested! :wink:
try this, this must work,…

    var duration = (myTimeItem.state as Number).intValue
    timer = createTimer(now.plusSeconds(duration)
Script execution of rule with UID 'ZigBee-3' failed: An error occurred during the script execution: Could not invoke method: java.time.ZonedDateTime.plusSeconds(long) on instance: 2022-11-08T20:58:34.150644+01:00[Europe/Berlin] in ZigBee

ZigBee is my .rules file.

When saving the rules file, the console is prompting following:

Validation issues found in configuration model 'ZigBee.rules', using it anyway: Cannot reference the field 'myTimerItem' before it is defined

I found an answer:

timer = createTimer(now.plusSeconds(myTimerItem.state as DecimalType).intValue)

does the trick.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.