OH 2 rules don't work in OH 3

Hi there!
I’m trying to implement a scheduler on a OH 3 instance, my rule is working fine on OH2 but in OH 3 I got this error message when the timer should execute.

“17:55:18.428 [WARN ] [core.internal.scheduler.SchedulerImpl] - Scheduled job failed and stopped
java.lang.IllegalStateException: Could not invoke method: org.openhab.core.model.script.lib.NumberExtensions.operator_equals(java.lang.Number,java.lang.Number) on instance: null
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1193) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1151) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._invokeFeature(XbaseInterpreter.java:1137) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeFeature(XbaseInterpreter.java:1082) ~[?:?]
at org.openhab.core.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:151) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:992) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:238) ~[?:?]
at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:216) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:962) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:238) ~[?:?]
at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:216) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:962) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:238) ~[?:?]
at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:216) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:962) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:238) ~[?:?]
at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:216) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:962) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:238) ~[?:?]
at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:216) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:962) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:238) ~[?:?]
at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:216) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:962) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:238) ~[?:?]
at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:216) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:962) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:238) ~[?:?]
at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:216) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:470) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:256) ~[?:?]
at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:216) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:459) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:240) ~[?:?]
at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:216) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:202) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.ClosureInvocationHandler.doInvoke(ClosureInvocationHandler.java:47) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.AbstractClosureInvocationHandler.invoke(AbstractClosureInvocationHandler.java:30) ~[?:?]
at com.sun.proxy.$Proxy171.apply(Unknown Source) ~[?:?]
at org.openhab.core.model.script.actions.ScriptExecution.lambda$0(ScriptExecution.java:82) ~[?:?]
at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$12(SchedulerImpl.java:166) ~[bundleFile:?]
at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$1(SchedulerImpl.java:76) [bundleFile:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:834) [?:?]
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1176) ~[?:?]
… 57 more”

I have no clue what’s the problem. Can someone point me in the right direction? Thanks!

I’m using this example:
AlarmClock · openhab/openhab1-addons Wiki · GitHub

The time of day libraries changed in OH3 as mentioned in the Release Notes. There are also many threads here on the forum available by searching.

Yes, I’m already changed the now.getMinuteOfDay… But then I think, I still should check the entire script for changed expressions. That is fantastic, if I only know why they changed and scraped the entire legacy support… I’m really not happy with it… But thanks anyway!

They changed because of the newer LTS version of Java, (Java 11) I believe.

Some breakage is expected with major version changes. That is called progress.

The 3rd party library Joda has been basically end of life for a very long time. It has been needing to be replaced for a very long time. The replacement which are the time classes built into the Java language itself are not wholly compatible with Joda so changes are required.

There was actually an attempt to replace Joda about three or four years ago in OH 2.3 (if I recall correctly). But it was a breaking change so we’ve kept this no longer supported and technically redundant library in OH all this time, waiting for OH 3.

Any time OH moves from one major version to another it is because there are breaking changes. So as was the case in OH 1 to OH 2, and OH 2 to OH 3, any future change in the major version number will have breaking changes and you will have to make changes to your configs to upgrade to it.

And in fact, the number of breaking changes between OH 2 and OH 3 are really minor compared to the changes between OH 1 and OH 2. There are only three breaking changes I’m aware of in rules that you have to worry about, and one of them is just a change of behavior (and all of these were listed in the release notes):

  • Joda DateTime has been replaced with ZonedDateTime
  • The arguments to executeCommandLine have changed.
  • You can no longer have more than one copy of a given rule running at the same time. Subsequent triggers to that rule will be queued up and executed in turn.
1 Like

Sadly I’m not coding in java, so I have no idea what’s wrong with my code. I already tried to make some changes to match the new requirements.
Could you perhaps point out, what’s wrong with my code?

var Timer timer1 = null
var java.util.concurrent.locks.ReentrantLock lock1 = new java.util.concurrent.locks.ReentrantLock()

rule “Initialization”
when
System started
then
postUpdate(nappaliKlimeTimerZeitStunde, 8)
postUpdate(nappaliKlimeTimerZeitMinute, 15)
postUpdate(nappaliKlimeTimerMontag, OFF)
postUpdate(nappaliKlimeTimerDienstag, OFF)
postUpdate(nappaliKlimeTimerMittwoch, OFF)
postUpdate(nappaliKlimeTimerDonnerstag, OFF)
postUpdate(nappaliKlimeTimerFreitag, OFF)
postUpdate(nappaliKlimeTimerSamstag, OFF)
postUpdate(nappaliKlimeTimerSonntag, OFF)
end

rule “Weckzeit”
when
Item nappaliKlimeTimerZeitStunde changed or
Item nappaliKlimeTimerZeitMinute changed
then
// If the UI to change the Alarm time is clicked several times the code below
// is subject to race conditions. Therefore we make sure that all events
// are processed one after the other.
lock1.lock()
try {
var String msg = “”

// Copy the Alarm-Time from the UI to local variables
var stunde = nappaliKlimeTimerZeitStunde.state as DecimalType
var minute = nappaliKlimeTimerZeitMinute.state as DecimalType

// Combine the hour and minutes to one string to be displayed in the 
// user interface
if (stunde < 10) { msg = "0" } 
msg = msg + nappaliKlimeTimerZeitStunde.state.format("%d") + ":"

if (minute < 10) { msg = msg + "0" }
msg = msg + nappaliKlimeTimerZeitMinute.state.format("%d")
postUpdate(nappaliKlimeTimerZeitMessage,msg)

// calculate the alarm time [min]
var int weckzeit1
weckzeit1 = (nappaliKlimeTimerZeitStunde.state as DecimalType).intValue * 60 + 
            (nappaliKlimeTimerZeitMinute.state as DecimalType).intValue
weckzeit1 = weckzeit1.intValue

// calculate current time [min]
var int jetzt1
jetzt1 = now.getHour() * 60 + now.getMinute()
jetzt1 = jetzt1.intValue

// calculate the difference between the requested alarm time and 
// current time (again in minutes)  
var int delta1
delta1 = (weckzeit1 - jetzt1)
delta1 = delta1.intValue

// add one day (1440 minutes) if alarm time for today already passed
if (jetzt1 > weckzeit1) { delta1 = delta1 + 1440 }

// check if there is already an alarm timer; cancel it if present
if (timer1 != null) {
   timer1.cancel
   timer1 = null
}

// create a new timer using the calculated delta [min]
timer1 = createTimer(now.plusMinutes(delta1)) [|
    // This code will be executed if the timer triggers
    // ************************************************
    // check if alarm clock is armed for this weekday
    var Number day = now.getDayOfWeek
    if (((day == 1) && (nappaliKlimeTimerMontag.state == ON))     ||
        ((day == 2) && (nappaliKlimeTimerDienstag.state == ON))   ||
        ((day == 3) && (nappaliKlimeTimerMittwoch.state == ON))   ||
        ((day == 4) && (nappaliKlimeTimerDonnerstag.state == ON)) ||
        ((day == 5) && (nappaliKlimeTimerFreitag.state == ON))    ||
        ((day == 6) && (nappaliKlimeTimerSamstag.state == ON))    ||
        ((day == 7) && (nappaliKlimeTimerSonntag.state == ON))) {
            // The things to do if the alarm clock is enabled for this day of week: 
            // ...
            // ...

            ///////klimea sajat kod

             nappaliKlima1e34846b_UnitMode.sendCommand("heat")
             nappaliKlima1e34846b_TargetTemperature.sendCommand("23")



       }
       // Re-Arm the timer to trigger again tomorrow (same time) 
       timer1.reschedule(now.plusHours(24))
    // ************************************************
    // Here the code ends that executes once the timer triggers 
    ]

} finally {
// release the lock - we are ready to process the next event
lock1.unlock()
}
end

Give us a clue. What does “wrong” mean - what does it do or not that you were not expecting?

3 Likes

This may help the OP.

How to ask a good question / Help Us Help You - Tutorials & Examples - openHAB Community

In addition to what rossko57 asks, add some logging to the rules until you determine exactly which line of code is failing. We are not computers. Scanning through 100+ lines of code that are not in code fences looking for an unnamed problem is just not something reasonable to ask a human to do.

1 Like

The log is ther in the first post I made, but perhaps some clarification would help, sorry!
So I have a couple of items, for setting a timer and on which day it should execute. I hard coded the whit it should happen, when the timer fires.

// create a new timer using the calculated delta [min]
timer1 = createTimer(now.plusMinutes(delta1)) [|
    // This code will be executed if the timer triggers
    // ************************************************
    // check if alarm clock is armed for this weekday
    var Number day = now.getDayOfWeek
    if (((day == 1) && (nappaliKlimeTimerMontag.state == ON))     ||
        ((day == 2) && (nappaliKlimeTimerDienstag.state == ON))   ||
        ((day == 3) && (nappaliKlimeTimerMittwoch.state == ON))   ||
        ((day == 4) && (nappaliKlimeTimerDonnerstag.state == ON)) ||
        ((day == 5) && (nappaliKlimeTimerFreitag.state == ON))    ||
        ((day == 6) && (nappaliKlimeTimerSamstag.state == ON))    ||
        ((day == 7) && (nappaliKlimeTimerSonntag.state == ON))) {
            // The things to do if the alarm clock is enabled for this day of week: 
            // ...
            // ...

            ///////klimea sajat kod

             nappaliKlima1e34846b_UnitMode.sendCommand("heat")
             nappaliKlima1e34846b_TargetTemperature.sendCommand("23")



       }
       // Re-Arm the timer to trigger again tomorrow (same time) 
       timer1.reschedule(now.plusHours(24))
    // ************************************************
    // Here the code ends that executes once the timer triggers 

I can set the timer, and it will be set, but when the it should execute, the commands and rescheduel it errors out. As shown in the first post. Sadly it doesn’t give me too much information, about what I’m doing wrong.
Perhaps if you guys could me point me, where can I check the new expressions!
Thanks!

Alright, it’s to do with timer execution.

and something to with numeric equality test

so it seems to be choking on that.

Where does that day variable come from?

Aha, and we know that datetime stuff has changed in OH3/Java11 environment, everyone keeps telling us.

A quick forum search on “OH3 getDayOfWeek” leads to -

It seems getDayOfWeek still exists, but does not return a number unless you ask for it. You’re probably getting THURSDAY now by default.

3 Likes

Thank you so much for that!
Is there a page somewhere, where I could learn the expressions, a comperative chart or something? Because I couldn’t even diagnose where it stucked. Thanks again!

Not really. getDayOfWeek is a Java11 function,lots on the interwebs about that.