How to install JavaScript Scripts/Rules in OpenHab 3.1


I have been trying to install and run JavaScript Rule/Scipts. I have followed this intructions: JavaScript Scripting - Automation | openHAB I have also installed modified helper libaries from Ivan: GitHub - CrazyIvan359/openhab-helper-libraries: JSR223-Jython scripts and modules for use with openHAB, but I still keep getting errors like:

 org.graalvm.polyglot.PolyglotException: ReferenceError: "scriptExtension" is not define

That is when I am running HelloWorld.js example from Helper Libraries.

I was trying to google this issue, but I wasn’t able to find my answer. Any suggestion will be greatly appreciated.
I am running freshly installed OpenHab 3.1 on PI4B 4GB installed with OpenHabian.


There are two JavaScripts supported, one just comes with OH and it’s there by default. The other is a separately installed add-on. The two are not really compatible with each other. The Helper Libraries you link to only work for the built in JavaScript. So uninstall the add-on.


Thank you for help! I somehow missed your response. That explains a bit. First I have installed Add-on implementation, but I could run my test script as well. I was getting undefined “event” exception. Now, after I uninstalled Add-on and only left helper libraries I am getting this error:

[ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/jsr223/javascript/personal/HelloWorld.js': java.lang.ClassNotFoundException: org.eclipse.smarthome.model.script.actions.ScriptExecution

This is from hello world example from helper libaries that looks like this:

'use strict';
var OPENHAB_CONF = Java.type("java.lang.System").getenv("OPENHAB_CONF");
var me = "HelloWorld.js";

    name: "Javascript Hello World (GenericCronTrigger raw API with JS helper libraries)",
    description: "This is an example Jython cron rule using the raw API",
    triggers: [
        TimerTrigger("0/10 * * * * ?")
    execute: function( module, inputs){
        logInfo("Hello World!");

Is it better to install Helper Libraries or use JavaScript Add-on? I just need to do some REST request to communicate with my intercom. I didn’t manage to run any implementation.

Kind Regards,

That looks like you’ve not installed the correct version of the helper libraries for OH 3. You need GitHub - CrazyIvan359/openhab-helper-libraries at js-rewrite.

Beyond that I’m not going to be much help. While I’m using the older default JavaScript exclusively to write my rules, I’m also doing so exclusively in the UI and not using the helper libraries so I can more easily write rule templates.

Right now, probably not. In a couple weeks, probably yes.

So why not use Rules DSL? There are lots of examples of doing that on the forum and no external libraries required.

I instal

The reason is, that I needed to use websocket. If I understand correctly, websockets are not supported with Rules DSL. I ended up using HabApp and writting rule with python.

Many thanks. I greatly appreciate what you do to support OpenHab community! Have a great Sunday.