[beta testers wanted!] Jython addon w/ helper libraries (requires OH 2.5.x)

Hi All. I’ve been getting heavy into Jython scripting recently and have run into an issue on OH in a Docker container. It’s OH 2.5.8. I originally had the beta add-on installed and everything was running fine. I just tried the manual upgrade to jython-standalone-2.7.0.jar and am getting the following error for all python scripts (note, I’m just showing hello_world as an example, but it’s happening with all scripts):

Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/personal/hello_world.py': SystemError: Automatic proxy initialization should only occur on proxy classes in <script> at line number 8

For the upgrade, I shut down the container, pulled the org.openhab.core.automation.module.script.scriptenginefactory.jython-2.5.0-SNAPSHOT.jar file from add-ons, followed the instructions in installing the ython-standalone-2.7.0.jar file - as well as the latest helper libs from the https://openhab-scripters.github.io/openhab-helper-libraries site, changed the EXTRA_JAVA_OPTS in the docker-compose file to

      EXTRA_JAVA_OPTS: "-Duser.timezone=America/Chicago -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">

and checked the file locations in the container to make sure everything was in the right spot. When I got the errors initially, I stopped the container and manually removed the cache/ and tmp/ folders, then restarted. I’ve now restarted a couple of times, but the same errors persist. Any thoughts on troubleshooting?

Thanks in advance.

Just a quick edit: If I stop the container, add back the beta add-on, change EXTRA_JAVA_OPTS back, and restart the container, everything works again. I’m clearly missing something regarding not fully removing the old add-on configuration…

I have no idea why you would want to use a manual installation, which you can see is prone to error :wink:, but shutting down OH, removing the addon from /addons/, clearing the cache, and restarting OH will remove the addon. Have you looked at the Docker installation instructions for the helper libraries?

You are missing a forward slash at the beginnings of python.home and python path. If you are using the latest version, there is a script included in the helper libraries that will log system info. What do you see in the log when OH starts?

I have no idea why you would want to use a manual installation, which you can see is prone to error :wink:, but shutting down OH, removing the addon from /addons/, clearing the cache, and restarting OH will remove the addon. Have you looked at the Docker installation instructions for the helper libraries?

Mainly, I was going to just make sure I was using the latest setup instead of the Jython 2.5 beta add-on. That was about it…

You are missing a forward slash at the beginnings of python.home and python path. If you are using the latest version, there is a script included in the helper libraries that will log system info. What do you see in the log when OH starts?

Good catch. I thought I had done a direct copy/paste from the Docker section of the docs, but I must have pulled the path info from the direct install instructions and modified them. I’ve slept since then, but it’s a completely embarrassing mistake. :relaxed: I simultaneously installed it on an Rpi OH installation, and somewhere I must have just dropped the ball and copied the paths one to another.

I won’t have a chance to try it again until tomorrow evening, but now it completely makes sense why it didn’t pick anything up correctly. Sad thing is, I beat my head against the wall for an hour trying to figure out what wasn’t working. I assumed there was more “magic” in beta binding that there probably is, so I figured I just missed something other than just the path info.

After I give it another go tomorrow, I’ll let you know if there’s a problem, but I suspect (as is usual), it was just “user error.”

Thanks for responding, though. Sometimes it’s the little things that seem to cause more problems than the big things…

1 Like

I would like to start testing with Jython Rules as well, but in OH3.
From my understanding (reading a lot of forum topics) the Jython add on does not come by default with oh3.
So… do I have to install it the same way as mentioned in the first post?

I have this working on my standalone install from the Debian package but I’m not having any luck when trying to move this over to Docker.

Is someone that’s got this working with Docker able to give concise instructions please?

From what I can tell, it may not even work with OH3. I’d be interested in a definitive answer on this as well. Assuming it does work, it’s worth the effort for the manual install (which isn’t that difficult). I am able to do some things with Jython that just weren’t working in Rules DSL. Whether it’s going to work in OH3 is a big deal to me now…

Hi @danielwalters86. Sorry I didn’t see your post earlier, since I just recently went through everything on Docker myself. Are you still having issues? I have it working on Docker, natively on Debian, and on Openhabian.

Make sure the paths are correct (I’m assuming you’re using Docker-Compose?)

@RipNCode thanks for your reply.

Yes using docker-compose to pull the 2.5.9-snapshot image where I have mapped the following volumes to folders on my host OS:

/openhab/addons
/openhab/conf
/openhab/userdata

I have placed the org.openhab.core.automation.module.script.scriptenginefactory.jython-2.5.0-SNAPSHOT.jar into the addons folder on my host OS. I’m not sure what I should be doing next.

Thanks

There are actually two ways to do this. The first is with the beta add-on and manually adding the helper libraries. The second is to use the Jython 2.7.0.jar and add it to a given location (typically in the $CONF/automation/jython folder that needs to be created), then point docker-compose to the file location and restart OH so it picks it up. I recently moved from the add-on to the 2.7.0.jar, so I’ll try and address both.

I’m assuming NGRE is installed in your docker OH image.

Install the org.openhab.core.automation.module.script.scriptenginefactory.jython-2.5.0-SNAPSHOT.jar file in the [docker path]/openhab/conf/openhab2-addons folder.

Download the helper libraries from here to your openhab/conf directory (or someplace else - you’ll be mimicking the directory structure of this download in your openhab-conf/ directory).

It has all of the helper libraries - some of which you will have to use, and some of which you will probably want to use. I put the whole zip file in the conf directory to keep all of the sources (just a personal decision) and then created the directory structure manually.

The structure should look like this. Essentially, you need an “automation” folder in your openhab/conf directory (along with rules, items, services, etc folders). In the automation folder, you will need need a directory structure for the libraries/modules (/automation/lib/…), and for the scripts (rules) in (/automation/jsr223/…). The subdirectories below those paths are for the language choices, then for files for either the core helper libraries (core - required to have), community contributions (some good stuff in there), or your own stuff (personal folder). So, from the downloaded zip file, you need, at minimum, to put in the core files to /automation/jsr223/python/core and the same to on the /automation/lib/python/core side.

At that point, the directories will work and the files are there. Now you have to make some changes to the config files in the automation structure you just created (easy, but easily overlooked). At this page on the docs, pay attention to step 8. Once you have the core stuff in place, you need to make it “active” by renaming these files from default.

The easy way to test it before an OH restart is to put the hello_world.py script from the original downloaded files in [wherever you downloaded them]/openhab-helper-libraries-master/Script Examples/Python/hello_world.py into your /openhab-conf/automation/jsr223/python/personal/ directory. Now restart your container and watch the logs. The hello_world script should eventually load and you’ll see it spamming you. At that point you can move or delete it and you’ll be good to go.

The instructions for using the 2.7.0.jar are about the same, but you have to tell OH where to find it. You’ll stop OH. Remove the beta add-on. Download the 2.7.0.jar and create a directory in your automation folder called “jython” and put the .jar there. Then in your docker-compose file, point to where it is:

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”

Then restart it.

That was a bit verbose, but hopefully it helps. Once you get it, it’s straightforward. IMO, what’s missing in the docs is a big picture context to what all you’re doing. Basically, you’re adding jython.jar support to some location and building a directory structure with the downloaded helper libraries. That’s really all there is, but it is error prone, especially when it lacks a bit of context for a new user.

2 Likes

Thanks for your detailed write up. I’m pretty sure I had done all those steps…the jar was in the addons folder, my docker-compose file had the EXTRA_JAVA_OPTS entry and I had copied over my old conf folder which included the automation folder.

Alas, I started again from scratch and followed your steps and the hello_world.py is now running :smile:

Great. I’m glad I could help. Fortunately, I had just gone through all of this myself, so it was still fresh on my mind.

1 Like

I’m sorry. I’ve done all I can. The maintainers have very obtusely prevented the merge of my add-ons for almost a year now, so you will need to continue to wait.

What trouble are you having? The installation for docker should be the same as for non-docker.

No… the helper libraries are included in the add-on. If you are using the add-on, just install the scripts, not the libraries.

Can’t we indtall manually? I was able to get it started on OH2.5.6.148 as I remember under Java11 with Jython 2.7.0. Probably not as I do not see installable base of the rule engine in OH3 at all.

In OH3, manual installations of Jython have been broken for a long time. I believe this is true of all scripting languages. I do not plan to spend the time to look into it until my other development efforts are unblocked. So, you currently need an add-on, but they have not been merged and are now closed. Also, Java11 will require Jython 2.7.2 or newer. Just wait… a solution is on the way!

5 Likes

I’d appreciate some clarification what all of this means? Is jsr223 with its languages not supported by OH3? Are the helper libraries not supported? Is this a dead end?

Previously, there were many messages in the community that DSL rules will not work in openHAB3 and it will be necessary to rewrite all the rules for the new engine. I rewrote all the rules and I’m ready to go, but as I understand it, there is openHAB3, but my new rules will not work? In the release notes, OpenHAB3 saw information that the DSL rules are supported. Was I rewriting my rules in vain?

It’s not so much because of OH3 but more because of newer Java versions.

The extension mechanism was removed in Java 9 so any JARs added to /runtime/lib/ext will not be used.

See also:

1 Like

This is not true - DSL rules still work in OH3. Can you link to any authoritative statements which says that DSL rules won’t work in OH3?

I’m running OH 2.5.9 on Java 11(openjdk) with these Jython addon from this thread. And it’s working nicely.

1 Like

Having a Jython add-on can fix it for OH3 too. :wink: It’s the manual installations of JARs in /runtime/lib/ext that most likely also won’t work for you with Java 11.