Hello everyone
I am playing around with the new OH3 snapshots. I am not at all adept at writing JS rules. But i also know that the new OH3 UI supports Rule DSL. I am hoping it supports both - creating new and reading from the .rules files.
Could some bodybe kind to guide me on how to start writing Rules DSL scripts using the OH3 UI?
I read somewhere on Github that these need to start with //context: <something>
and indeed a .rules file appears so in the UI. But what about creating a new one? How do i start? Whats the value after context
?
My simple newrule.rules
file:
rule "New rule for testing"
when
Item HallTV received command On
then
logInfo("TV","Received command On")
end
how it looks in OH3 UI:
// context: newrule-1
logInfo("TV","Received command On")
I see many things all mashed together here.
JS rules use the NGRE Rule engine or manuual install in OH 2 & 3.
Rules DSL. In OH 2 these were generally file based. I understand OH3 accepts filr based rules in addition to allowing creation through the UI.I have created a couple of rules through the UI.
Are you wanting to write rules files or use the UI??
This does not use the UI though.
This is extremely confusing.
ok sorry, i will try to re state.
OH3 UI allows creation of rule scripts using ECMA - 262 5.1 (which i assume is the Nashorn / JS223 implementation)
My simple objective is to create a Rule DSL script using this UI (–>edit script). What do i write here? You mentioned you have done this, can you share some example?
The example i posted above.
newrule.rules
file - created from the command prompt and saved in
When seen from the UI:
Another example where it did not work for me. I created this Rule DSL script - i just get loads of errors.
2020-09-20 02:48:23.803 [WARN ] [e.automation.internal.RuleEngineImpl] - Fail to execute action: 1
org.eclipse.xtext.parser.ParseException: java.lang.IllegalStateException: Unresolved proxy https://openhab.org/model/Script#//Script. Make sure the EPackage has been registered.
at org.eclipse.xtext.parser.antlr.AbstractAntlrParser.doParse(AbstractAntlrParser.java:105) ~[?:?]
...
Hope it makes sense what i am trying to accomplish.
I have not seen that menu option. How did you get that?? I only see Rules mentioned in the UI, not Scripts. I am running Build #1928 .
I just when to the Rules menu on the left & clocked the +
sign, starting a new rule. No choice of rule type.
ysc
(Yannick Schaus)
September 19, 2020, 10:03pm
5
On the screen with the rules list, click on the blue “+” button in the lower-right corner, give an ID and a name, then click “Add action”, pick “execute a given script”, choose “Rule DSL” as the language then you can write your script the same way you would in the “then” section of a rule in .rules file.
Add a trigger if needed and click Save. Currently this will get back to the rules list (but it will probably be changed).
If you need to continue editing the rule again, click on it then on the little icon on the action item - it’s a shortcut to edit the script, saves a click.
Tip: while you’re editing you can use Ctrl+S to save it and Ctrl+R to run it immediately (no matter what the triggers are).
If you write your rules in a .rules file, they will appear in the UI but you can’t edit them (that’s why you have a lock icon after the name).
1 Like
ysc:
you can write your script the same way you would in the “then” section of a rule in .rules file.
Thanks but this doesn’t work. See screenshot above where I just put a logInfo("abcd","abcd")
and it gives an error
sihui
(SiHui)
September 20, 2020, 6:04am
8
Bruce_Osborne:
Where is that “script type” selection menu? Is it only on a build newer than 1928?
No, I am also using #1928:
2 Likes
ysc
(Yannick Schaus)
September 20, 2020, 6:54am
9
Hm, you’re right, I can reproduce this, pretty sure it worked before. Maybe @Kai can comment - otherwise please open an issue here: Issues · openhab/openhab-core · GitHub to have to looked at.
1 Like
Kai
(Kai Kreuzer)
September 20, 2020, 7:52am
10
Would have to dig into it as well - so yes, please open an issue for it.
1 Like
Okay, its weird but it started working. On its own. I dont know how. The only thing i did was (1) update by raspberry pi OS and (2) link the rule to trigger from an item instead of directly triggering from UI. And now it executs every time; even if i create a new scipt from UI.
Initially I thought it could be related to these (the JSR223 scripts still suffer from this) -
opened 06:51PM - 24 Oct 18 UTC
bug
Automation
EDIT: At first I thought this was recently introduced, but it was not. Steps to … reproduce [in this post](https://community.openhab.org/t/using-javascript-actions-in-paper-ui-created-rules/54580/5?u=5iver). The same occurs when using the REST API `/rules/{ruleUID}/runnow` (which is what Paper UI is sending).
> Try modifying the rule, doesn’t matter what you change… could be the name. Save the rule and DON"T execute from Paper UI. Trigger the rule though the Item. I use smarthome:send Test_Switch_1 ON from Karaf. No exception. Then try triggering the rule through Paper UI. No exception.
>
> To reproduce the exception, modify/save the rule, then execute through Paper UI. Exception. Trigger through Item. Exception.
>
> Seems the first trigger must not be through Paper UI, or you will get the exception. Once triggered from something other than Paper UI, you can then trigger through Paper UI. AND I have only seen the exception if the Rule Action contains Javascript with a Core Action.
If everything in the Action is commented out but the LoggerFactory import and the log statement, the exception does not occur. There looks to be an issue in the [getContext](https://github.com/eclipse/smarthome/blob/master/bundles/automation/org.eclipse.smarthome.automation.core/src/main/java/org/eclipse/smarthome/automation/core/internal/RuleEngineImpl.java#L1114) when the rule has not already been triggered by an event. Here is the JS Action:
```
'use strict';
var log = Java.type("org.slf4j.LoggerFactory").getLogger("org.eclipse.smarthome.model.script.Rules");
var Exec = Java.type("org.eclipse.smarthome.model.script.actions.Exec");
var test = Exec.executeCommandLine("echo hello world", 5000);
log.info("JSR223: JS: Test executeCommandLine [" + test + "]");
```
```
Rule saved in Paper UI:
2018-10-25 00:16:32.611 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleUpdatedEvent
2018-10-25 00:16:32.612 [DEBUG] [pse.smarthome.automation.module.core] - ServiceEvent UNREGISTERING - {org.eclipse.smarthome.core.events.EventSubscriber}={service.id=445, service.bundleid=235, service.scope=singleton, event.topics=smarthome/items/Test_Switch_1/command} - org.eclipse.smarthome.automation.module.core
2018-10-25 00:16:32.614 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
2018-10-25 00:16:32.614 [TRACE] [l.factory.ScriptModuleHandlerFactory] - create 2 -> script.ScriptAction
2018-10-25 00:16:32.615 [TRACE] [ore.factory.CoreModuleHandlerFactory] - create 1 -> core.ItemCommandTrigger : cd1cce1b-f559-48ef-a955-210d019586ad
2018-10-25 00:16:32.616 [DEBUG] [pse.smarthome.automation.module.core] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.events.EventSubscriber}={service.id=446, service.bundleid=235, service.scope=singleton, event.topics=smarthome/items/Test_Switch_1/command} - org.eclipse.smarthome.automation.module.core
2018-10-25 00:16:32.617 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
Rule triggered through Item (successful):
2018-10-25 00:16:49.075 [TRACE] [re.handler.ItemCommandTriggerHandler] - ->FILTER: smarthome/items/Test_Switch_1/command:Test_Switch_1
2018-10-25 00:16:49.076 [TRACE] [re.handler.ItemCommandTriggerHandler] - Received Event: Source: null Topic: smarthome/items/Test_Switch_1/command Type: ItemCommandEvent Payload: {"type":"OnOff","value":"ON"}
2018-10-25 00:16:49.078 [DEBUG] [omation.core.internal.RuleEngineImpl] - The trigger '1' of rule 'cd1cce1b-f559-48ef-a955-210d019586ad' is triggered.
2018-10-25 00:16:49.079 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
2018-10-25 00:16:49.153 [INFO ] [eclipse.smarthome.model.script.Rules] - JSR223: JS: Test executeCommandLine [hello world]
2018-10-25 00:16:49.153 [DEBUG] [omation.core.internal.RuleEngineImpl] - The rule 'cd1cce1b-f559-48ef-a955-210d019586ad' is executed.
2018-10-25 00:16:49.154 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
Rule triggered through Paper UI (successful):
2018-10-25 00:17:02.827 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
2018-10-25 00:17:02.880 [INFO ] [eclipse.smarthome.model.script.Rules] - JSR223: JS: Test executeCommandLine [hello world]
2018-10-25 00:17:02.881 [DEBUG] [omation.core.internal.RuleEngineImpl] - The rule 'cd1cce1b-f559-48ef-a955-210d019586ad' is executed.
2018-10-25 00:17:02.882 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
Rule name changed and saved through Paper UI:
2018-10-25 00:18:10.884 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleUpdatedEvent
2018-10-25 00:18:10.885 [DEBUG] [pse.smarthome.automation.module.core] - ServiceEvent UNREGISTERING - {org.eclipse.smarthome.core.events.EventSubscriber}={service.id=446, service.bundleid=235, service.scope=singleton, event.topics=smarthome/items/Test_Switch_1/command} - org.eclipse.smarthome.automation.module.core
2018-10-25 00:18:10.887 [TRACE] [l.factory.ScriptModuleHandlerFactory] - create 2 -> script.ScriptAction
2018-10-25 00:18:10.887 [TRACE] [ore.factory.CoreModuleHandlerFactory] - create 1 -> core.ItemCommandTrigger : cd1cce1b-f559-48ef-a955-210d019586ad
2018-10-25 00:18:10.889 [DEBUG] [pse.smarthome.automation.module.core] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.events.EventSubscriber}={service.id=447, service.bundleid=235, service.scope=singleton, event.topics=smarthome/items/Test_Switch_1/command} - org.eclipse.smarthome.automation.module.core
2018-10-25 00:18:10.891 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
2018-10-25 00:18:10.892 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
Rule triggered through Paper UI (exception):
2018-10-25 00:18:20.020 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
2018-10-25 00:18:20.040 [WARN ] [omation.core.internal.RuleEngineImpl] - Fail to execute action: 2
java.lang.RuntimeException: java.lang.ClassNotFoundException: org.eclipse.smarthome.model.script.actions.Exec cannot be found by com.eclipsesource.jaxrs.publisher_5.3.1.201602281253
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:397) ~[?:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:449) ~[?:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:406) ~[?:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:402) ~[?:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155) ~[?:?]
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) ~[?:?]
at org.eclipse.smarthome.automation.module.script.internal.handler.ScriptActionHandler.lambda$0(ScriptActionHandler.java:60) ~[?:?]
at java.util.Optional.ifPresent(Optional.java:159) ~[?:?]
at org.eclipse.smarthome.automation.module.script.internal.handler.ScriptActionHandler.execute(ScriptActionHandler.java:57) ~[?:?]
at org.eclipse.smarthome.automation.core.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1198) [234:org.eclipse.smarthome.automation.core:0.10.0.201810180807]
at org.eclipse.smarthome.automation.core.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1055) [234:org.eclipse.smarthome.automation.core:0.10.0.201810180807]
at org.eclipse.smarthome.automation.core.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1071) [234:org.eclipse.smarthome.automation.core:0.10.0.201810180807]
at org.eclipse.smarthome.automation.rest.internal.RuleResource.runNow(RuleResource.java:288) [243:org.eclipse.smarthome.automation.rest:0.10.0.201810180807]
at sun.reflect.GeneratedMethodAccessor32.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) [170:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) [170:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.internal.Errors.process(Errors.java:315) [170:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.internal.Errors.process(Errors.java:297) [170:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.internal.Errors.process(Errors.java:267) [170:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) [170:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473) [168:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.2]
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427) [168:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.2]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388) [168:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.2]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341) [168:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.2]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228) [168:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.2]
at com.eclipsesource.jaxrs.publisher.internal.ServletContainerBridge.service(ServletContainerBridge.java:76) [20:com.eclipsesource.jaxrs.publisher:5.3.1.201602281253]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:865) [85:org.eclipse.jetty.servlet:9.4.11.v20180605]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:535) [85:org.eclipse.jetty.servlet:9.4.11.v20180605]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71) [185:org.ops4j.pax.web.pax-web-jetty:7.2.3]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548) [82:org.eclipse.jetty.security:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1317) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:293) [185:org.ops4j.pax.web.pax-web-jetty:7.2.3]
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473) [85:org.eclipse.jetty.servlet:9.4.11.v20180605]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1219) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80) [185:org.ops4j.pax.web.pax-web-jetty:7.2.3]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.Server.handle(Server.java:531) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:352) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:281) [75:org.eclipse.jetty.io:9.4.11.v20180605]
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102) [75:org.eclipse.jetty.io:9.4.11.v20180605]
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118) [75:org.eclipse.jetty.io:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:762) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:680) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at java.lang.Thread.run(Thread.java:748) [?:?]
Caused by: java.lang.ClassNotFoundException: org.eclipse.smarthome.model.script.actions.Exec cannot be found by com.eclipsesource.jaxrs.publisher_5.3.1.201602281253
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:484) ~[?:?]
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395) ~[?:?]
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387) ~[?:?]
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150) ~[?:?]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:?]
at org.eclipse.osgi.internal.framework.EquinoxBundle.loadClass(EquinoxBundle.java:564) ~[?:?]
at org.ops4j.pax.swissbox.core.BundleClassLoader.findClass(BundleClassLoader.java:176) ~[185:org.ops4j.pax.web.pax-web-jetty:7.2.3]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:?]
at org.ops4j.pax.swissbox.core.BundleClassLoader.loadClass(BundleClassLoader.java:192) ~[185:org.ops4j.pax.web.pax-web-jetty:7.2.3]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:?]
at java.lang.Class.forName0(Native Method) ~[?:?]
at java.lang.Class.forName(Class.java:348) ~[?:?]
at jdk.nashorn.internal.runtime.Context.findClass(Context.java:1051) ~[?:?]
at jdk.nashorn.internal.objects.NativeJava.simpleType(NativeJava.java:498) ~[?:?]
at jdk.nashorn.internal.objects.NativeJava.type(NativeJava.java:322) ~[?:?]
at jdk.nashorn.internal.objects.NativeJava.type(NativeJava.java:314) ~[?:?]
at jdk.nashorn.internal.objects.NativeJava.type(NativeJava.java:310) ~[?:?]
at jdk.nashorn.internal.scripts.Script$68$\^eval\_.:program(<eval>:3) ~[?:?]
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:637) ~[?:?]
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494) ~[?:?]
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) ~[?:?]
... 71 more
2018-10-25 00:18:20.043 [DEBUG] [omation.core.internal.RuleEngineImpl] - The rule 'cd1cce1b-f559-48ef-a955-210d019586ad' is executed.
2018-10-25 00:18:20.043 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
```
A couple issues here then.
Where is/should this documented? Right now to indicate that the ERE rules and JSR223 Rules are the same. They are created differently (ERE uses PaperUI, JSR223 uses text files), stored differently (ERE Rules are stored in the JSONDB), and neither docs (unless I missed it) reference the other. As far as most users will be concerned, the PaperUI UI IS the ERE. As far as I was concerned, the JSON that gets saved to JSONDB for each Rule is the ERE (or at least the code…
But I just cant reproduce the issue now. Rule DSL scripts created from the UI are executing fine. I restarted the OS, re-created rules, wrote a new script etc., but it just seems to be working fine now. @ysc please check the behaviour at your end too. Maybe by creating a new Rule DSL from UI, triggering it from an item and then triggering again from UI.
1 Like
I am experiencing a similar issue with OH3 build 1945.
When I write a simple rule and save this in conf/rules this rule is properly executed.
When I create the same rule in the UI, the rule does not execute. I get the following in the log:
[ERROR] [internal.handler.ScriptActionHandler] - Script execution failed: An error occurred during the script execution: null
My file based rule, when looking in the UI is shown as:
triggers:
id: “0”
configuration:
cronExpression: 0 0 0 * * ?
type: timer.GenericCronTrigger
conditions: []
actions:
inputs: {}
id: script
configuration:
type: application/vnd.openhab.dsl.rule
script: |
// context: system-2
counter = Uptime.state as DecimalType
counter = counter + 1
postUpdate(Uptime, counter)
watchdog = 0
postUpdate(Watchdog, watchdog)
type: script.ScriptAction
The rule created in UI:
triggers:
id: “0”
configuration:
cronExpression: 0 0 0 * * ?
type: timer.GenericCronTrigger
conditions: []
actions:
inputs: {}
id: script
configuration:
type: application/vnd.openhab.dsl.rule
script: |
var Number counter = Uptime.state as DecimalType
counter = counter + 1
postUpdate(Uptime, counter)
var Number watchdog = 0
postUpdate(Watchdog, watchdog)
type: script.ScriptAction
The main difference is that in my file based rules, I have declared the variables globally. In the UI based rule I declared these in the rule.
When I copy the line with // context to the UI based rule, it does function.
I have submitted an issue for this:
opened 08:37AM - 04 Oct 20 UTC
I am running OH3 build #1945.
When I write a simple rule and save this as a .rules file in conf/rules this...
1 Like