Sunset rule

Hi All,

I’ve configured this rule, but I’m not sure on its operation with respect to the sunset start channel. Does this appear correct? Essentially, at Sunset the motion sensors in the bedroom are enabled. Then at 10pm they are disabled.

Once I saved it, I got a monster error:

11:03:24.374 [ERROR] [org.quartz.core.JobRunShell          ] - Job DEFAULT.2019-10-04T10:55:24.368+10:00: Proxy for org.eclipse.xtext.xbase.lib.Procedures$Procedure0: [ | {
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@6a6fe08c
} ] threw an unhandled Exception:
java.lang.NullPointerException: null
        at org.eclipse.smarthome.model.script.engine.ScriptError.<init>(ScriptError.java:66) ~[?:?]
        at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:140) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:902) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:865) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:224) ~[?:?]
        at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:204) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:768) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:220) ~[?:?]
        at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:204) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluateArgumentExpressions(XbaseInterpreter.java:1116) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._invokeFeature(XbaseInterpreter.java:1046) ~[?:?]

/* RULE TO DISABLE MOTION SENSORS AT NIGHT & REENABLE at SUNSET*/

rule "Disable the Arming of the motion sensors when its 10pm"
when
        Time cron "0 0 22 ? * * *"
then
        Bed1_Motion_Armed.sendCommand("OFF")
        Bed2_Motion_Armed.sendCommand("OFF")
        Bed3_Motion_Armed.sendCommand("OFF")
        Bed4_Motion_Armed.sendCommand("OFF")
        MasterBedRoom_Motion_Armed.sendCommand("OFF")
       logInfo("Motion","Disabling Sensors")
       sendBroadcastNotification("Its 10pm. Disabling Bedroom motion sensors")
end

rule "Enable motion sensors at Sunset"
when
        Channel "astro:sun:local:set#start" triggered START
then
        Bed1_Motion_Armed.sendCommand("ON")
        Bed2_Motion_Armed.sendCommand("ON")
        Bed3_Motion_Armed.sendCommand("ON")
        Bed4_Motion_Armed.sendCommand("ON")
        MasterBedRoom_Motion_Armed.sendCommand("ON")
        logInfo("Motion","Enabling sensors")
        sendBroadcastNotification("Sun has set. Enabling motion sensors")
end


I don’t see the problem by looking at the code , so I recommend putting dummy logInfos after each line to figure out which line is the problematic one.

1 Like

I think I had the channel wrong, it should be set#event, triggered START

Ill give this a go!

1 Like

Oh, right! try that :smiley:

Quartz errors are usually to do with timing.

If a rules file has spawned some Timer with createTimer, that timer continues to wait for its appointed time even when you edit and reload the rules file.
But the timer’s context has been destroyed. When it executes its code block, it invariably fails with a null error at some point.

It’s likely the reported error has nothing to do with your new rules.

Ill have to wait until sunset again to see if it occurs again . Thanks rossko57, ill refer to this again tomorrow and see what I find.

PS: What is your avatar :slight_smile: Dr Who?

I respond for @rossko57
It’s a dalek from Dr. Who

Why don’t you put these motion detectors in a group and simplify your rule

rule "Disable the Arming of the motion sensors when its 10pm"
when
    Time cron "0 0 22 ? * * *"
then
    BedroomsMotionSensors.sendCommand("OFF")
    logInfo("Motion","Disabling Sensors")
    sendBroadcastNotification("Its 10pm. Disabling Bedroom motion sensors")
end
1 Like

Shorter description of Dalek - lunatic in a tank.

I object to Wikipedia’s use of “cyborg”, they are not dependant on the shell. Wearable tech. More disgustingly, they choose to seal themselves in there for life. No wonder they scream at everyone!

1 Like