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

True, did not pull the oh3-patch branch

After setting the debug level I see the “Hello World” output

Thanks for the help.

1 Like

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

You have to rename the file to _ init _ .py (remove the additional extension)

image

@danielwalters86

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.

Sure,
Maybe my statement above was not clear enough, that’s what I meant.

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.

@lukics Thank you, this was what I was missing. My file was still called __init__.py.example

This was useful information too. I’m now up and running calling a basic library function so thank you both :+1:

1 Like

Sry if this is answered anywhere here in this thread, but it takes month to read all posts…

Am I able to get this running with OH3 or not? and if the answer is yes, what is required to get this working?

I got:

  • the 2.5 addon jar
  • the helper libs
  • the helper lib workaround for OH3
  • renamed configuration.py and init.py
  • using jython-standalone-2.7.0.jar

maybe I miss something or it isn’t possible for now?!

cheers, Dan

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.

1 Like

thanks but your link does not work… can you please correct it :wink:

I think it is here Dan

1 Like

thanx :wink: I think it’s running for me now, but VSCode still complains - can I ignore these errors?

Unable to import 'core.triggers'pylint(import-error)
Undefined variable 'items'pylint(undefined-variable)

etc…

1 Like

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.

5 Likes

ok thanks a lot :slight_smile: