Hi,
i want to write a rule which sends me a message if batteries of my actors are low.
I have a group item which contains all Battery-Low items.
With blockly i can write a script like this which logs all item:
The logging result locks like this:
2021-12-26 18:09:17.088 [WARN ] [org.openhab.rule.c2c315fef0 ] - LivingRoom1_BatteryLow (Type=SwitchItem, State=OFF, Label=Batterie leer, Category=null, Groups=[gBatteryLow, gLivingRoom])
2021-12-26 18:09:17.101 [WARN ] [org.openhab.rule.c2c315fef0 ] - LivingRoom2_BatteryLow (Type=SwitchItem, State=OFF, Label=Batterie leer, Category=null, Groups=[gBatteryLow, gLivingRoom])
2021-12-26 18:09:17.106 [WARN ] [org.openhab.rule.c2c315fef0 ] - DiningRoom_BatteryLow (Type=SwitchItem, State=OFF, Label=Batterie leer, Category=null, Groups=[gDiningRoom, gBatteryLow])
2021-12-26 18:09:17.109 [WARN ] [org.openhab.rule.c2c315fef0 ] - DiningRoom_BatteryLowWSU (Type=SwitchItem, State=OFF, Label=Batterie leer, Category=null, Groups=[gDiningRoom, gBatteryLow])
2021-12-26 18:09:17.111 [WARN ] [org.openhab.rule.c2c315fef0 ] - Kitchen1_BatteryLow (Type=SwitchItem, State=OFF, Label=Batterie leer, Category=null, Groups=[gBatteryLow, gKitchen])
2021-12-26 18:09:17.113 [WARN ] [org.openhab.rule.c2c315fef0 ] - Kitchen2_BatteryLow (Type=SwitchItem, State=OFF, Label=Batterie leer, Category=null, Groups=[gBatteryLow, gKitchen])
2021-12-26 18:09:17.116 [WARN ] [org.openhab.rule.c2c315fef0 ] - Kitchen_BatteryLowWSU (Type=SwitchItem, State=OFF, Label=Batterie leer, Category=null, Groups=[gKitchen, gBatteryLow])
2021-12-26 18:09:17.118 [WARN ] [org.openhab.rule.c2c315fef0 ] - BathRoom_BatteryLow (Type=SwitchItem, State=OFF, Label=Batterie leer, Category=null, Groups=[gBatteryLow, gBath])
2021-12-26 18:09:17.120 [WARN ] [org.openhab.rule.c2c315fef0 ] - BathRoom_BatteryLowWSU (Type=SwitchItem, State=OFF, Label=Batterie leer , Category=null, Groups=[gBatteryLow, gBath])
2021-12-26 18:09:17.123 [WARN ] [org.openhab.rule.c2c315fef0 ] - BathRoom_BatteryLowPresenceD (Type=SwitchItem, State=OFF, Label=Batterie leer, Category=null, Groups=[gBatteryLow, gBath])
2021-12-26 18:09:17.125 [WARN ] [org.openhab.rule.c2c315fef0 ] - L2_BatteryLow (Type=SwitchItem, State=OFF, Label=Batterie leer, Category=null, Groups=[gL2Room, gBatteryLow])
2021-12-26 18:09:17.128 [WARN ] [org.openhab.rule.c2c315fef0 ] - L2_BatteryLowWSU (Type=SwitchItem, State=OFF, Label=Batterie leer, Category=null, Groups=[gL2Room, gBatteryLow])
2021-12-26 18:09:17.130 [WARN ] [org.openhab.rule.c2c315fef0 ] - L2_BatterySmokeDetector (Type=SwitchItem, State=OFF, Label=Batterie leer, Category=null, Groups=[gL2Room, gBatteryLow])
2021-12-26 18:09:17.132 [WARN ] [org.openhab.rule.c2c315fef0 ] - L1_BatteryLow (Type=SwitchItem, State=OFF, Label=Batterie leer, Category=null, Groups=[gL1Room, gBatteryLow])
2021-12-26 18:09:17.135 [WARN ] [org.openhab.rule.c2c315fef0 ] - L1_BatteryLowWSU (Type=SwitchItem, State=OFF, Label=Batterie leer, Category=null, Groups=[gL1Room, gBatteryLow])
2021-12-26 18:09:17.137 [WARN ] [org.openhab.rule.c2c315fef0 ] - L1_BatterySmokeDetector (Type=SwitchItem, State=OFF, Label=Batterie leer, Category=null, Groups=[gL1sRoom, gBatteryLow])
2021-12-26 18:09:17.140 [WARN ] [org.openhab.rule.c2c315fef0 ] - Bedroom_BatteryLow (Type=SwitchItem, State=OFF, Label=Batterie leer, Category=null, Groups=[gBedRoom, gBatteryLow])
2021-12-26 18:09:17.142 [WARN ] [org.openhab.rule.c2c315fef0 ] - Bedroom_BatteryLowWSU (Type=SwitchItem, State=OFF, Label=Batterie leer, Category=null, Groups=[gBedRoom, gBatteryLow])
Now i want to send a message if the items state is ON. The scripts looks like this:
But this doesnât work:
java.lang.RuntimeException: org.openhab.core.items.ItemNotFoundException: Item 'LivingRoom1_BatteryLow (Type=SwitchItem, State=OFF, Label=Batterie leer, Category=null, Groups=[gBatteryLow, gLivingRoom])' could not be found in the item registry
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:531) ~[jdk.scripting.nashorn:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:456) ~[jdk.scripting.nashorn:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:413) ~[jdk.scripting.nashorn:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:409) ~[jdk.scripting.nashorn:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:162) ~[jdk.scripting.nashorn:?]
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) ~[java.scripting:?]
at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.lambda$0(ScriptActionHandler.java:62) ~[?:?]
at java.util.Optional.ifPresent(Optional.java:183) ~[?:?]
at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.execute(ScriptActionHandler.java:59) ~[?:?]
at org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1180) ~[?:?]
at org.openhab.core.automation.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1032) ~[?:?]
at org.openhab.core.automation.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1048) ~[?:?]
at org.openhab.core.automation.rest.internal.RuleResource.runNow(RuleResource.java:327) ~[?:?]
at jdk.internal.reflect.GeneratedMethodAccessor156.invoke(Unknown Source) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
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:707) ~[bundleFile:3.1.0]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:273) ~[bundleFile:3.4.5]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:799) ~[bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:550) ~[bundleFile:9.4.43.v20210629]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71) ~[bundleFile:?]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) ~[bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:602) ~[bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235) ~[bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1624) ~[bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) ~[bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1434) ~[bundleFile:9.4.43.v20210629]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:294) ~[bundleFile:?]
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) ~[bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:501) ~[bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594) ~[bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) ~[bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1349) ~[bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) ~[bundleFile:9.4.43.v20210629]
at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:82) ~[bundleFile:?]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.server.Server.handle(Server.java:516) ~[bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:388) ~[bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:633) [bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:380) [bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277) [bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) [bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) [bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) [bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:338) [bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:315) [bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:173) [bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131) [bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:386) [bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883) [bundleFile:9.4.43.v20210629]
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034) [bundleFile:9.4.43.v20210629]
at java.lang.Thread.run(Thread.java:829) [?:?]
Caused by: org.openhab.core.items.ItemNotFoundException: Item 'LivingRoom1_BatteryLow (Type=SwitchItem, State=OFF, Label=Batterie leer, Category=null, Groups=[gBatteryLow, gLivingRoom])' could not be found in the item registry
at org.openhab.core.internal.items.ItemRegistryImpl.getItem(ItemRegistryImpl.java:86) ~[?:?]
at jdk.nashorn.internal.scripts.Script$Recompilation$3344$\^eval\_$cu1$restOf.:program(<eval>:13) ~[?:?]
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:655) ~[jdk.scripting.nashorn:?]
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513) ~[jdk.scripting.nashorn:?]
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:527) ~[jdk.scripting.nashorn:?]
... 67 more
Whatâs going on here?