Time Based State Machine [4.0.0.0;4.9.9.9]

In the future, please post text where ever possible. Screen shots are pretty much useless to me. They can’t be searched, are all but impossible to read on a small screen, cannot be copied from, etc.

Use code fences:

```
code goes here
```
1 Like

I’ve been checking various things and found that I still had a cronjob for rebooting the vm running at 4 in the morning. I since then removed that and now it’s working, maybe the system start level trigger is not working correctly? The other issue was probably that my timezone was set wrong in my time items.

If you have even one Thing that never becomes ONLINE during startup, you will never reach system runlevel 100. You can change the runlevel to 70 or before and see if that’s a problem.

Well that explains everything. I have a couple of Things that are behind switchable wall outlets that most of the time are offline.
i’ve tested everything for a couple of days and so far everything is working perfectly, thank you very much!

Hi Rich,
I’m using the OH 4.0.2 release and trying to get the time machine to work. I have created corresponding items and these also have valid values.
When calling the rule I always get this error:

2023-08-24 09:51:59.518 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'd1bd349ac8' failed: org.graalvm.polyglot.PolyglotException: Error: "2023-08-24T09:52:09.398+02:00[SYSTEM]" is an unsupported type for conversion to time.ZonedDateTime
2023-08-24 09:52:56.313 [DEBUG] [.internal.GraalJSScriptEngineFactory] - bundle org.openhab.automation.jsscripting:4.0.2 (240)[org.openhab.automation.jsscripting.internal.GraalJSScriptEngineFactory(307)] : ConfigurableComponentHolder configuration updated for pid org.openhab.jsscripting with change count 5
2023-08-24 09:52:56.317 [DEBUG] [.internal.GraalJSScriptEngineFactory] - bundle org.openhab.automation.jsscripting:4.0.2 (240)[org.openhab.automation.jsscripting.internal.GraalJSScriptEngineFactory(307)] : Querying state active
2023-08-24 09:52:56.319 [DEBUG] [.internal.GraalJSScriptEngineFactory] - bundle org.openhab.automation.jsscripting:4.0.2 (240)[org.openhab.automation.jsscripting.internal.GraalJSScriptEngineFactory(307)] : Querying state active
2023-08-24 09:52:56.322 [DEBUG] [.internal.GraalJSScriptEngineFactory] - bundle org.openhab.automation.jsscripting:4.0.2 (240)[org.openhab.automation.jsscripting.internal.GraalJSScriptEngineFactory(307)] : invoking modified: modified: parameters [org.apache.felix.scr.impl.helper.ReadOnlyDictionary]
2023-08-24 09:52:56.324 [DEBUG] [.internal.GraalJSScriptEngineFactory] - bundle org.openhab.automation.jsscripting:4.0.2 (240)[org.openhab.automation.jsscripting.internal.GraalJSScriptEngineFactory(307)] : invoked modified: modified
2023-08-24 09:52:56.326 [DEBUG] [.internal.GraalJSScriptEngineFactory] - bundle org.openhab.automation.jsscripting:4.0.2 (240)[org.openhab.automation.jsscripting.internal.GraalJSScriptEngineFactory(307)] : No change in target property for dependency $000: currently registered: true
2023-08-24 09:52:56.329 [DEBUG] [.internal.GraalJSScriptEngineFactory] - bundle org.openhab.automation.jsscripting:4.0.2 (240)[org.openhab.automation.jsscripting.internal.GraalJSScriptEngineFactory(307)] : No change in target property for dependency $001: currently registered: true
2023-08-24 09:52:56.331 [DEBUG] [.internal.GraalJSScriptEngineFactory] - bundle org.openhab.automation.jsscripting:4.0.2 (240)[org.openhab.automation.jsscripting.internal.GraalJSScriptEngineFactory(307)] : No change in target property for dependency osgi.ds.satisfying.condition: currently registered: true
2023-08-24 09:52:56.333 [DEBUG] [.internal.GraalJSScriptEngineFactory] - bundle org.openhab.automation.jsscripting:4.0.2 (240)[org.openhab.automation.jsscripting.internal.GraalJSScriptEngineFactory(307)] : Querying state active
2023-08-24 09:52:56.340 [DEBUG] [.internal.GraalJSScriptEngineFactory] - bundle org.openhab.automation.jsscripting:4.0.2 (240)[org.openhab.automation.jsscripting.internal.GraalJSScriptEngineFactory(307)] : ImmediateComponentHolder Finished configuring the dependency managers for component for pid org.openhab.jsscripting 
2023-08-24 09:52:56.343 [DEBUG] [.internal.GraalJSScriptEngineFactory] - bundle org.openhab.automation.jsscripting:4.0.2 (240)[org.openhab.automation.jsscripting.internal.GraalJSScriptEngineFactory(307)] : ImmediateComponentHolder Will not enable component for pid org.openhab.jsscripting: holder enabled state: true, metadata enabled: true 
2023-08-24 09:53:16.099 [ERROR] [b.automation.script.javascript.stack] - Failed to execute script:
org.graalvm.polyglot.PolyglotException: Error: "2023-08-24T09:53:26.061+02:00[SYSTEM]" is an unsupported type for conversion to time.ZonedDateTime
	at <js>.toZDT(/etc/openhab/automation/js/node_modules/openhab/time.js:266) ~[?:?]
	at <js>.check(/etc/openhab/automation/js/node_modules/openhab_rules_tools/timerMgr.js:46) ~[?:?]
	at <js>.:program(<eval>:258) ~[?:?]
	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.rest.internal.RuleResource.runNow(RuleResource.java:381) ~[?:?]
	at org.openhab.core.automation.rest.internal.RuleResource.runNow(RuleResource.java:398) ~[?:?]
	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.doPost(AbstractHTTPServlet.java:217) ~[bundleFile:3.4.5]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:517) ~[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-24 09:53:16.127 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'd1bd349ac8' failed: org.graalvm.polyglot.PolyglotException: Error: "2023-08-24T09:53:26.061+02:00[SYSTEM]" is an unsupported type for conversion to time.ZonedDateTime

I have another question, how do I have to create items that should be used on Fridays and Sundays? For example Friday_night 23:30 and Sunday_night 22:50 ?

Thanks
Heiko

There is a bug in the openhab-js library.

You can do one of the following:

  • install the latest openhab-js library using npm and configure the add-on to not use the built in library; even though it’s the same library for some reason this fixes the problem

  • change the following line

              var mapped = startTimes.map(i => { return { 'state': i.getMetadata()[NAMESPACE].value,
                                                          'time' : time.toZDT(i).toToday() } });

to

               var mapped = startTimes.map(i => { return { 'state': i.getMetadata()[NAMESPACE].value,
                                                          'time' : time.toZDT(i.toString()).toToday() } });

I’ve been hesitant to change this in the original template because it’s a temporary problem that will be fixed soon. I might just have to do it anyway.

Hi Rich,
this doesn´t fix the error for me.
openHAB 4.0.1 - Release Build with latest openHABian updates

I changed the two lines to:

              var mapped = startTimes.map(i => { return { 'state': i.getMetadata()[NAMESPACE].value,
                                                          'time' : time.toZDT(i.toString()).toToday() } });

but the error remains the same:

2023-08-24 16:44:52.645 [DEBUG] [omation.rules_tools.TimeStateMachine] - Starting state machine in ten seconds...
2023-08-24 16:44:52.670 [ERROR] [b.automation.script.javascript.stack] - Failed to execute script:
org.graalvm.polyglot.PolyglotException: Error: "2023-08-24T16:45:02.650+02:00[SYSTEM]" is an unsupported type for conversion to time.ZonedDateTime
	at <js>.toZDT(/node_modules/openhab.js:2) ~[?:?]
	at <js>.check(/etc/openhab/automation/js/node_modules/openhab_rules_tools/timerMgr.js:46) ~[?:?]
	at <js>.:program(<eval>:258) ~[?:?]
	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.rest.internal.RuleResource.runNow(RuleResource.java:381) ~[?:?]
	at org.openhab.core.automation.rest.internal.RuleResource.runNow(RuleResource.java:398) ~[?:?]
	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.doPost(AbstractHTTPServlet.java:217) ~[bundleFile:3.4.5]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:517) ~[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-24 16:44:52.694 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'TimeBasedStateMachine' failed: org.graalvm.polyglot.PolyglotException: Error: "2023-08-24T16:45:02.650+02:00[SYSTEM]" is an unsupported type for conversion to time.ZonedDateTime

That’s right, you need to change this line too.

timers.check(tod.state, tod.time, stateTransitionGenerator(tod.state));

to

timers.check(tod.state, tod.time.toString(), stateTransitionGenerator(tod.state));
1 Like

Ok that´s brings me to the next error :slight_smile:

2023-08-24 17:07:26.044 [WARN ] [ore.internal.scheduler.SchedulerImpl] - Scheduled job 'ui.TimeBasedStateMachine.debounce' failed and stopped
org.graalvm.polyglot.PolyglotException: Error: Failed to parse string Default_Morning (Type=DateTimeItem, State=2023-08-04T06:00:00.000+0200, Label=null, Category=null, Groups=[TimesOfDay]): DateTimeParseException: Text cannot be parsed to a Duration: Default_Morning (Type=DateTimeItem, State=2023-08-04T06:00:00.000+0200, Label=null, Category=null, Groups=[TimesOfDay]), at index: 0
	at <js>._parseString(/etc/openhab/automation/js/node_modules/openhab/time.js:149) ~[?:?]
	at <js>.toZDT(/etc/openhab/automation/js/node_modules/openhab/time.js:211) ~[?:?]
	at <js>.:=>(<eval>:217) ~[?:?]
	at <js>.createTimersGenerator(<eval>:216) ~[?:?]
	at <js>.:=>(/etc/openhab/automation/js/node_modules/openhab_rules_tools/timerMgr.js:66) ~[?:?]
	at com.oracle.truffle.polyglot.PolyglotFunctionProxyHandler.invoke(PolyglotFunctionProxyHandler.java:154) ~[?:?]
	at jdk.proxy1.$Proxy1204.run(Unknown Source) ~[?:?]
	at org.openhab.automation.jsscripting.internal.threading.ThreadsafeTimers.lambda$0(ThreadsafeTimers.java:85) ~[?:?]
	at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$12(SchedulerImpl.java:189) ~[?:?]
	at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$1(SchedulerImpl.java:88) ~[?:?]
	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) ~[?:?]

The items are coming from one of your earlier versions of this rule.

// Default day, initialization for JavaScript should be done thgrough MainUI. 
DateTime Default_Morning (TimesOfDay) { etod="MORNING"[type="default"] }
DateTime Default_Day (TimesOfDay) { etod="DAY"[type="default"] }
DateTime Default_Evening (TimesOfDay) { etod="EVENING"[type="default"] }
DateTime Default_Night (TimesOfDay) { etod="NIGHT"[type="default"] }
DateTime Default_Bed (TimesOfDay) { etod="BED"[type="default"] }

I need more coffee.

tod.time is an Item of course. We need the state, not the toString.

timers.check(tod.state, tod.time.state, stateTransitionGenerator(tod.state));

The state is already a String.

Wait, now I’m not sure what is going on. tod.time should be a ZonedDateTime but the toString is showing it to be a DateTime Item. Let me know if that works. If not I may have to dig deeper to figure out a work around and it might be better if you install the library and change the settings for now.

I´ve gone this way and now it works.

I gave up and updated the rule template. Thanks for helping me find a fix that works. You can install the 0.4 version of the template which should work now in all ways that openhab-js is installed.

1 Like

The error messages are gone now. However, I get a warning that the dayset weekend is not configured. But I have created corresponding items.

2023-08-25 07:35:43.873 [INFO ] [omation.rules_tools.TimeStateMachine] - All tsm Items are configured correctly
2023-08-25 07:35:45.513 [WARN ] [emeris.internal.EphemerisManagerImpl] - This dayset is not configured : weekend
2023-08-25 07:35:45.515 [WARN ] [emeris.internal.EphemerisManagerImpl] - This dayset is not configured : weekend
2023-08-25 07:35:46.135 [INFO ] [omation.rules_tools.TimeStateMachine] - Today is a weekday day.
2023-08-25 07:35:46.729 [INFO ] [omation.rules_tools.TimeStateMachine] - The current state is DAY

The time of day is now correctly determined.

One more question, you may have overlooked it above. How can I generate items that are only valid for Friday or Sunday. For example Friday_night and Sunday_night. These should switch at times other than weekdays and weekends.

I’ll have to experiment to see why you get that message. Run with debug logging and post the logs.

That’s what custom daysets are for. Configure a dayset in Ephemeris (see the Ephemeris docs under Actions) and use the “dayset” type in the Item metadata.

Hi,
in my system there is no %ConfDir/services/emphemeris.cfg. When I there add a file with the entries I get warnings on startup. If I edit the runtime.cfg with the entries for weekday, weekend, Friday and Sunday, the system starts without error messages and the script template does not issue any error messages about the missing weekend. I am now testing further with Friday and Sunday.

Is there a way if tomorrow is a holiday that a different night time could be used?
So I would like to use the night time from the weekend if tomorrow is a weekend or a holiday. If tomorrow is a working day, use the night time of the weekday. Is that possible?

Need I for each “dayset” the complete count of items (morning, day, evening, night)? Or is only one item per different time enough?

Not super easily right now. But I might look into adding an offset property to the Items and see if that doesn’t make things too complicated.

In the mean time, you can create a custom holidays xml file with the holiday eves defined and use the custom type and file property.

Hi,
I can’t get my dayset-sunday to work. As soon as I add an item like this:

DateTime  TZ_Sonntag_Nacht  "Sonntag Nacht"  <time>  (Tageszeiten) { tsm="NIGHT"[type="dayset",set="sunday"] }

i get this error message

2023-08-27 14:54:10.383 [WARN ] [ore.internal.scheduler.SchedulerImpl] - Scheduled job 'ui.f815d6d2e6.debounce' failed and stopped
org.graalvm.polyglot.PolyglotException: TypeError: (intermediate value).getMetadata is not a function
	at <js>.:=>(<eval>:160) ~[?:?]
	at <js>.getTodayItems(<eval>:160) ~[?:?]
	at <js>.createTimersGenerator(<eval>:210) ~[?:?]
	at <js>.:=>(/etc/openhab/automation/js/node_modules/openhab_rules_tools/timerMgr.js:66) ~[?:?]
	at com.oracle.truffle.polyglot.PolyglotFunctionProxyHandler.invoke(PolyglotFunctionProxyHandler.java:154) ~[?:?]
	at jdk.proxy1.$Proxy443.run(Unknown Source) ~[?:?]
	at org.openhab.automation.jsscripting.internal.threading.ThreadsafeTimers.lambda$0(ThreadsafeTimers.java:85) ~[?:?]
	at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$12(SchedulerImpl.java:189) ~[?:?]
	at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$1(SchedulerImpl.java:88) ~[?:?]
	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) ~[?:?]

What’s wrong?

Thanks

You are running OH 4 with the latest openhab helper library? You don’t happen to have the library installed via npm and it’s an older version of the library?

A few months ago, maybe longer, the way the helper library accesses metadata changed.

You have created a custom dayset named “sunday” in the Ephemeris config?

Generate debug level logs and post them here.

Hello,
somehow the worm is in here.

RPi3 completely rebuilt with the latest openHABian image.
According to the documentation, I have set and installed everything correctly…

2023-08-29 18:38:44.145 [DEBUG] [omation.rules_tools.TimeStateMachine] - Starting state machine in ten seconds...
2023-08-29 18:38:44.174 [DEBUG] [omation.rules_tools.TimeStateMachine] - Flapping detected, waiting before creating timers for today
2023-08-29 18:38:54.154 [DEBUG] [omation.rules_tools.TimeStateMachine] - Validating Item types, Item metadata, and Group membership
2023-08-29 18:38:54.182 [DEBUG] [omation.rules_tools.TimeStateMachine] - TZ_Wochenende_Tag is valid
2023-08-29 18:38:54.193 [DEBUG] [omation.rules_tools.TimeStateMachine] - TZ_Woche_Nacht is valid
2023-08-29 18:38:54.203 [DEBUG] [omation.rules_tools.TimeStateMachine] - TZ_Wochenende_Vorabend is valid
2023-08-29 18:38:54.212 [DEBUG] [omation.rules_tools.TimeStateMachine] - TZ_Default_Tag is valid
2023-08-29 18:38:54.223 [DEBUG] [omation.rules_tools.TimeStateMachine] - TZ_Wochenende_Nacht is valid
2023-08-29 18:38:54.235 [DEBUG] [omation.rules_tools.TimeStateMachine] - TZ_Wochenende_Morgen is valid
2023-08-29 18:38:54.245 [DEBUG] [omation.rules_tools.TimeStateMachine] - TZ_Default_Morgen is valid
2023-08-29 18:38:54.252 [DEBUG] [omation.rules_tools.TimeStateMachine] - TZ_Woche_Vorabend is valid
2023-08-29 18:38:54.258 [DEBUG] [omation.rules_tools.TimeStateMachine] - TZ_Woche_Abend is valid
2023-08-29 18:38:54.265 [DEBUG] [omation.rules_tools.TimeStateMachine] - TZ_Wochenende_Abend is valid
2023-08-29 18:38:54.271 [DEBUG] [omation.rules_tools.TimeStateMachine] - TZ_Default_Nacht is valid
2023-08-29 18:38:54.277 [DEBUG] [omation.rules_tools.TimeStateMachine] - TZ_Default_Abend is valid
2023-08-29 18:38:54.283 [DEBUG] [omation.rules_tools.TimeStateMachine] - TZ_Default_Vorabend is valid
2023-08-29 18:38:54.289 [DEBUG] [omation.rules_tools.TimeStateMachine] - TZ_Woche_Tag is valid
2023-08-29 18:38:54.295 [DEBUG] [omation.rules_tools.TimeStateMachine] - TZ_Woche_Morgen is valid
2023-08-29 18:38:54.314 [INFO ] [omation.rules_tools.TimeStateMachine] - All tsm Items are configured correctly
2023-08-29 18:38:54.322 [WARN ] [ore.internal.scheduler.SchedulerImpl] - Scheduled job 'ui.e2ea68fe61.debounce' failed and stopped
org.graalvm.polyglot.PolyglotException: TypeError: Cannot read property "configuration" from undefined
	at <js>.:=>(<eval>:84) ~[?:?]
	at <js>.getItemsOfType(<eval>:84) ~[?:?]
	at <js>.validateAllConfigs(<eval>:121) ~[?:?]
	at <js>.createTimersGenerator(<eval>:202) ~[?:?]
	at <js>.:=>(/etc/openhab/automation/js/node_modules/openhab_rules_tools/timerMgr.js:66) ~[?:?]
	at com.oracle.truffle.polyglot.PolyglotFunctionProxyHandler.invoke(PolyglotFunctionProxyHandler.java:154) ~[?:?]
	at jdk.proxy1.$Proxy224.run(Unknown Source) ~[?:?]
	at org.openhab.automation.jsscripting.internal.threading.ThreadsafeTimers.lambda$0(ThreadsafeTimers.java:85) ~[?:?]
	at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$12(SchedulerImpl.java:189) ~[?:?]
	at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$1(SchedulerImpl.java:88) ~[?:?]
	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) ~[?:?]

my Items:

Group	Tageszeiten	"Tageszeiten"	<time>
String	Tageszeit	"Tageszeit"	<time>	(Tageszeiten)

DateTime  TZ_Woche_Morgen "Woche Morgen" <time>  (Tageszeiten) { tsm="MORNING" [type="weekday"] }
DateTime  TZ_Woche_Tag "Woche Tag"  <time>  (Tageszeiten) { channel="astro:sun:local:rise#start", tsm="DAY"[type="weekday"] }
DateTime  TZ_Woche_Vorabend "Woche Vorabend"  <time>  (Tageszeiten) { channel="astro:sun:local:civilDusk#start", tsm="TWILIGHT"[type="weekday"] }
DateTime  TZ_Woche_Abend "Woche Abend"  <time>  (Tageszeiten) { channel="astro:sun:local:set#start", tsm="EVENING"[type="weekday"] }
DateTime  TZ_Woche_Nacht  "Woche Nacht"  <time>  (Tageszeiten) { tsm="NIGHT"[type="weekday"] }

DateTime  TZ_Wochenende_Morgen "Wochenende Morgen"  <time>  (Tageszeiten) { tsm="MORNING" [type="weekend"] }
DateTime  TZ_Wochenende_Tag "Wochenende Tag"  <time>  (Tageszeiten) { channel="astro:sun:local:rise#start", tsm="DAY"[type="weekend"] }
DateTime  TZ_Wochenende_Vorabend "Wochenende Vorabend"  <time>  (Tageszeiten) { channel="astro:sun:local:civilDusk#start", tsm="TWILIGHT"[type="weekend"] }
DateTime  TZ_Wochenende_Abend "Wochenende Abend"  <time>  (Tageszeiten) { channel="astro:sun:local:set#start", tsm="EVENING"[type="weekend"] }
DateTime  TZ_Wochenende_Nacht  "Wochenende Nacht"  <time>  (Tageszeiten) { tsm="NIGHT"[type="weekend"] }

DateTime  TZ_Default_Morgen "Default Tag"  <time>  (Tageszeiten) { tsm="MORNING"[type="default"] }
DateTime  TZ_Default_Tag "Default Tag"  <time>  (Tageszeiten) { channel="astro:sun:local:rise#start", tsm="DAY"[type="default"] }
DateTime  TZ_Default_Vorabend "Default Vorabend"  <time>  (Tageszeiten) { channel="astro:sun:local:civilDusk#start", tsm="TWILIGHT"[type="default"] }
DateTime  TZ_Default_Abend "Default Abend"  <time>  (Tageszeiten) { channel="astro:sun:local:set#start", tsm="EVENING"[type="default"] }
DateTime  TZ_Default_Nacht "Default Nacht"  <time>  (Tageszeiten) { tsm="NIGHT"[type="default"] }

I installed the openhab_rules_tools via openhabian-config. JS scripting was already part of the OH installation. What is still missing?

Thanks

I don’t understand how it’s able to access and check the metadata and then fail to access the data later. If there was a problem with the metadata I would have expected it to show up during the configuration check.

Click on the code tab of the instantiated rule and paste in the “configuration” section at the top so I can see how it’s been configured.

I can’t figure out how this error is happening. It makes no sense. Prior to when the error occurs we’ve already verified that all the Items have metadata and they all have a configuration, and that configuration has a type field (that’s what the “Itemname is valid” entries mean). But after we’ve confirmed that, when we attempt to check the metadata again we get an error.

Also, open the script action. What is the version number at the very top of the action in the comment?

Also, for grins, post lines 82-85 of the script action as well (that’s where the error is happening).