Timer in OH3 JAVA 11

  • Platform information:
    • Hardware:PC
    • OS: WIN 10
    • Java Runtime Environment: JRE 11
    • openHAB version: 3.4.3
      At first: I´m not good in programming, so i have a lot of problems with OH 3.4.3
      As this version of OH 3 on PC with WIN10 needs JAVA11 my rules with timers are not working.
      I tried for days to find a solution for my problem, but all blogs i found did not really fit do my problems and many explations i could not understand!
      I figguerd out, the Problem must be the difference between JAVA 8 and JAVA 11. In JAVA 8 this rules is working.
      I tried some examples for timers, but they only work with
      createTimer(now.plusMinutes(10)
      not with
      createTimer(now.plusMinutes((Item.state as DecimalType)
      or
      createTimer(now.plusMinutes((Item.state as Number)

log INFO:
An error occurred during the script execution: Could not invoke method: java.time.Instant.plusMinutes(long) on instance: 2023-05-02T11:29:49.520329600Z

So my Question:
What to do, that my Rules:

rule “Bewässerung”
when
Item Sonoff_2_Bewaesserung changed from OFF to ON
then
createTimer(now.plusMinutes((Laufzeit_Sonoff_2_mm.state as DecimalType).intValue), [ |
Sonoff_2_Bewaesserung.sendCommand (OFF)])
end

is working in JAVA 11

Thanks for help!

When posting code or logs, please use code fences.

```
code goes here
```

Also be sure to make it clear what rules language you are referring to.

When. it comes to timers, the only difference between OH 2.5 (which runs on Java 8) and OH 3.x (which runs on Java 11) has to do with the replacement of the Joda date time library with what’s built into Java. There are a few minor differences between the two.

That should work

That never would have worked.

This also never would have worked.

This should work assuming that the Item is a Number Item and the state is neither NULL, UNDEF, nor a QuantityType.

Thanks for quik answer!
I just tried this rules in OH3.3 on openhabianpi
It is working!

rule "Test" 
when
Item Sonoff_4_Energieraum changed from OFF to ON
then	
	createTimer(now.plusSeconds((Laufzeit_Sonoff_2_mm.state as DecimalType).intValue), [ |
            Sonoff_4_Energieraum.sendCommand (OFF)])
end

What to do to make it work in OH3.4.3 on PC or openhabianpi?

Nothing. If it works in 3.3 it should work in 3.4. Major breaking changes like that do not occur between point releases, only between major releases.

Thanks rikoshak!
I persume i run in circles the last few days.
I tried again with OH3.4.3 on WIN PC and it works!

rule "Test" 
when
Item Sonoff_1_Schalter changed from OFF to ON
then	
	createTimer(now.plusSeconds((Sonoff_2_mm.state as DecimalType).intValue), [ |
            Sonoff_1_Schalter.sendCommand (OFF)])
end

I have no idea what i made wrong - may it be necessary to restart OH after changing rules?
Dosn´t matter, the rules is runnig.
Many Thanks

Not usually.

This rule you confirmed working is based on different items than the not working rule in your first post.
Would be a good start to check the difference between the items.

Thanks for your reply
Different items came from different version of HO.
Meanwile the items are working in both OH versions.