Migrate from Nashorn to JSScripting for UI Rules

Just watch the announcements is the best I can offer. Changes in behavior, make big fixes, and breaking changes are are announced there on milestone or major releases.

Things get implemented when and if someone volunteers to do it so it’s not possible to forecast when something gets done. But this particular behavior has been identified as a potential problem already.

1 Like

I do not understand completely that Jhyton and JS Scripting can run parallel or not. I understand that Jhyton will be depreciated in certain time so we need to change to JS Scription what is not good as I had plenty of work to change to Jhyton (Python) from DSL. I have tried to install JS Scripting:

But it gave the following error:

So I assumed that libraries are missing and I installed it with NPM.
Then after restart of openhab it gave the errors in the following log.
JS and Jhyton scripting startup.log (20.6 KB)
here is my system detailes
system detailes.txt (2.2 KB)
My questions are that two scripting engine can run parallel or I need to wait?
Did I installed something wrong?
What is your suggestion for the change?

Yes the can.

That time is not determined and likely will not be under our control. But I wouldn’t expect it to happen any time soon. There should be no pressure to rush and change to a new language right now.

That’s not what that means I think. That looks like the JSON perfect by the page is malformed. Try restarting OH and refreshing the page to get a lean slate and see if that works. If it doesn’t yet clearing the cache using openhab-cli.

There is a known problem with the latest version of openhab-js on npm which causes some errors in the logs about being unable to load some core libraries. You might be seeing that. But given that I’m pretty sure the problem is not caused by the library I recommend deleting what was installed by npm.

Many thanks for your kind prompt reply!
I do not understand clearly what does it mean page is malformed.
When I installed JS Scripting from binding it had created only empty subfolders in automation folder (JS). After OH restart libraries were not created as well.
That’s why I updated the libraries by NPM. After that I restarted OH 3 times but it frozen due to Java heap error (memory run out). So I had to remove JS Scripting libraries and OH started only after that again.
Catch was not emptied. I can do it but how can I install JS Scripting libraries?

The library is included in the binding, but you can not see it in the folder.

Remove the node_modules folder from automation/js. Then install the JS Scripting binding and DO NOT install the openhab library manually.
Create a script that is using the library and it should work (without manually installing or seeing the library in automation/js).

Ok. I was doing it this way at the very beginning. That was the point when I get this error:

Both try to make a script through UI or create it from file. Same result. If I get the same error, what should I check?
I guessed that Jhyton Scripting set up and new JSS Scripting have conflict, pls bear in mind that I use Ivan’s Helper Libraries: Ivan’s Helper Libraries - OH3, Python, JavaScript

The same error cannot happen if you create .js files because the concept on a Script Action really only exists in a UI rule.

That error is complaining about the JSON that makes up the rule. In specific, it’s complaining that you have a Script Action without a “script” element. It’s not even getting to the point where Jython or JSScripting comes into play.

That’s what I mean by the time being malformed.

If possible, it might be informative to see what’s in the code tab. And anything posted to the logs when you see that error in the UI is always useful.

Despite that error, can you get to the text editor and enter some code? Can you save the rule and come back to edit it?

Theoretically, not only can you have Jython and JSScripting in different rules at the same time, you can use it in the same rule.

So error was due to Script was empty. Now it has green idle status.
This would be my fisrt code:

rules.JSRule({
  name: "Turn on yard decor ligtes in case of double click",
  description: "Turn on yard decor ligtes in case of double click",
  triggers: [triggers.ChannelEventTrigger('Channel mihome:86sw2:286C0785BE33:158d0002fb4e94:ch2', 'DOUBLE_PRESSED')],
  execute: data => {
    items.getItem("LUMILumiRelayC2Acn01200158D00067C96F71Switch").sendCommand("ON");
  }
});

But this is not good for UI scripting. I was looking for some simple examples but I can’t find any suitable for me.

All you define in a UI rule Script Action is the execute part. Everything else is defined in the form. You only use JSRule or the time Builder in .js files.

I have posted all of my complete JSScripting rules at Some JS Scripting UI Rules Examples. Since are simple, some are complex. Skip to the actual rules which come after the libraries.