JSR223 Jython with Docker openHAB

Here is a quick and dirty how-to for getting the JSR223 Jython working with OH in Docker.

These instructions do not require modifications to the official Docker image.

WARNING: I’ve not gone any further than seeing that the empty test.py script is seen and loaded.

See the JSR223 docs for details.

  1. Download and install Jython to some directory that gets mounted into your openHAB volume. It seems feasible that the stand alone jar file might work for this but I did the full install. I chose /opt/openhab2/conf/jython as this is directory that gets loaded into the container under /openhab/conf.

  2. Create a folder to store any Python libraries and packages you will want to be available to your Jython rules. I chose /opt/openhab2/conf/lib/python.

  3. Whatever you use to start the openHAB container, (Docker-Compose, Ansible, by hand) you will need to add the following environment variable to the container:

EXTRA_JAVA_OPTS="-Xbootclasspath/a:/openhab/conf/jython/jython.jar -Dpython.home=/openhab/conf/jython -Dpython.path=/openhab/conf/lib/python"

where /openhab/conf/jython and /openhab/conf/lib are replaced with where ever you mount the jython and lib folders we just created is located.

  1. Create /opt/openhab2/conf/automation/jsr223 folder which will hold the scripts.

  2. Create an empty test.py file in conf/automation/jsr223.

  3. Start the openHAB container with the new environment variable option and watch the logs. You should log entries showing that python, ECMAScript are enabled and a line showing test.py being loaded.

  4. Install the Experimental Rules Engine.

I’d love to hear if someone tries using just the stand alone jar file or further experiments.

EDIT: Added step 7 as the Experimental Rules Engine is required to run JSR223.


Thanks for this! Just added this to my image, seems to work fine. I used the stand alone jar (which only installs jython.jar).

Maybe make a small change to your guide: mention the same path in step 1 and step 3 (conf/jsr223 vs conf/jython)

Thanks, error has been corrected. It’s good to know the stand alone will work.

Thanks Rich! About exec bindings and os.system() calls, I found the topic Running Exec binding scripts in Docker using custom image very useful.