I need the sunrise- and sunsettime of the astro binding in a number variable with the format “minutes of a day”. For example sunrise is at 7:30 the content of my number variable has to be: 450.
My question is now, is there any possibility to convert, for example the hours an minutes of a DateTime item into Number variables in a rule file?
Pseudo-Code of what i want to do:
var Number hours = MyDateTimeItem.gethours
var Number minutes = MyDateTimeItem.getminutes
Result:
content of MyDateTimeItem: 18:30 Uhr
content of hours: 18
content of minutes: 30
Unfortunately it does not work, i get the following error:
2017-02-09 13:30:37.239 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'testregel': The name '<XFeatureCallImplCustom>.calendar' cannot be resolved to an item or type.
Do i have to include some special file?
I only have included:
var DateTime sonnenaufgang = new DateTime((I_BR_AS_SO_aufgang.state as DateTimeType).calendar.timeInMillis)
var DateTime sonnenuntergang = new DateTime((I_BR_AS_SO_untergang.state as DateTimeType).calendar.timeInMillis)
var Integer sonnenaufgang_min = sonnenaufgang.getMinuteOfDay
var Integer sonnenuntergang_min = sonnenuntergang.getMinuteOfDay
2017-02-09 13:59:44.058 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ‘testregel’
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_101]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_101]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101]
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.GeneratedMethodAccessor873.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101]
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.GeneratedMethodAccessor844.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101]
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]