This guide is written for openHAB v2.4, at the time of writing, it was Build #1390. To get this build, run
docker pull openhab/openhab:2.4.0-snapshot-amd64-debian.
Once you have openHAB installed and running, you can install Jython as follows (these are the steps I figured out after some trial and error).
Install the Next-Generation Rule Engine (in Paper UI, go to Add-ons > Misc, find Rule Engine (Experimental), and click “INSTALL”.
Once installed, Jython and the helper libraries can be installed into openHAB.
Get the files for openhab2-jython:
mv openhab2-jython-master/automation conf/
mv is to move the automation directory into the conf directory that’s mounted in openHAB at
If you already have an automation directory, manually move over the individual directories.
Next, get and install the actual Jython binary:
curl http://search.maven.org/remotecontent?filepath=org/python/jython-standalone/2.7.0/jython-standalone-2.7.0.jar -o jython-standalone-2.7.0.jar
mv jython-standalone-2.7.0.jar conf/automation/jython/
conf directory above is the directory that’s mounted in openHAB.
Finally, copy over the
hello_world.py script so we can see things happening in the logs.
cp openhab2-jython-master/Script\ Examples/Python/hello_world.py conf/automation/jsr223/python/personal
When starting the docker container, include the environment variable as follows:
-e "EXTRA_JAVA_OPTS=-Xbootclasspath/a:/openhab/conf/automation/jython/jython-standalone-2.7.0.jar -Dpython.home=/openhab/conf/automation/jython -Dpython.path=/openhab/conf/automation/lib/python"
Or, if you are using a compose file, include this:
EXTRA_JAVA_OPTS: "-Xbootclasspath/a:/openhab/conf/automation/jython/jython-standalone-2.7.0.jar -Dpython.home=/openhab/conf/automation/jython -Dpython.path=/openhab/conf/automation/lib/python"
You should see something such as this in the logs:
2018-10-17 02:18:06.704 [INFO ] [.internal.GenericScriptEngineFactory] - Activated scripting support for python
After a minute or two, this should appear in the logs every 10 seconds or so:
2018-10-17 02:24:40.077 [INFO ] [eclipse.smarthome.model.script.Rules] - JSR223: This is a 'hello world!' from a Jython rule (decorator): Cron
Building image from Dockerfile
In the /Docker/Python/ directory, there is an example Dockerfile which will add Jython support to the given container version.
It includes a script to enable the Next-Generation Rule Engine in the addons.cfg and adds necessary entries to
EXTRA_JAVA_OPTS (including setting python.path to
As a user, you only need to add Python scripts and rules to your
To build a container with jython, simply run
docker build --build-arg OPENHAB_VERSION=2.4.0.M6-amd64-debian .
Jython will be installed in
The installation directory, as well as Jython version, can be set with build args (see the /Docker/Python/Dockerfile).