Converting rules and .js files

I am trying to use my 2.x rules and the javascript snippets that I had developed. Very probably this is explained somewhere, as I am for sure not the first one having these problems, but I did not find the instructions.

I have two problems for now:

  • .rules: triggeringItem is not passed to the rule anymore, the variable is zero. Can I replace that with another item?
  • .js: All my javascript files start with the following lines:
    • load(Java.type(“java.lang.System”).getenv(“OPENHAB_CONF”)+’/automation/jsr223/jslib/JSRule.js’);
    • var ThingUID = Java.type(“org.eclipse.smarthome.core.thing.ThingUID”);
      These not work anymore. I understand that the second line should have the new namespace org.openhab.core.thing.ThingUID or something like that, but that doesn’t work either.

I would be very helpful if someone could point me to the instructions that I have missed.


Note that is just the name of the Item. To get the Item’s state you can use:

event.itemState or if it’s not the state from the triggering Item items[itemName].

First of all, I assume you are writing rules in .js files using the Helper Libraries? If so, the Helper Libraries have a different path and different file names than that. For example, to import the rules libraries the path would be /automation/lib/javascript/core/rules.js. Note that you must “install” the libraries manually yourself. If that load doesn’t work any more it’s because that SRule.js file doesn’t exist or doesn’t exists at that path.

OH now has no references to org.eclipse.smarthome. That particular class is now in org.openhab.core.thing