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

I see. Sorry I try it tomorrow. Too late here. Than I come back that it works.

Here is the result in the log file. I will try voice only tomorrow but I’m sure that as it works voice will be same good as well.

2020-07-22 23:17:05.048 [INFO ] [hon.Open/Close shutters when raining] - Elállt az eső, kezdem nyitni a redőnyöket!

Thanks!

1 Like

@5iver do you plan to release addon jar with jython-2.7.2 included?
Asking because upt to 2.7.2 there is a quite serious security vuln. in jython.

Currently I’m using 2.7.2 via manual install without problems, however my installation is not big in terms of jython usage.

Jython 2.7.2 is included in the PR. The beta jar is pretty old at this point, waiting for the maintainers to merge. I will update the jars (there will be two, since Jythion and the libraries have been split) after pushing some new features to the helper libraries. So, it is coming!

1 Like

I installed OH3 snapshot and Jython does not work, here the log :

2020-09-15 19:04:39.359 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/etc/openhab/automation/jsr223/python/core/components/100_DirectoryTrigger.py'
2020-09-15 19:04:40.412 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/jsr223/python/core/components/100_DirectoryTrigger.py': java.lang.NullPointerException: java.lang.Nu
llPointerException in <script> at line number 6
2020-09-15 19:04:40.413 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/etc/openhab/automation/jsr223/python/core/components/100_OsgiEventTrigger.py'
2020-09-15 19:04:41.504 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/jsr223/python/core/components/100_OsgiEventTrigger.py': java.lang.NullPointerException: java.lang.Nu
llPointerException in <script> at line number 5
2020-09-15 19:04:41.515 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/etc/openhab/automation/jsr223/python/core/components/100_StartupTrigger.py'
2020-09-15 19:04:42.438 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/jsr223/python/core/components/100_StartupTrigger.py': java.lang.NullPointerException: java.lang.Null
PointerException in <script> at line number 6
2020-09-15 19:04:42.439 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/etc/openhab/automation/jsr223/python/core/components/200_JythonBindingInfoProvider.py'
2020-09-15 19:04:43.519 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/jsr223/python/core/components/200_JythonBindingInfoProvider.py': java.lang.NullPointerException: jav
a.lang.NullPointerException in <script> at line number 5
2020-09-15 19:04:43.519 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/etc/openhab/automation/jsr223/python/core/components/200_JythonExtensionProvider.py'
2020-09-15 19:04:44.143 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/jsr223/python/core/components/200_JythonExtensionProvider.py': java.lang.NullPointerException: java.
lang.NullPointerException in <script> at line number 6
2020-09-15 19:04:44.144 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/etc/openhab/automation/jsr223/python/core/components/200_JythonItemChannelLinkProvider.py'
2020-09-15 19:04:44.866 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/jsr223/python/core/components/200_JythonItemChannelLinkProvider.py': java.lang.NullPointerException:
 java.lang.NullPointerException in <script> at line number 6
2020-09-15 19:04:44.867 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/etc/openhab/automation/jsr223/python/core/components/200_JythonItemProvider.py'
2020-09-15 19:04:45.744 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/jsr223/python/core/components/200_JythonItemProvider.py': java.lang.NullPointerException: java.lang.
NullPointerException in <script> at line number 6
2020-09-15 19:04:45.744 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/etc/openhab/automation/jsr223/python/core/components/200_JythonThingProvider.py'
2020-09-15 19:04:46.448 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/jsr223/python/core/components/200_JythonThingProvider.py': java.lang.NullPointerException: java.lang
.NullPointerException in <script> at line number 5
2020-09-15 19:04:46.448 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/etc/openhab/automation/jsr223/python/core/components/200_JythonThingTypeProvider.py'
2020-09-15 19:04:47.267 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/jsr223/python/core/components/200_JythonThingTypeProvider.py': java.lang.NullPointerException: java.
lang.NullPointerException in <script> at line number 5
2020-09-15 19:04:47.268 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/etc/openhab/automation/jsr223/python/core/components/200_JythonTransform.py'
2020-09-15 19:04:47.850 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/jsr223/python/core/components/200_JythonTransform.py': java.lang.NullPointerException: java.lang.Nul
lPointerException in <script> at line number 7

the line is :
scriptExtension.importPreset(None)
if I removed it, the next error is on
import core

Someone have an idea?
the init script is good :

2020-09-15 19:04:05.673 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/etc/openhab/automation/jsr223/python/core/000_startup_delay.py'
2020-09-15 19:04:09.351 [INFO ] [jsr223.jython.core.startup_delay    ] - Checking for initialized context
2020-09-15 19:04:09.356 [INFO ] [jsr223.jython.core.startup_delay    ] - Context initialized... waiting 30s before allowing scripts to load
2020-09-15 19:04:39.358 [INFO ] [jsr223.jython.core.startup_delay    ] - Complete

I don’t know if I need to open a new thread, let me know.
Thanks for your help

This add-on is only compatible with OH 2.5. Last I looked and have mentioned a couple times in the forum, Jython 2.7.2 or newer is required for OH 3.0. I haven’t put much time into it, but manual installations of Jython and other languages are not working in OH 3.0, so it appears add-ons for ScriptEngineFactories may be required for OH 3.0. This could possibly be due to PRs that were merged even after I had specifically asked for them not be merged until after I had reviewed and tested them.

I had originally submitted a Jython PR nearly a year ago, before the OH 2.5.0 release, but the maintainers chose to ignore the submission and then not make any effort to include it in the release. Since then, the OH maintainers have chosen to ignore or block my automation development efforts (read through the PRs in the OP), so these PRs will not be included in any openHAB release. Don’t fret though… after finishing up some updates to the helper libraries, I will provide an update to this add-on. This will allow everyone to use add-ons to install the latest helper libraries and Jython 2.7.2 with OH 2.5.x. As for post OH 2.5.x, :zipper_mouth_face:

2 Likes

Thanks! But what about OH3? It is not clear for me how it will be integrated/included. I thought that OH3 will come with your rule engine built in by default.

Are you able to tell me what this means in terms of supported rules languages will be installed by default or that can be installed from the UI in OH3? It seems disappointing to me that the Jython add-on isn’t moving towards being merged, at least that’s the impression I get.

IMHO, using Jython and your fantastic helper libraries for rules is immensely more flexible than the rules DSL and I’d love for Jython to be available OOB or via the usual simple click-to-install-addon method.

1 Like

+1

I have invested heavily in Jython scripting and really want to see this to be a first class citizen in OH3. Is there any type of white paper on the future of OH 3.0 scripting? Is there a strategy or direction beyond a dependency to contributor’s or maintainer’s taste?

2 Likes

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