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

It should not be a problem to have the core and community libs in /automation/lib/python/, as long as they are up to date. Unless you are developing them, it is best to not copy them and just use the libraries in the add-on.

I have a lot of documentation and library updates to push, which includes steps for installing the add-on, but I’ll update the OP with this info.

1 Like

Can I use a library like Pandas in Jython and how would this work?

I’m getting a complicated JSON string that I need to sort and filter to get to the right information. Currently a bit clueless on how to approach that. I do have a Python script (using pandas) to accomplish it, but if possible I’d love to do it all inside OH.

Pandas requires Python >= 3.6.1, so you would need to call your script through executeCommandLine to pull the data in. Although, if you are just pulling data from JSON, you could use the built-in json package. This doesn’t have anything to do with this add-on though, so please create a new topic to discuss further.

Will this be released in a future version of openhab before openhab 3?
or is the only way to play arround with rules in jython if you manually install it?

That is my hope, but it is up to the maintainers. I initially submitted a PR to be included in 2.5.0, but it was never reviewed. The Jython add-on has now been reviewed and approved by one maintainer, but it needs one more approval. The Jython helper library add-on has not been reviewed yet. The PRs (included in the OP) and also this issue will give you the current status.

I started to use Google TTS in Jyhton. It works with Hungarian Wavenet shyntetesis in DSL Rules. Now I tried Jython and it seems that it does not recognize Hungarian charachters.
I saved it in the log file as well to show the result.

from core.actions import Voice # Google TTS say command

Closeshuttersinrain.log.info("Elállt az eső, kezdem nyitni a redőnyöket!")
Voice.say("Elállt az eső, kezdem nyitni a redőnyöket!")

Result:

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

Can you check how characther sets are used?

This is not specific to the add-on, so should go into a new topic. Use Unicode for special characters…

Closeshuttersinrain.log.info(u"Elállt az eső, kezdem nyitni a redőnyöket!")

I have an update coming that swaps everything I could find to unicode for the core libs, but you’ll still need to specify it in your scripts.

Ok. Shall I wait till it is coming out and I will see how to specify UTF-8 in my coding?

No… try using unicode like what I posted (add a ‘u’ in front).

1 Like

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?