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

If you install the “Jython Scripting” add-on via the “Automation” add-ons type you can use Python in UI/file based rules.

It doesn’t include any helper libraries but once they are updated for OH3 they can also be included ofcourse.

1 Like

How and where to do it?

Like this:

4 Likes

Thanks, could not find it because I still had M1 installed :slight_smile:

I have strange error messages and DSL rules has some issues as well. So I will try to figure out the problems and come back if I can’t solve it. Also I will report if it works.

Tried to migrate from 2.5 to 3.0RC2
Installed Jython add-on
got this error at starup:

2020-12-20 11:12:24.563 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/etc/openhab/automation/jsr223/python/core/components/100_DirectoryTrigger.py'
2020-12-20 11:12:24.868 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation ofscript 'file:/etc/openhab/automation/jsr223/python/core/components/100_DirectoryTrigger.py': java.lang.NullPointerException: java.lang.NullPointerException in <script> at line number 6

2020-12-20 11:12:28.480 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/jsr223/python/personal/verlichting_kast_lamp.py': ImportError: No module named core in <script> at line number 1

This is with all the scripts. It was working nice in OH2.5

I think all the helper libraries for OH3 are still missing or not updated to use in OH3. You could use python in your rules, but all the imports still do not work:
e.g.

from core.rules import rule
from core.triggers import when
from core.log import logging, LOG_PREFIX
from core.actions import Transformation

Exactly!

It looks like the Helper library will make sense for Jython file rules, but are not necessary for the Jython UI rules approach? I haven’t installed OH3 yet, but are there mechanisms to group UI rules somehow? The number of rules I have implemented will be far to big to have them in one long list…

Yes using the helper library probably makes the most sense when creating file based rules.

Currently you can only filter rules based on their name. I think adding additional ways to filter/group items/rules/things might make sense for OH 3.1+.

The Demo has been updated to OH3 so you can give it a try without installing anything :slight_smile:

https://demo.openhab.org/ (to login to admin mode use username: demo and password: demo)

I’ve just tried updating from OH2 to OH3 RC2, installed the Jython scripting automation addon, but my scripts aren’t running. It seems that the helper libraries need to be updated.

Sorry I tried to look but haven’t managed to find it. Where can I find the jython helper libraries for OH3? Is it not publicly available yet?

10 posts above yours!

Either you misunderstood my question or I misunderstood your suggestion. I have already got Jython Scripting installed. I was asking about the jython helper libraries, not the Jython scripting support.

I had the jython helper libraries from OH2 in my conf/automation/ folder as it was running on OH2. They produced errors in OH3:

2020-12-21 17:42:04.292 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/core/components/100_DirectoryTrigger.py': java.lang.NullPointerException: java.lang.NullPointerException in <script> at line number 6
2020-12-21 17:42:04.292 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/core/components/100_OsgiEventTrigger.py'
2020-12-21 17:42:04.735 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/core/components/100_OsgiEventTrigger.py': java.lang.NullPointerException: java.lang.NullPointerException in <script> at line number 5
2020-12-21 17:42:04.736 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/core/components/100_StartupTrigger.py'
2020-12-21 17:42:05.221 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/core/components/100_StartupTrigger.py': java.lang.NullPointerException: java.lang.NullPointerException in <script> at line number 6
2020-12-21 17:42:05.222 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/core/components/200_JythonBindingInfoProvider.py'
2020-12-21 17:42:05.652 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/core/components/200_JythonBindingInfoProvider.py': java.lang.NullPointerException: java.lang.NullPointerException in <script> at line number 5
2020-12-21 17:42:05.654 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/core/components/200_JythonExtensionProvider.py'
2020-12-21 17:42:06.152 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/core/components/200_JythonExtensionProvider.py': java.lang.NullPointerException: java.lang.NullPointerException in <script> at line number 6
2020-12-21 17:42:06.153 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/core/components/200_JythonItemChannelLinkProvider.py'
2020-12-21 17:42:06.647 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/core/components/200_JythonItemChannelLinkProvider.py': java.lang.NullPointerException: java.lang.NullPointerException in <script> at line number 6
2020-12-21 17:42:06.647 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/core/components/200_JythonItemProvider.py'
2020-12-21 17:42:07.319 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/core/components/200_JythonItemProvider.py': java.lang.NullPointerException: java.lang.NullPointerException in <script> at line number 6
2020-12-21 17:42:07.320 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/core/components/200_JythonThingProvider.py'
2020-12-21 17:42:07.896 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/core/components/200_JythonThingProvider.py': java.lang.NullPointerException: java.lang.NullPointerException in <script> at line number 5
2020-12-21 17:42:07.897 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/core/components/200_JythonThingTypeProvider.py'
2020-12-21 17:42:08.461 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/core/components/200_JythonThingTypeProvider.py': java.lang.NullPointerException: java.lang.NullPointerException in <script> at line number 5
2020-12-21 17:42:08.462 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/core/components/200_JythonTransform.py'
2020-12-21 17:42:08.903 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/core/components/200_JythonTransform.py': java.lang.NullPointerException: java.lang.NullPointerException in <script> at line number 7

I think you have misunderstood.

Again:

To be clear: the Jython helper libraries are not available for OH3 at the moment.

I’ve uploaded my temporary fix for the jython helper libraries. Details can be found here: Jython helper libraries for OH3

1 Like

Is there any news about getting things running in OH3 as good as it is in OH2.5?

I thought it was already in OH3.

There is an open PR that make the Jython libraries compatible with OH3. You will need to install the Jython automation addon and follow the manual installation instructions in the HL docs to use it.

It works fine with OH3 with the linked PR for me. There was some difficulties but only because of Joda time - Java time change.

1 Like

I’m having some issues getting the patched Jython libraries working.

My set up:

  1. Docker image: openhab-3.1.0-snapshot (arm64)
  2. Jython automation bundle installed
  3. Files copied into /jsr223/python/core and /lib/python/core
  4. Configuration.py set up

Logs:

2021-01-06 13:09:50.028 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Time zone set to 'Europe/London'.

2021-01-06 13:09:50.158 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Location set to '52.40304863399438,-1.8824170479174995'.

2021-01-06 13:09:50.177 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Locale set to 'en_GB'.

2021-01-06 13:10:06.222 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mapdb.persist'

2021-01-06 13:10:06.998 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'influxdb.persist'

2021-01-06 13:10:13.554 [INFO ] [.core.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007

2021-01-06 13:10:15.822 [INFO ] [ab.core.service.AbstractWatchService] - ScriptEngine for py not available

2021-01-06 13:10:15.827 [INFO ] [ab.core.service.AbstractWatchService] - ScriptEngine for py not available

2021-01-06 13:10:15.839 [INFO ] [ab.core.service.AbstractWatchService] - ScriptEngine for py not available

2021-01-06 13:10:15.843 [INFO ] [ab.core.service.AbstractWatchService] - ScriptEngine for py not available

2021-01-06 13:10:15.847 [INFO ] [ab.core.service.AbstractWatchService] - ScriptEngine for py not available

2021-01-06 13:10:15.865 [INFO ] [ab.core.service.AbstractWatchService] - ScriptEngine for py not available

2021-01-06 13:10:20.667 [INFO ] [org.openhab.ui.internal.UIService   ] - Started UI on port 9080

2021-01-06 13:10:20.841 [INFO ] [e.automation.internal.RuleEngineImpl] - Rule engine started.

2021-01-06 13:10:26.919 [INFO ] [io.openhabcloud.internal.CloudClient] - Connected to the openHAB Cloud service (UUID = feb126b2-dea5-4766-a20f-959231dea89c, base URL = http://localhost:9080)

2021-01-06 13:10:28.017 [INFO ] [internal.ModuleHandlerFactoryStarter] - WebPushNotificationModuleHandlerFactory started by ModuleHandlerFactoryStarter

2021-01-06 13:10:28.706 [INFO ] [hab.ui.habot.tile.internal.HABotTile] - Started HABot at /habot

2021-01-06 13:10:29.221 [INFO ] [ab.ui.habpanel.internal.HABPanelTile] - Started HABPanel at /habpanel

2021-01-06 13:10:35.805 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/core/000_Startup.py'

2021-01-06 13:10:38.512 [WARN ] [jython.startup                      ] - 

*******************************************************************************

Jython version:             2.7.2.final

Operating system:           Linux

OS Version:                 5.4.0-1025-raspi

Java vendor:                Azul Systems, Inc.

Java VM name:               OpenJDK 64-Bit Server VM

Java runtime name:          OpenJDK Runtime Environment

Java runtime version:       11.0.9+11-LTS

configuration.py installed: True

sys.path:                   /openhab/conf/automation/lib/python

                            /openhab/userdata/cache/org.eclipse.osgi/270/0/bundleFile/Lib

                            __classpath__

                            __pyclasspath__/

*******************************************************************************

2021-01-06 13:10:38.517 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/core/components/100_DirectoryTrigger.py'

2021-01-06 13:10:40.099 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/core/components/100_StartupTrigger.py'

2021-01-06 13:10:40.954 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/personal/cron.py'

2021-01-06 13:10:46.124 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/personal/hello_world.py'

2021-01-06 13:10:48.980 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/personal/new_hello_world.py'

So OH3 can detect and run at least some .py files but the hello_world.py does not run. It seems to parse the rule and is listed but I get no output in the logs that it’s running.

Any ideas what to try?