Reloading/Autoupdating JS233 (JavaScript) rules

Hi,

I am migrating all my rules from DSL format into JS233/JavaScript format (running openHAB 3.1.0.M3).

I do use VS Code to write and edit the *.js files (which are located in /etc/openhab/automation/jsr223/javascript/personal). The rules all have the “new” coding style like:

'use strict';
var OPENHAB_CONF = Java.type("java.lang.System").getProperty("openhab.conf");
var JS_PATH = OPENHAB_CONF + "/automation/lib/javascript";

load(JS_PATH + "/core/rules.js");
load(JS_PATH + "/core/triggers.js");
load(JS_PATH + "/core/metadata.js");
load(JS_PATH + "/core/log.js");
load(JS_PATH + "/personal/myfunctions.js");

var LOG = getLogger(LOG_PREFIX + ".test");  

var Message;

function test(event) { 
    LOG.info("Log something")
    events.sendCommand("Test_Switch", OFF)
}
when("Item Test_Switch changed")(test);
rule(
    " Test",
    "No desc"
)(test);

Everything actually works well except of the reloading (or better said autoupdating) of the rules. That said, if I am modify let’s say an *.item file which contains items which are used in JavaScript rules the JS rule is not getting updated with the information from the ItemRegistry like it is used in DSL rules.

Also when I do changes in a bib which is imported via the "load(“path/to/bib.js”) function the changes are not visible in the main rules.

I do have either restart OH3 all the time or reloading the *.js files by modifying them (add one empty space and save them again).

How can I solve this?

Thanks!

Might this be related -

Yes this seems to be preety much the same bug.

I also was migrating from OH2.5.X to OH3.

The manifestation so far observed in DSL seems confined to rule triggers (but of course if the rule doesn’t trigger, you don’t know what else doesn’t work!)

Is there some other symptom you have seen here?

Yes I‘ve added an Item to a group which is observed in a JS rule.

Item state changed and nothing happened.

As I did a manual Save of the JS rule (to force the reload) the next item change fired the rule.

As a trigger? It’s a known limitation that group based triggers (equivalent of Member of xxx in DSL) are actually constructed one by one from the membership that exists at rule load time.

However, if that were all that were going on, trigger from an “old” member should still work even if a “new” member does not.
I suspect a change in Group membership might be having the same effect as a direct edit though, and killing all the triggers? But it is important not to confuse two different effects here.

Yes it was a Member of group item.

But this also happened to an existing member of the group. Even there I had to reload the *.js file to get the Event fired.