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
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
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?
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
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.
Iām having some issues getting the patched Jython libraries working.
My set up:
Docker image: openhab-3.1.0-snapshot (arm64)
Jython automation bundle installed
Files copied into /jsr223/python/core and /lib/python/core
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.
Done the same on the OH 3.0.0 docker installation:
2021-01-06 12:45:03.405 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/core/000_Startup.py'
2021-01-06 12:45:05.507 [WARN ] [jython.startup ] -
*******************************************************************************
Jython version: 2.7.2.final
Operating system: Linux
OS Version: 5.4.72-v7l+
Java vendor: Azul Systems, Inc.
Java VM name: OpenJDK Client VM
Java runtime name: OpenJDK Runtime Environment
Java runtime version: 11.0.9+11-LTS
configuration.py installed: False
sys.path: /openhab/conf/automation/lib/python
/openhab/userdata/cache/org.eclipse.osgi/214/0/bundleFile/Lib
__classpath__
__pyclasspath__/
*******************************************************************************
2021-01-06 12:45:05.509 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/core/components/100_DirectoryTrigger.py'
2021-01-06 12:45:07.481 [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 8
2021-01-06 12:45:07.483 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/core/components/100_StartupTrigger.py'
2021-01-06 12:45:10.073 [WARN ] [jython.core.log ] - The 'configuration.py' file is missing from teh python.path!
2021-01-06 13:00:52.784 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/personal/Hello.py'
2021-01-06 13:00:55.469 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/personal/Hello.py'
2021-01-06 13:01:22.180 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/openhab/conf/automation/jsr223/python/personal/Hello.py'
2021-01-06 13:01:26.262 [WARN ] [jython.core.log ] - The 'configuration.py' file is missing from teh python.path!
2021-01-06 13:01:26.953 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/personal/Hello.py': ImportError: No module named joda in <script> at line number 6
Only error messages no output at all.
The hello world example:
"""
This script uses a decorated cron rule that will generate logs every 10s and can be used to test your initial setup.
"""
from core.rules import rule
from core.triggers import when
@rule("Jython Hello World (cron decorators)", description="This is an example cron triggered rule using decorators", tags=["Test tag", "Hello World"])# description and tags are optional
@when("Time cron 0/10 * * * * ?")
def hello_world_cron_decorators(event):
hello_world_cron_decorators.log.info("Hello World!")
@danielwalters86 please post more of your log. Do you see warn entries like lukics?
@lukics you are indeed missing the configuration.py file, but that is not why the hello.py script is not loading. I see a warning in your log saying that joda cannot be imported, if you were indeed running the patch from PR #376 you would not see this error. Please make sure that you updated to the correct version.
@CrazyIvan359 I have updated my post with a longer log.
Edit: This is strange. I tried to debug what was going on so I sshād into the karaf console and issued the command log:set DEBUG at 13:55 and all of a sudden I had output in the logsā¦