Rule error when thing offline

Hello,

i got the problem, that the switch state of a hue item doesnt change to OFF when the light is turned off by the wall switch.
So i tried to create a rule that posts an update to the item state when the thing gets offline (power off by wall switch).
Actually the rule doenst work and i get the following error at the logs while the switch state doesnt change.

21:18:10.856 [ERROR] [.internal.handler.ScriptActionHandler] - Script execution of rule with UID 'hue-1' failed: An error occurred during the script execution: index=1, size=1 in hue
rule "Licht Badezimmerdecke aus"
when
    Thing "hue:0210:001788289a8e:1" changed to OFFLINE
then
    createTimer(now.plusSeconds(10)) {
        if ("hue:0210:001788289a8e:1" != "ONLINE") {
            Hue_BZ_Deckenleuchte_Farbe.postUpdate(OFF)
        }
    }
end

Anyone an idea how this could be solved?

Thanks in advance,
Alex

rule "Licht Badezimmerdecke aus"
when
    Thing "hue:0210:001788289a8e:1" changed to OFFLINE
then
    createTimer(now.plusSeconds(10)) [ |
        if (ThingAction.getThingStatusInfo("hue:0210:001788289a8e:1").getStatus().toString() != "ONLINE") {
            Hue_BZ_Deckenleuchte_Farbe.postUpdate(OFF)
        }
    ]
end
1 Like

Thank you! I tried it out immediatly but still get the error:

21:32:58.847 [ERROR] [.internal.handler.ScriptActionHandler] - Script execution of rule with UID 'hue-1' failed: An error occurred during the script execution: index=1, size=1 in hue

This is not the correct syntax for createTimer in DSL, you need square braces and a pipe to properly designate the lambda function

   createTimer(now.plusSeconds(10)) [ |
        //do stuff
    ]
1 Like

Yes you are right. I haven’t looked at that part of the code and I used DSL long time ago.

Sorry Kristof, I clicked the wrong “reply”!
Intended for @e36Alex (who will need to use the Thing action as well, just as you suggested.)

1 Like

Thank you!

I edited the rule now to:

rule "Licht Badezimmerdecke aus"
when
    Thing "hue:0210:001788289a8e:1" changed to OFFLINE
then
    createTimer(now.plusSeconds(10)) [ |
        if (ThingAction.getThingStatusInfo("hue:0210:001788289a8e:1").getStatus().toString() != "ONLINE") {
            Hue_BZ_Deckenleuchte_Farbe.postUpdate(OFF)
        }
    ]
end

In VSCode i get the following warning for ThingAction:

Also i get the following warning in the logs and the item state doesnt change:

20:46:08.635 [WARN ] [core.internal.scheduler.SchedulerImpl] - Scheduled job failed and stopped
java.lang.reflect.UndeclaredThrowableException: null
        at com.sun.proxy.$Proxy1280.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:829) [?:?]
Caused by: org.openhab.core.model.script.engine.ScriptExecutionException: The name 'ThingAction' cannot be resolved to an item or type; line 19, column 13, length 11
        at org.openhab.core.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:141) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:992) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:955) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:236) ~[?:?]
        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:858) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:232) ~[?:?]
        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:858) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:232) ~[?:?]
        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:858) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:232) ~[?:?]
        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:991) ~[?:?]
        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) ~[?:?]
        ... 10 more

I don’t think you need the ThingAction part at all, just use getThingStatusInfo

1 Like

Thats it - thank you!

This is the final result now:

rule "Licht Badezimmerdecke aus"
when
    Thing "hue:0210:001788289a8e:1" changed to OFFLINE
then
    createTimer(now.plusSeconds(10)) [ |
        if (getThingStatusInfo("hue:0210:001788289a8e:1").getStatus().toString() != "ONLINE") {
            Hue_BZ_Deckenleuchte_Farbe.postUpdate(OFF)
        }
    ]
end