Blockly DateTime Blocks

I’m using the blockly “datetime” blocks to compare dateTime items wit “now” running OH4.0.2-1

if i do like this, in my opinion these are the most obvious blocks to do so.
the Item is a datTime item!

i get the following error

2023-08-16 21:32:05.750 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'Vorhaus_Motion' failed: org.graalvm.polyglot.PolyglotException: Error: "Abenddeammerung_Startzeit (Type=DateTimeItem, State=2023-08-16T20:17:00.000+0200, Label=Abenddeammerung Start, Category=, Tags=[Point])" is an unsupported type for conversion to time.ZonedDateTime

So i compared some blocks.
Unbenannt

console.info((time.toZDT(items.getItem('Abenddeammerung_Startzeit'))));

error


2023-08-16 22:05:13.282 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'AA' failed: org.graalvm.polyglot.PolyglotException: Error: "Abenddeammerung_Startzeit (Type=DateTimeItem, State=2023-08-16T20:17:00.000+0200, Label=Abenddeammerung Start, Category=, Tags=[Point])" is an unsupported type for conversion to time.ZonedDateTime

If i fetch the state like this
Unbenannt

console.info((time.toZDT(items.getItem(items.getItem('Abenddeammerung_Startzeit').state))));

i get this error

2023-08-16 21:53:15.898 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'AA' failed: org.openhab.core.items.ItemNotFoundException: Item '2023-08-16T20:17:00.000+0200' could not be found in the item registry

The only blocks working are those
Unbenannt

console.info((time.toZDT(items.getItem('Abenddeammerung_Startzeit').state)));

Shouldn’t this block
Unbenannt
do this job and fetch the state of the item, or do i miss something?

Show the code produced by these blocks. I would have expected that to work.

This might be a known bug in the openhab-js library. It’s failing to convert Items when they are passed to time.toZDT(). It’s know so I would expect a fix before too long if it isn’t already fixed.

That’s not going to work. You don’t have an Item any more, you have the state of an Item which is a String.

Yes, that works around the bug in openhab-js by parsing the date time string instead of trying to convert the DateTime Item.

here is the code

// graalVM
function zdtCompare(zdt1, zdt2, compareOp, precision, compDate) {
  switch (precision) {
    case 'years':
     zdt2 = zdt2.withMonth(zdt1.monthValue());
    case 'months':
     zdt2 = zdt2.withDayOfMonth(zdt1.dayOfMonth());
    case 'days':
     zdt2 = zdt2.withHour(zdt1.hour());
    case 'hours':
     zdt2 = zdt2.withMinute(zdt1.minute());
    case 'minutes':
     zdt2 = zdt2.withSecond(zdt1.second());
    case 'seconds':
     zdt2 = zdt2.withNano(zdt1.nano());
  }
  if (compDate === 'date') {
    zdt1 = zdt1.toLocalDate();
    zdt2 = zdt2.toLocalDate();
  } else if (compDate === 'time') {
    zdt1 = zdt1.toLocalTime();
    zdt2 = zdt2.toLocalTime();
  }
  switch (compareOp) {
    case 'before':
      return zdt1.isBefore(zdt2);
    case 'equal':
      return zdt1.equals(zdt2);
    case 'after':
      return zdt1.isAfter(zdt2);
    case 'beforeEqual':
      return zdt1.isBefore(zdt2) || zdt1.equals(zdt2);
    case 'afterEqual':
      return zdt1.isAfter(zdt2) || zdt1.equals(zdt2);
  }
}


zdtCompare((time.ZonedDateTime.now()), (time.toZDT(items.getItem('Abenddeammerung_Startzeit'))), 'before', 'minutes', 'dateandtime');

There is nothing wrong with that code. It’s the bug. You already figured out the work around.

Thanks a lott Rich

Thanks i have the same issue with OH4.0.2-1.
Will there a github bug report?

I have some more error in my log for that event:

2023-08-17 08:57:22.837 [ERROR] [b.automation.script.javascript.stack] - Failed to execute script:
org.graalvm.polyglot.PolyglotException: Error: "SonnenaufgangStart (Type=DateTimeItem, State=2023-08-17T06:05:00.000+0200, Label=SonnenaufgangStart, Category=sunrise, Tags=[Point, Timestamp], Groups=[Sonnendaten])" is an unsupported type for conversion to time.ZonedDateTime
	at <js>.R(@openhab-globals.js:2) ~[?:?]
	at <js>.:program(<eval>:17) ~[?:?]
	at org.graalvm.polyglot.Context.eval(Context.java:399) ~[?:?]
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:458) ~[?:?]
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:426) ~[?:?]
	at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:262) ~[java.scripting:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocableAndAutocloseable.eval(DelegatingScriptEngineWithInvocableAndAutocloseable.java:53) ~[?:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.eval(InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.java:78) ~[?:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocableAndAutocloseable.eval(DelegatingScriptEngineWithInvocableAndAutocloseable.java:53) ~[?:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.eval(InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.java:78) ~[?:?]
	at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.lambda$0(ScriptActionHandler.java:71) ~[?:?]
	at java.util.Optional.ifPresent(Optional.java:178) ~[?:?]
	at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.execute(ScriptActionHandler.java:68) ~[?:?]
	at org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1188) ~[?:?]
	at org.openhab.core.automation.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1039) ~[?:?]
	at org.openhab.core.automation.internal.RuleEngineImpl.activateRule(RuleEngineImpl.java:858) ~[?:?]
	at org.openhab.core.automation.internal.RuleEngineImpl.setRule(RuleEngineImpl.java:504) ~[?:?]
	at org.openhab.core.automation.internal.RuleEngineImpl.addRule(RuleEngineImpl.java:464) ~[?:?]
	at org.openhab.core.automation.internal.RuleEngineImpl$2.added(RuleEngineImpl.java:274) ~[?:?]
	at org.openhab.core.automation.internal.RuleEngineImpl$2.updated(RuleEngineImpl.java:285) ~[?:?]
	at org.openhab.core.automation.internal.RuleEngineImpl$2.updated(RuleEngineImpl.java:1) ~[?:?]
	at org.openhab.core.common.registry.AbstractRegistry.notifyListeners(AbstractRegistry.java:395) ~[?:?]
	at org.openhab.core.common.registry.AbstractRegistry.notifyListenersAboutUpdatedElement(AbstractRegistry.java:416) ~[?:?]
	at org.openhab.core.automation.internal.RuleRegistryImpl.notifyListenersAboutUpdatedElement(RuleRegistryImpl.java:258) ~[?:?]
	at org.openhab.core.automation.internal.RuleRegistryImpl.notifyListenersAboutUpdatedElement(RuleRegistryImpl.java:1) ~[?:?]
	at org.openhab.core.common.registry.AbstractRegistry.updated(AbstractRegistry.java:322) ~[?:?]
	at org.openhab.core.automation.internal.RuleRegistryImpl.updated(RuleRegistryImpl.java:440) ~[?:?]
	at org.openhab.core.automation.internal.RuleRegistryImpl.updated(RuleRegistryImpl.java:1) ~[?:?]
	at org.openhab.core.common.registry.AbstractRegistry.updated(AbstractRegistry.java:1) ~[?:?]
	at org.openhab.core.common.registry.AbstractProvider.notifyListeners(AbstractProvider.java:66) ~[?:?]
	at org.openhab.core.common.registry.AbstractProvider.notifyListenersAboutUpdatedElement(AbstractProvider.java:91) ~[?:?]
	at org.openhab.core.common.registry.AbstractManagedProvider.update(AbstractManagedProvider.java:118) ~[?:?]
	at org.openhab.core.common.registry.AbstractRegistry.update(AbstractRegistry.java:361) ~[?:?]
	at org.openhab.core.automation.rest.internal.RuleResource.update(RuleResource.java:292) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
	at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:179) ~[bundleFile:3.4.5]
	at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96) ~[bundleFile:3.4.5]
	at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:201) ~[bundleFile:3.4.5]
	at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:104) ~[bundleFile:3.4.5]
	at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59) ~[bundleFile:3.4.5]
	at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96) ~[bundleFile:3.4.5]
	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) ~[bundleFile:3.4.5]
	at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) ~[bundleFile:3.4.5]
	at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:265) ~[bundleFile:3.4.5]
	at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234) ~[bundleFile:3.4.5]
	at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208) ~[bundleFile:3.4.5]
	at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160) ~[bundleFile:3.4.5]
	at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:225) ~[bundleFile:3.4.5]
	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:298) ~[bundleFile:3.4.5]
	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPut(AbstractHTTPServlet.java:234) ~[bundleFile:3.4.5]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:520) ~[bundleFile:4.0.4]
	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:273) ~[bundleFile:3.4.5]
	at org.ops4j.pax.web.service.spi.servlet.OsgiInitializedServlet.service(OsgiInitializedServlet.java:102) ~[bundleFile:?]
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:799) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1656) ~[bundleFile:9.4.50.v20221201]
	at org.ops4j.pax.web.service.spi.servlet.OsgiFilterChain.doFilter(OsgiFilterChain.java:100) ~[bundleFile:?]
	at org.ops4j.pax.web.service.jetty.internal.PaxWebServletHandler.doHandle(PaxWebServletHandler.java:310) ~[bundleFile:?]
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:600) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1624) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1440) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:505) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1355) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:234) ~[bundleFile:9.4.50.v20221201]
	at org.ops4j.pax.web.service.jetty.internal.PrioritizedHandlerCollection.handle(PrioritizedHandlerCollection.java:96) ~[bundleFile:?]
	at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:722) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.server.Server.handle(Server.java:516) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:487) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:732) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:479) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:338) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:315) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:173) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:409) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883) ~[bundleFile:9.4.50.v20221201]
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034) ~[bundleFile:9.4.50.v20221201]
	at java.lang.Thread.run(Thread.java:833) ~[?:?]
2023-08-17 08:57:22.890 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'SystemTimeOfDay' failed: org.graalvm.polyglot.PolyglotException: Error: "SonnenaufgangStart (Type=DateTimeItem, State=2023-08-17T06:05:00.000+0200, Label=SonnenaufgangStart, Category=sunrise, Tags=[Point, Timestamp], Groups=[Sonnendaten])" is an unsupported type for conversion to time.ZonedDateTime
2023-08-17 09:00:00.372 [ERROR] [b.automation.script.javascript.stack] - Failed to execute script:
org.graalvm.polyglot.PolyglotException: Error: "SonnenaufgangStart (Type=DateTimeItem, State=2023-08-17T06:05:00.000+0200, Label=SonnenaufgangStart, Category=sunrise, Tags=[Point, Timestamp], Groups=[Sonnendaten])" is an unsupported type for conversion to time.ZonedDateTime
	at <js>.R(@openhab-globals.js:2) ~[?:?]
	at <js>.:program(<eval>:17) ~[?:?]
	at org.graalvm.polyglot.Context.eval(Context.java:399) ~[?:?]
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:458) ~[?:?]
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:426) ~[?:?]
	at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:262) ~[java.scripting:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocableAndAutocloseable.eval(DelegatingScriptEngineWithInvocableAndAutocloseable.java:53) ~[?:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.eval(InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.java:78) ~[?:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocableAndAutocloseable.eval(DelegatingScriptEngineWithInvocableAndAutocloseable.java:53) ~[?:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.eval(InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.java:78) ~[?:?]
	at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.lambda$0(ScriptActionHandler.java:71) ~[?:?]
	at java.util.Optional.ifPresent(Optional.java:178) ~[?:?]
	at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.execute(ScriptActionHandler.java:68) ~[?:?]
	at org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1188) ~[?:?]
	at org.openhab.core.automation.internal.RuleEngineImpl.runRule(RuleEngineImpl.java:997) ~[?:?]
	at org.openhab.core.automation.internal.TriggerHandlerCallbackImpl$TriggerData.run(TriggerHandlerCallbackImpl.java:87) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[?:?]
	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:1136) ~[?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
	at java.lang.Thread.run(Thread.java:833) ~[?:?]
2023-08-17 09:00:00.387 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'SystemTimeOfDay' failed: org.graalvm.polyglot.PolyglotException: Error: "SonnenaufgangStart (Type=DateTimeItem, State=2023-08-17T06:05:00.000+0200, Label=SonnenaufgangStart, Category=sunrise, Tags=[Point, Timestamp], Groups=[Sonnendaten])" is an unsupported type for conversion to time.ZonedDateTime

BTW the workaround doesn’t work or i do something wrong:

2023-08-17 09:13:26.097 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'SystemTimeOfDay' failed: org.openhab.core.items.ItemNotFoundException: Item '2023-08-17T06:05:00.000+0200' could not be found in the item registry

Wrong block

Thanks! Tomatoes on my eyes! That do the trick.

There already is and it’s being worked.

1 Like

I again cannot find an issue for the topic by searching via Issues · openhab/openhab-webui · GitHub

Do you again mind to point me to that issue, so I can have start working on it?

It’s not a Blockly issue. It’s an openhab-js issue and it was discovered as part of Parsing RFC DateTime string doesn't work with 4.5.1 add-on but works with npm installed library · Issue #288 · openhab/openhab-js · GitHub.

2 Likes

As far as I can see, as you mentioned, it seems not to be a Blockly Problem but I pinged @florian-h05 for a joint investigation of it.

Correct, I and users of my rule templates experience the same problem using just JS Scripting rules without Blockly.

But the issue I linked to is actually to cover a different issue that I still need to gather data about which is definitely not a Blockly problem. I see inconsistent behavior (i.e. the problem occurs sometimes but not other times based on how the openhab-js library is installed and used).

Just for Information OH4.1.0M1 that isn’t solved. Today i get exactly same confuse. After searching I find myself here… So datetime from item doesn’t take any effect and produce an error.
Thanks.

I’m pretty sure this thread dates to after 4.1 M1. Is it a problem in 4.1M2 or the latest snapshots? Keep in mind that if you have openhab-js installed manually you’ll need to update that as well.

Getting the same error with the supposedly working blocks…

org.graalvm.polyglot.PolyglotException: TypeError: Cannot read property "toOpenHabString" from undefined

No, that isn’t the same error at all. Please open a new thread and post your rule.