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…
Thanks, any ideas why I can’t import libraries into my personal scripts?
In OH2 I had my libraries in /lib/python/personal and would use something like
import personal.my_utils.py
but now I get the message
Error during evaluation of script ‘file:/openhab/conf/automation/jsr223/python/personal/hello_world_v2.py’: ImportError: No module named personal in at line number 6
Assuming you have a file named my_utils.py in the personal folder, you would import and use it like this:
from personal import my_utils
my_utils.my_func()
Alternatively you can import thing from you file like this:
from personal.my_utils import my_func
my_func()
@lukics you don’t necessarily have to put your code in the __init__.py file, there just needs to be an __init__.py file for you to be able to import things from that folder.
Yes, it definitely works, I just wanted to let you know that you don’t have to put all the module code in that file because it can get long and messy having a big module stuffed into a single file.
The add-on is not available in OH3, but there is an updated version of the Helper Libraries available. This post contains notes and instructions on getting that set up. Skip steps 10 and 11, they do not apply in OH3 because the new Python Automation add-on handles them for you.
It helps if you paste the link location when making a link… Doh! Fixed now.
There is a .pylintrc file in the root of the repo, and a page in the documentation that covers setting up VSC to work a little better. I am working on stubs for all of openHAB and the Helper Libraries, hopefully I will be able to get the finishing touches on soon and get them released.