I’ve created simple rules using “SimpleRule()” and added it to the Registry using “UID=automationManager.addRule(sRule)” from within a Javascript rule, this works well and does what I want. However, I also need to delete rules I have created. Quite reasonably they cannot be deleted via the UI, not that I want to anyway. Unfortunately, however “rules.remove(UID)” does not work either as it fails with a Class exception:
2021-01-28 13:13:37.129 [WARN ] [e.automation.internal.RuleEngineImpl] - Fail to execute action: script
java.lang.ClassCastException: class org.openhab.core.automation.internal.RuleImpl cannot be cast to class java.lang.String (org.openhab.core.automation.internal.RuleImpl is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @187e57b; java.lang.String is in module java.base of loader 'bootstrap')
at org.openhab.core.automation.ManagedRuleProvider.keyToString(ManagedRuleProvider.java:1) ~[?:?]
at org.openhab.core.common.registry.AbstractManagedProvider.remove(AbstractManagedProvider.java:90) ~[?:?]
I’ve also noticed that the UID returned by “automationManager.addRule()” is different to the UID shown in the User Interface. E.g. The returned UID is
“org.openhab.core.automation.internal.RuleImpl@55d5266a”
whereas the Unique ID shown in the UI is the two don’t seem to be related.
The actual code I am using is:
var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
var FrameworkUtil = Java.type("org.osgi.framework.FrameworkUtil");
var _bundle = FrameworkUtil.getBundle(scriptExtension.class);
var bundle_context = _bundle.getBundleContext()
var MetadataRegistry_Ref = bundle_context.getServiceReference("org.openhab.core.items.MetadataRegistry");
var MetadataRegistry = bundle_context.getService(MetadataRegistry_Ref);
var Metadata = Java.type("org.openhab.core.items.Metadata");
var MetadataKey = Java.type("org.openhab.core.items.MetadataKey");
var RuleRegistry = Java.type("org.openhab.core.automation.Rule");
var ruleEngine = Java.type("org.openhab.core.automation.RuleManager");
scriptExtension.importPreset("RuleSupport");
scriptExtension.importPreset("RuleSimple");
var ArrayOfKeys = {};
var ListOfRules;
var ReturnValue;
var TimesCalled = 1;
var UID;
//----------------------------------------------------------------------------------------------------------------
outputCurrentRules = function()
{
var i =0;
logger.info("\n\n\n Rules found on Call: " +TimesCalled);
var ReturnValue=rules.getAll().stream().forEach(function(keys)
{
ArrayOfKeys[i] = (keys);
logger.info("Key Value [" +i +"] is: " +ArrayOfKeys[i] +" and Type is: " +typeof ArrayOfKeys[i]);
i++;
});
logger.info("\n\nReturn value of rules.getAll() on call[" +TimesCalled +"] is: " +ReturnValue );
TimesCalled = TimesCalled + 1;
}
//----------------------------------------------------------------------------------------------------------------
var sRule = new SimpleRule() {
execute: function( module, input) {
logger.info("This is a 'hello world!' from a Javascript rule.");
}
};
sRule.setTriggers([
TriggerBuilder.create()
.withId("aTimerTrigger")
.withTypeUID("timer.GenericCronTrigger")
.withConfiguration(
new Configuration({
"cronExpression": "0 * * * * ?"
})).build()
]);
sRule.name = "JavaScript Hello World example (raw API)";
sRule.description = "This is an example Hello World rule using the raw API";
logger.info("\n\nCalling outputCurrentRules() before creating new rule. UID type is: " +typeof UID +" value: " +UID +"\n\n");
outputCurrentRules();
UID=automationManager.addRule(sRule);
logger.info("\n\nCalling outputCurrentRules() after creating new rule. UID type is: " +typeof UID +" value: " +UID +"\n\n");
outputCurrentRules();
var status = rules.remove(UID);
logger.info("\n\nCalling outputCurrentRules() after attempting to remove new rule. Status is: " +status +" UID type is: " +typeof UID +" value: " +UID +"\n\n");
outputCurrentRules();
var ListOfRules = rules.getAll();
logger.info("\n\n ListOfRules is Type: " +typeof ListOfRules +" and has a value of: " +ListOfRules);
logger.info("ListOfRules has Keys: " +Object.keys(ListOfRules));
and the logger output is:
2021-01-28 13:13:03.492 [INFO ] [openhab.event.RuleUpdatedEvent ] - Rule '5be9c178bc' has been updated.
==> /var/log/openhab/openhab.log <==
2021-01-28 13:13:34.367 [INFO ] [org.openhab.rule.5be9c178bc ] -
Calling outputCurrentRules() before creating new rule. UID type is: undefined value: undefined
2021-01-28 13:13:34.520 [INFO ] [org.openhab.rule.5be9c178bc ] -
Rules found on Call: 1
2021-01-28 13:13:34.753 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [0] is: org.openhab.core.automation.internal.RuleImpl@69d06cd4 and Type is: object
2021-01-28 13:13:34.778 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [1] is: org.openhab.core.automation.internal.RuleImpl@9fdff718 and Type is: object
2021-01-28 13:13:34.797 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [2] is: org.openhab.core.automation.internal.RuleImpl@681c78b4 and Type is: object
2021-01-28 13:13:34.815 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [3] is: org.openhab.core.automation.internal.RuleImpl@5678fbf1 and Type is: object
2021-01-28 13:13:34.833 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [4] is: org.openhab.core.automation.internal.RuleImpl@bf73ef19 and Type is: object
2021-01-28 13:13:34.851 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [5] is: org.openhab.core.automation.internal.RuleImpl@388cf63 and Type is: object
2021-01-28 13:13:34.869 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [6] is: org.openhab.core.automation.internal.RuleImpl@c43cf370 and Type is: object
2021-01-28 13:13:34.887 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [7] is: org.openhab.core.automation.internal.RuleImpl@23397516 and Type is: object
2021-01-28 13:13:34.906 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [8] is: org.openhab.core.automation.internal.RuleImpl@b5761806 and Type is: object
2021-01-28 13:13:34.926 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [9] is: org.openhab.core.automation.internal.RuleImpl@ca8efeff and Type is: object
2021-01-28 13:13:34.956 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [10] is: org.openhab.core.automation.internal.RuleImpl@13917c22 and Type is: object
2021-01-28 13:13:34.974 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [11] is: org.openhab.core.automation.internal.RuleImpl@a8ba356d and Type is: object
2021-01-28 13:13:34.993 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [12] is: org.openhab.core.automation.internal.RuleImpl@a0b8dfcf and Type is: object
2021-01-28 13:13:35.011 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [13] is: org.openhab.core.automation.internal.RuleImpl@e0f71c8c and Type is: object
2021-01-28 13:13:35.030 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [14] is: org.openhab.core.automation.internal.RuleImpl@674571fe and Type is: object
2021-01-28 13:13:35.047 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [15] is: org.openhab.core.automation.internal.RuleImpl@a17fa663 and Type is: object
2021-01-28 13:13:35.074 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [16] is: org.openhab.core.automation.internal.RuleImpl@57fb2b07 and Type is: object
2021-01-28 13:13:35.092 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [17] is: org.openhab.core.automation.internal.RuleImpl@7f6c6d90 and Type is: object
2021-01-28 13:13:35.112 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [18] is: org.openhab.core.automation.internal.RuleImpl@e042ab8 and Type is: object
2021-01-28 13:13:35.130 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [19] is: org.openhab.core.automation.internal.RuleImpl@2b1cfda0 and Type is: object
2021-01-28 13:13:35.148 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [20] is: org.openhab.core.automation.internal.RuleImpl@91d1496d and Type is: object
2021-01-28 13:13:35.166 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [21] is: org.openhab.core.automation.internal.RuleImpl@55d5266a and Type is: object
2021-01-28 13:13:35.185 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [22] is: org.openhab.core.automation.internal.RuleImpl@a2063019 and Type is: object
2021-01-28 13:13:35.321 [INFO ] [org.openhab.rule.5be9c178bc ] -
Return value of rules.getAll() on call[1] is: undefined
2021-01-28 13:13:36.094 [INFO ] [org.openhab.rule.5be9c178bc ] -
Calling outputCurrentRules() after creating new rule. UID type is: object value: org.openhab.core.automation.internal.RuleImpl@8e4e86c6
2021-01-28 13:13:36.218 [INFO ] [org.openhab.rule.5be9c178bc ] -
Rules found on Call: 2
2021-01-28 13:13:36.324 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [0] is: org.openhab.core.automation.internal.RuleImpl@69d06cd4 and Type is: object
2021-01-28 13:13:36.352 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [1] is: org.openhab.core.automation.internal.RuleImpl@9fdff718 and Type is: object
2021-01-28 13:13:36.371 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [2] is: org.openhab.core.automation.internal.RuleImpl@8e4e86c6 and Type is: object
2021-01-28 13:13:36.389 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [3] is: org.openhab.core.automation.internal.RuleImpl@5678fbf1 and Type is: object
2021-01-28 13:13:36.408 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [4] is: org.openhab.core.automation.internal.RuleImpl@c43cf370 and Type is: object
2021-01-28 13:13:36.425 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [5] is: org.openhab.core.automation.internal.RuleImpl@a8ba356d and Type is: object
2021-01-28 13:13:36.444 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [6] is: org.openhab.core.automation.internal.RuleImpl@a17fa663 and Type is: object
2021-01-28 13:13:36.462 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [7] is: org.openhab.core.automation.internal.RuleImpl@a2063019 and Type is: object
2021-01-28 13:13:36.481 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [8] is: org.openhab.core.automation.internal.RuleImpl@681c78b4 and Type is: object
2021-01-28 13:13:36.500 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [9] is: org.openhab.core.automation.internal.RuleImpl@bf73ef19 and Type is: object
2021-01-28 13:13:36.519 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [10] is: org.openhab.core.automation.internal.RuleImpl@388cf63 and Type is: object
2021-01-28 13:13:36.536 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [11] is: org.openhab.core.automation.internal.RuleImpl@23397516 and Type is: object
2021-01-28 13:13:36.555 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [12] is: org.openhab.core.automation.internal.RuleImpl@b5761806 and Type is: object
2021-01-28 13:13:36.579 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [13] is: org.openhab.core.automation.internal.RuleImpl@ca8efeff and Type is: object
2021-01-28 13:13:36.597 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [14] is: org.openhab.core.automation.internal.RuleImpl@13917c22 and Type is: object
2021-01-28 13:13:36.616 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [15] is: org.openhab.core.automation.internal.RuleImpl@a0b8dfcf and Type is: object
2021-01-28 13:13:36.634 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [16] is: org.openhab.core.automation.internal.RuleImpl@e0f71c8c and Type is: object
2021-01-28 13:13:36.652 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [17] is: org.openhab.core.automation.internal.RuleImpl@674571fe and Type is: object
2021-01-28 13:13:36.670 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [18] is: org.openhab.core.automation.internal.RuleImpl@57fb2b07 and Type is: object
2021-01-28 13:13:36.688 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [19] is: org.openhab.core.automation.internal.RuleImpl@7f6c6d90 and Type is: object
2021-01-28 13:13:36.706 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [20] is: org.openhab.core.automation.internal.RuleImpl@e042ab8 and Type is: object
2021-01-28 13:13:36.724 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [21] is: org.openhab.core.automation.internal.RuleImpl@2b1cfda0 and Type is: object
2021-01-28 13:13:36.742 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [22] is: org.openhab.core.automation.internal.RuleImpl@91d1496d and Type is: object
2021-01-28 13:13:36.760 [INFO ] [org.openhab.rule.5be9c178bc ] - Key Value [23] is: org.openhab.core.automation.internal.RuleImpl@55d5266a and Type is: object
2021-01-28 13:13:36.791 [INFO ] [org.openhab.rule.5be9c178bc ] -
Return value of rules.getAll() on call[2] is: undefined
2021-01-28 13:13:37.129 [WARN ] [e.automation.internal.RuleEngineImpl] - Fail to execute action: script
java.lang.ClassCastException: class org.openhab.core.automation.internal.RuleImpl cannot be cast to class java.lang.String (org.openhab.core.automation.internal.RuleImpl is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @187e57b; java.lang.String is in module java.base of loader 'bootstrap')
at org.openhab.core.automation.ManagedRuleProvider.keyToString(ManagedRuleProvider.java:1) ~[?:?]
at org.openhab.core.common.registry.AbstractManagedProvider.remove(AbstractManagedProvider.java:90) ~[?:?]
at org.openhab.core.common.registry.AbstractRegistry.remove(AbstractRegistry.java:359) ~[?:?]
at jdk.nashorn.internal.scripts.Script$Recompilation$28716$\^eval\_$cu1$restOf.:program(<eval>:141) ~[?:?]
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:?]
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:1179) [bundleFile:?]
at org.openhab.core.automation.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1031) [bundleFile:?]
at org.openhab.core.automation.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1047) [bundleFile:?]
at org.openhab.core.automation.rest.internal.RuleResource.runNow(RuleResource.java:314) [bundleFile:?]
at jdk.internal.reflect.GeneratedMethodAccessor73.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:1.0.9]
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96) [bundleFile:1.0.9]
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:201) [bundleFile:1.0.9]
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:104) [bundleFile:1.0.9]
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59) [bundleFile:1.0.9]
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96) [bundleFile:1.0.9]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) [bundleFile:1.0.9]
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) [bundleFile:1.0.9]
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267) [bundleFile:1.0.9]
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234) [bundleFile:1.0.9]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208) [bundleFile:1.0.9]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160) [bundleFile:1.0.9]
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:216) [bundleFile:1.0.9]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:301) [bundleFile:1.0.9]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:220) [bundleFile:1.0.9]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) [bundleFile:3.1.0]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:276) [bundleFile:1.0.9]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:852) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:544) [bundleFile:9.4.20.v20190813]
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.20.v20190813]
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:536) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1581) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1307) [bundleFile:9.4.20.v20190813]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:293) [bundleFile:?]
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:482) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1549) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1204) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [bundleFile:9.4.20.v20190813]
at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80) [bundleFile:?]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.Server.handle(Server.java:494) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:374) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:268) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:367) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:782) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:918) [bundleFile:9.4.20.v20190813]
at java.lang.Thread.run(Thread.java:834) [?:?]
2021-01-28 13:14:00.692 [INFO ] [org.openhab.rule.5be9c178bc ] - This is a 'hello world!' from a Javascript rule.
If I just get a list of rules using the following code:
var ListOfRules = rules.getAll();
logger.info("\n\n ListOfRules is Type: " +typeof ListOfRules +" and has a value of: " +ListOfRules);
logger.info("ListOfRules has Keys: " +Object.keys(ListOfRules));
then although typeof reports that ListOfRules is an Object if I try and get the Keys using Object.keys() then I get a type error:
2021-01-28 13:31:33.151 [INFO ] [org.openhab.rule.5be9c178bc ] -
ListOfRules is Type: object and has a value of: [org.openhab.core.automation.internal.RuleImpl@69d06cd4, org.openhab.core.automation.internal.RuleImpl@9fdff718, org.openhab.core.automation.internal.RuleImpl@8e4e86c6, org.openhab.core.automation.internal.RuleImpl@5678fbf1, org.openhab.core.automation.internal.RuleImpl@c43cf370, org.openhab.core.automation.internal.RuleImpl@a8ba356d, org.openhab.core.automation.internal.RuleImpl@a17fa663, org.openhab.core.automation.internal.RuleImpl@a2063019, org.openhab.core.automation.internal.RuleImpl@681c78b4, org.openhab.core.automation.internal.RuleImpl@bf73ef19, org.openhab.core.automation.internal.RuleImpl@388cf63, org.openhab.core.automation.internal.RuleImpl@23397516, org.openhab.core.automation.internal.RuleImpl@b5761806, org.openhab.core.automation.internal.RuleImpl@ca8efeff, org.openhab.core.automation.internal.RuleImpl@13917c22, org.openhab.core.automation.internal.RuleImpl@a0b8dfcf, org.openhab.core.automation.internal.RuleImpl@e0f71c8c, org.openhab.core.automation.internal.RuleImpl@674571fe, org.openhab.core.automation.internal.RuleImpl@57fb2b07, org.openhab.core.automation.internal.RuleImpl@7f6c6d90, org.openhab.core.automation.internal.RuleImpl@e042ab8, org.openhab.core.automation.internal.RuleImpl@2b1cfda0, org.openhab.core.automation.internal.RuleImpl@91d1496d, org.openhab.core.automation.internal.RuleImpl@55d5266a]
2021-01-28 13:31:33.414 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID '5be9c178bc' failed: TypeError: [org.openhab.core.automation.internal.RuleImpl@69d06cd4, org.openhab.core.automation.internal.RuleImpl@9fdff718, org.openhab.core.automation.internal.RuleImpl@8e4e86c6, org.openhab.core.automation.internal.RuleImpl@5678fbf1, org.openhab.core.automation.internal.RuleImpl@c43cf370, org.openhab.core.automation.internal.RuleImpl@a8ba356d, org.openhab.core.automation.internal.RuleImpl@a17fa663, org.openhab.core.automation.internal.RuleImpl@a2063019, org.openhab.core.automation.internal.RuleImpl@681c78b4, org.openhab.core.automation.internal.RuleImpl@bf73ef19, org.openhab.core.automation.internal.RuleImpl@388cf63, org.openhab.core.automation.internal.RuleImpl@23397516, org.openhab.core.automation.internal.RuleImpl@b5761806, org.openhab.core.automation.internal.RuleImpl@ca8efeff, org.openhab.core.automation.internal.RuleImpl@13917c22, org.openhab.core.automation.internal.RuleImpl@a0b8dfcf, org.openhab.core.automation.internal.RuleImpl@e0f71c8c, org.openhab.core.automation.internal.RuleImpl@674571fe, org.openhab.core.automation.internal.RuleImpl@57fb2b07, org.openhab.core.automation.internal.RuleImpl@7f6c6d90, org.openhab.core.automation.internal.RuleImpl@e042ab8, org.openhab.core.automation.internal.RuleImpl@2b1cfda0, org.openhab.core.automation.internal.RuleImpl@91d1496d, org.openhab.core.automation.internal.RuleImpl@55d5266a] is not an Object in <eval> at line number 150
I’m thoroughly confused and am not sure what to try next. But while I have failed to find a solution myself or by searching the forum I am sure someone more experienced than me must have come across this problem and solved it. So can someone please shine some light on what I need to do to get the ID of a rule and then delete the rule.
Many thanks in advance.