Triggering a rule in Paper UI causes an exception if the rule has not already been triggered elsewhere

A couple issues here then.

  1. 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 the ERE runs).
    So knowing that both use the same run time engine is helpful information to know. However, from a practical perspective this distinction is one that will only be important and only make sense for users who are working at a very low level in OH. The types of people who are trying to use the ERE right now are going to think that the PaperUI Rules entry forms are the ERE. So do we need to invent a new name to avoid this confusion? Because for the most part, I suspect that at this point in time only you and the devs working with the ERE and JSR223 will think JSR223 when they see ERE. The rest of us will think either the PaperUI UI or JSONDB Rules that it produces.

  2. For the JSON Rules, why do I have to import anything? Everything else about this Rule is already done for us, defining the trigger, defining the conditions under which the Rule can run (but only if), etc. Everything I need to define the body of the Rule should already be there and I should only have to start writing my script.

In short, I should only need to have that one line to write a Rule in the ERE UI and use core OH Actions. All of that proforma type stuff should already be there and all I should have to write are the actions that do what needs to be done when that Rule is triggered.

I copied and pasted that code and I get exceptions:

2018-10-24 09:15:19.955 [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) ~[?:?]
...

That is why I was assuming that the JSON DB Rules and JSR223 are fundamentally different. I did try.

Then I’ll need more help to explain what I’m doing wrong. Because everything I try to replicate from GitHub - lewie/openhab2-javascript: JSR223 JavaScript Code openHAB 2.x automation fails to work when entered into the PaperUI scripts. Particularly since the code you pasted in above works for you and an exact copy and paste of it throws ClassNotFoundExceptions for me.

I’d like to get this stuff working because, try as we might to prevent it, new users keep trying to use PaperUI Rules and there are no docs and no experience from the users on this forum to help and this will only get worse. I’d like to get out in front of this and start generating some docs.

I should note that log import and call does work. It is dumb but I’ve never tried just a basic hello world logging Rule. So logging works and works the same as JSR223 JavaScript. But executeCommandLine, at least for me, does not work and I’d really love to know why. If I can log, create Timers (I’m about to experiment with that), call the core Actions, and access the implicit variables (or the JS equivalents) I’ll have enough to start building comprehensive documentation.

Oh, and how to import JS libraries would be terribly helpful as well.

Thanks for the info. You have been very helpful. Getting the logger to work might be just enough to help me figure some of these things out on my own.

Update: I tried to create a Timer with

'use strict';
var log = Java.type("org.slf4j.LoggerFactory").getLogger("org.eclipse.smarthome.model.script.Rules");
log.info("test", "Hello world")

var ScriptExecution = Java.type("org.eclipse.smarthome.model.script.actions.ScriptExecution");
ScriptExecution.createTimer(now().plusSeconds(2), function(){log.info("test", "timer log");});

And I get a ClassNotFoundException for org.eclipse.smarthome.model.script.actions.ScriptExecution.

The log import and log.info works.