I’m trying to implement a rule in OH1.8 that checks what time it is in relation to the Sunset and Sunrise time but every time it executes I get a null error:
2016-12-12 22:23:10.628 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Matt locale change'
java.lang.NullPointerException: null
at org.eclipse.xtext.common.types.util.JavaReflectAccess.getRawType(JavaReflectAccess.java:107) ~[na:na]
at org.eclipse.xtext.common.types.util.JavaReflectAccess.getConstructor(JavaReflectAccess.java:90) ~[na:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateConstructorCall(XbaseInterpreter.java:511) ~[na:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateVariableDeclaration(XbaseInterpreter.java:601) ~[na:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateBlockExpression(XbaseInterpreter.java:321) ~[na:na]
at sun.reflect.GeneratedMethodAccessor46.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:204) ~[na:na]
at org.openhab.model.script.internal.engine.ScriptImpl.execute(ScriptImpl.java:59) ~[na:na]
at org.openhab.core.scriptengine.ScriptExecutionThread.run(ScriptExecutionThread.java:44) ~[na:na]
This is what I have in my items file:
DateTime Sunrise_Start_Time "Sunrise - Start [%1$tH:%1$tM]" <clock> {astro="planet=sun, type=rise, property=start"}
DateTime Sunrise_End_Time "Sunrise - End [%1$tH:%1$tM]" <clock> {astro="planet=sun, type=rise, property=end"}
DateTime Sunset_Start_Time "Sunset - Start [%1$tH:%1$tM]" <clock> {astro="planet=sun, type=set, property=start"}
DateTime Sunset_End_Time "Sunset - End [%1$tH:%1$tM]" <clock> {astro="planet=sun, type=set, property=end"}
And this is my rule file:
import org.openhab.core.items.*//GroupItem
import java.util.Collections.*
import java.util.Date
import org.openhab.model.script.actions.Timer
rule "Matt locale change"
when
Item MattInLocale changed from OFF to ON
then
val Sunset = new DateTime((Sunset_Start_Time.state as DateTimeType).calendar.timeInMillis)
val Sunrise = new DateTime((Sunrise_End_Time.state as DateTimeType).calendar.timeInMillis)
logDebug("Matt Locale Change","Rule Executed")
if (now.isAfter(Sunset) && now.isBefore(Sunrise)){
logDebug("Matt Locale Change","Time after sunset and before sunrise")
FrontPorchLight.sendCommand(ON)
logDebug("Matt Locale Change","Porch Light Command On Sent")
}
end
Is there something I’m missing? I’m trying to use code examples I found in this forum but I’m not having any luck.