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

I keep getting the error below on startup although it does not seem to affect stuff once running.
Wonder if that “2.5.0;3.0.0” needs to be adapted for 2.5.1 to make this warning go away.

2020-01-17 12:38:07.104 [WARN ] [org.apache.felix.fileinstall        ] - Error while starting bundle: file:/usr/share/openhab2/addons/org.openhab.core.automation.module.script.scriptenginefactory.jython-2.5.0-SNAPSHOT.jar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.core.automation.module.script.scriptenginefactory.jython [203]
  Unresolved requirement: Import-Package: org.openhab.core.automation.module.script; version="[2.5.0,3.0.0)"

        at org.eclipse.osgi.container.Module.start(Module.java:444) ~[org.eclipse.osgi-3.12.100.jar:?]
        at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:383) ~[org.eclipse.osgi-3.12.100.jar:?]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260) [bundleFile:3.6.4]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233) [bundleFile:3.6.4]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1221) [bundleFile:3.6.4]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:515) [bundleFile:3.6.4]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365) [bundleFile:3.6.4]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316) [bundleFile:3.6.4]

The “2.5.0;3.0.0” means that the dependency requirement would be met with a version >= 2.5.0 and < 3.0.0. I can’t reproduce this error… I’m on 2.5.1-2 and using the version of the Jython bundle from the OP. The only time I would expect to see this is when restarting OH after clearing the cache.

Not sure this is the right thread, but I have problems installing Jython scripting too. I have the latest openHABian distribution with openHAB updated to 2.5.1. I have scripting support for Javascript installed already and it is working. I have installed the scripting support for Jython following https://openhab-scripters.github.io/openhab-helper-libraries/Getting%20Started/Installation.html in addition. I hope to not have missed anything. I have stopped and restarted openHAB too.

My problem is that no .py script is recognized and loaded. With all the debug options enabled, I get jsr223.javascript output, but nothing on Jython…

I’m curious about the discussion on EXTRA_JAVA_OPTS. I think I have set it correctly, this is the lengthy process description I get from ps -axl:

4   110   489     1  20   0 911324 305760 -     Ssl  ?          5:30 /usr/bin/java -Dopenhab.home=/usr/share/openhab2 -Dopenhab.conf=/etc/openha
b2 -Dopenhab.runtime=/usr/share/openhab2/runtime -Dopenhab.userdata=/var/lib/openhab2 -Dopenhab.logdir=/var/log/openhab2 -Dfelix.cm.dir=/var/lib
/openhab2/config -Djava.library.path=/var/lib/openhab2/tmp/lib -Djetty.host=0.0.0.0 -Djetty.http.compliance=RFC2616 -Dorg.ops4j.pax.web.listenin
g.addresses=0.0.0.0 -Dorg.osgi.service.http.port=8080 -Dorg.osgi.service.http.port.secure=8443 -Djava.awt.headless=true -Xms250m -Xmx650m -Xbootclasspath/a:/etc/openhab2/automation/jython/jython-standalone-2.7.1.jar -Dpython.home=/etc/openhab2/automation/jython -Dpython.path=/etc/openhab2/automation/lib/python -Djava.endorsed.dirs=/opt/jdk/zulu8.40.0.178-ca-jdk1.8.0_222-linux_aarch32hf/jre/lib/endorsed:/opt/jdk/zulu8.40.0.178-ca-jdk1.8.0_222-linux_aarch32hf/lib/endorsed:/usr/share/openhab2/runtime/lib/endorsed -Djava.ext.dirs=/opt/jdk/zulu8.40.0.178-ca-jdk1.8.0_222-linux_aarch32hf/jre/lib/ext:/opt/jdk/zulu8.40.0.178-ca-jdk1.8.0_222-linux_aarch32hf/lib/ext:/usr/share/openhab2/runtime/lib/ext -Dkaraf.instances=/var/lib/openhab2/tmp/instances -Dkaraf.home=/usr/share/openhab2/runtime -Dkaraf.base=/var/lib/openhab2 -Dkaraf.data=/var/lib/openhab2 -Dkaraf.etc=/var/lib/openhab2/etc -Dkaraf.log=/var/log/openhab2 -Dkaraf.restart.jvm.supported=true -Djava.io.tmpdir=/var/lib/openhab2/tmp -Djava.util.logging.config.file=/var/lib/openhab2/etc/java.util.logging.properties -Dkaraf.startLocalConsole=false -Dkaraf.startRemoteShell=true -classpath /usr/share/openhab2/runtime/lib/boot/org.apache.karaf.diagnostic.boot-4.2.7.jar:/usr/share/openhab2/runtime/lib/boot/org.apache.karaf.jaas.boot-4.2.7.jar:/usr/share/openhab2/runtime/lib/boot/org.apache.karaf.main-4.2.7.jar:/usr/share/openhab2/runtime/lib/boot/org.apache.karaf.specs.activator-4.2.7.jar:/usr/share/openhab2/runtime/lib/boot/osgi.core-6.0.0.jar org.apache.karaf.main.Main

The standalone Jython is 2.7.1, I have made sure /etc/openhab2/automation/jython/jython-standalone-2.7.1.jar is where it should be.

Any hint on where to look and how to debug that is appreciated.

  • Harald

It would be best if you would start your own topic for this (include some logs and double check permissions on the Jython jar), unless you read the OP and help test the Jython bundle. This may actually fix your issue too!

Fine, I have switched to the beta, so I’m on topic now. :slight_smile:

I followed this short path:

If you already have Jython setup, stop OH, remove the Jython portion of your EXTRA_JAVA_OPTS, copy the jar, and start OH. The existing core and community libraries on your filesystem will be ignored.

What I get in the logs (setting a filter on “jsr”) is this:

2020-01-17 16:09:31.954 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'js' with identifier: file:/etc/openhab2/automation/jsr223/javascript/core/000_startup_delay.js
2020-01-17 16:09:32.074 [INFO ] [jsr223.javascript.core.startup_delay] - Checking for initialized context
2020-01-17 16:09:32.121 [INFO ] [jsr223.javascript.core.startup_delay] - Context initialized... waiting 30s before allowing scripts to load
2020-01-17 16:10:02.161 [INFO ] [jsr223.javascript.core.startup_delay] - Complete
2020-01-17 16:10:02.167 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/etc/openhab2/automation/jsr223/python/core/000_startup_delay.py
2020-01-17 16:10:02.248 [INFO ] [jsr223.jython.core.startup_delay    ] - Checking for initialized context
2020-01-17 16:10:02.251 [INFO ] [jsr223.jython.core.startup_delay    ] - Context initialized... waiting 30s before allowing scripts to load
2020-01-17 16:10:32.262 [INFO ] [jsr223.jython.core.startup_delay    ] - Complete
2020-01-17 16:10:32.271 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/etc/openhab2/automation/jsr223/python/core/components/100_DirectoryTrigger.py
2020-01-17 16:10:33.568 [INFO ] [23.jython.core.DirectoryEventTrigger] - TriggerHandler added [jsr223.DirectoryTrigger]
2020-01-17 16:10:33.574 [INFO ] [23.jython.core.DirectoryEventTrigger] - TriggerType added [jsr223.DirectoryTrigger]
2020-01-17 16:10:33.577 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/etc/openhab2/automation/jsr223/python/core/components/100_OsgiEventTrigger.py
2020-01-17 16:10:34.201 [INFO ] [jsr223.jython.core.OsgiEventTrigger ] - TriggerHandler added [jsr223.OsgiEventTrigger]
2020-01-17 16:10:34.206 [INFO ] [jsr223.jython.core.OsgiEventTrigger ] - TriggerType added [jsr223.OsgiEventTrigger]
2020-01-17 16:10:34.210 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/etc/openhab2/automation/jsr223/python/core/components/100_StartupTrigger.py
2020-01-17 16:10:34.248 [INFO ] [jsr223.jython.core.StartupTrigger   ] - TriggerHandler added [jsr223.StartupTrigger]
2020-01-17 16:10:34.251 [INFO ] [jsr223.jython.core.StartupTrigger   ] - TriggerType added [jsr223.StartupTrigger]
2020-01-17 16:10:34.254 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/etc/openhab2/automation/jsr223/python/core/components/200_JythonBindingInfoProvider.py
2020-01-17 16:10:34.358 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/etc/openhab2/automation/jsr223/python/core/components/200_JythonExtensionProvider.py
2020-01-17 16:10:35.175 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/etc/openhab2/automation/jsr223/python/core/components/200_JythonItemChannelLinkProvider.py
2020-01-17 16:10:35.240 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/etc/openhab2/automation/jsr223/python/core/components/200_JythonItemProvider.py
2020-01-17 16:10:35.287 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/etc/openhab2/automation/jsr223/python/core/components/200_JythonThingProvider.py
2020-01-17 16:10:35.349 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/etc/openhab2/automation/jsr223/python/core/components/200_JythonThingTypeProvider.py
2020-01-17 16:10:35.406 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/etc/openhab2/automation/jsr223/python/core/components/200_JythonTransform.py
2020-01-17 16:10:35.596 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'js' with identifier: file:/etc/openhab2/automation/jsr223/javascript/personal/Sun.js
2020-01-17 16:10:36.498 [INFO ] [jsr223.javascript                   ] - |Sun.js: script loaded|

So this is more on Python than before. What I’m missing is that the hello_world.py file I had placed in CONF/automation/lib/Python/personal. Same for the init.py file in the same directory. Do I need to place scripts elsewhere? I will play a bit…

  • Harry

Yes… read step 12 of the installation instructions again. :wink:

More details here… File Locations — openHAB Helper Libraries documentation

Hehe, I move Hello World to automation/jsr223/python/personal/hello_world.py (instead) of automation/lib/python/personal/hello_world.py and it is working now.

  • Harald

Excellent… glad you got it working! Thank you for testing this out!

I thought I were fast. :wink:

May I ask the question why “user” scripts are buried so deep in the file structure? Why not read them directly from the “rules” directory like the old DSL stuff?

Anyway, I will start with this Python stuff now!

  • Harald

That was how it was initially implemented in OH2. I’m not sure what the rationale was, but I agree that it could be a little simpler. Changing the /automation/jsr223/ directory structure is on my list of things to do for OH 3.0.

1 Like

I’m replying over here to keep everything in one place. I have not noticed this error, but it is very possible this is due to some work I have done to get this trigger working again. This OsgiEventTrigger and DirectoryTrigger have not worked in a long while. I’m surprised that nobody else has reported it!

Did you already have the helper libraries installed? If so, have you downloaded a recent version of the core scripts?

The error will not harm anything, but you won’t be able to use this trigger, which doesn’t work anyhow. So, safe to ignore it and I’ll get it fixed.

I have not actually tested this, but I’ll take a look. You should be able to add a python.path to EXTRA_JAVA_OPTS and the bundle will append it to the path that it is adding.

Wait wait wait… something doesn’t add up. There is a push on Dec 18, but the jar is dated Dec 6. I must have not updated the jar. Gimme a sec…

I have installed the addon (the MANIFEST file states “Bundle-Version: 2.5.0.201912061703”) which is the version you just mentioned :wink:, and copied the following directories from the Helper Libraries (I only use Python):

automation/
├── jsr223
│   └── python
│       ├── community
│       ├── core
│       │   ├── 000_startup_delay.py
│       │   └── components
│       │       ├── 100_DirectoryTrigger.py
│       │       ├── 100_OsgiEventTrigger.py
│       │       ├── 100_StartupTrigger.py
│       │       ├── 200_JythonBindingInfoProvider.py
│       │       ├── 200_JythonExtensionProvider.py
│       │       ├── 200_JythonItemChannelLinkProvider.py
│       │       ├── 200_JythonItemProvider.py
│       │       ├── 200_JythonThingProvider.py
│       │       ├── 200_JythonThingTypeProvider.py
│       │       └── 200_JythonTransform.py
│       └── personal
│           ├── astro_sun_direction.py
│           ├── astro_sun_tomorrow.py
│           ├── reset_expire.py
│           ├── sensor_status.py
│           └── watchdog.py
└── lib
    └── python
        ├── configuration$py.class
        ├── configuration.py
        └── personal
            ├── __init__$py.class
            └── __init__.py

9 directories, 20 files

A question about the configuration.py file. I put global constants in there and reload the module with:

import configuration
reload(configuration)
from configuration import COUNTRY, CITY, SECRET_STUFF, ...

Is my understanding correct that I should do something like this to get an updated configuration, or will it pickup the changes automatically?

You will need to reload the module in each script that you want to see the changes.

1 Like

Testing result: I couldnt get it work (I didnt see the hello world script run every 10 seconds). Feel free to ignore my post if I’m not the tester you’re looking for (I’m a NOOB and am NOT familiar with the scripting engine, but I did follow the directions and interpreted them and concatenated what I thought I was supposed to do from the “familiar with how to setup Jython and the HLs” link - only do YOUR steps 1-5 + step 7 from that link). I’m trying to get Jython scripting to work for a feature I’m trying to implement which is how I found this post). I have: openhab ver 2.5.1-2. Is there supposed to be a new addon in PaperUI once I do this that I’m supposed to install?

My Interpreted Steps (incorrect-dont work)
  • Prerequisites:
    -openhab 2.5 (S1778) or newer
    -Stop Openhab service: sudo systemctl stop openhab2
    -Backup OH: sudo $OPENHAB_RUNTIME/bin/backup /etc/openhab2/Backup_openhab1_20200121.zip

  • Download the 2.5 jar file from https://drive.google.com/drive/u/1/folders/1Bixyq9GqUQA7bmoRW89mH3WHM5KKSjiY
    -Copy org.openhab.core.automation.module.script.scriptenginefactory.jython-2.5.0-SNAPSHOT.jar to: /etc/openhab2/addons/
    -AND- /usr/share/openhab2/addons/ (Since I don’t know what one mine uses)

  • Download https://github.com/openhab-scripters/openhab-helper-libraries/archive/master.zip
    -Copy /core/automation/jsr223/python/core/ folder -> /etc/openhab2/automation/jsr223/python/core/
    -Copy /Core/automation/lib/python/configuration.py.example -> /etc/openhab2/automation/lib/python/configuration.py

  • Copy: /Script Examples/Python/hello_world.py script -> /automation/jsr223/python/personal/

  • Start Openhab service: sudo systemctl start openhab2

Validate:

  • Start openHAB and watch the logs for errors and the entries from the Hello World script.
    -This script will make a log entry every 10s and should be deleted after installation has been verified.

Troubleshooting Steps:

  • Fix permissions: sudo openhabian-config ->10:Apply Improvements->14:Fix Permissions
  • sudo reboot
  • Uninstalled “Rule Engine (Experimental)”, rebooted, then reinstalled “Rule Engine (Experimental)”

Console Logging:

  • SSH into openhabian
  • Commands:
    sudo openhab-cli console (Connect to console)
    habopen (default password)
    log:set DEBUG org.openhab.core.automation (enable debug logging for automation
    log:set DEBUG jsr223 (Enable debug logging for jsr223)
    log:tail
    [CTRL+Z] (Exit)

No. You install the Next Gen Rules Engine add-on from PaperUI under the Misc tab (step 5 at Installation — openHAB Helper Libraries documentation) which is a prerequisite for the jar file linked to above to work. Unfortunately you need to follow a combination of the instructions there and the instructions on the OP. So you need to do:

  • Steps 1-9 at the helper library link
  • steps 1-5 in the OP
  • steps 12-15 at the helper library installation link.

Did this folder actually exist? The /usr/share… folder is the correct one I think.

All feedback is very welcome and helpful! My instructions need an update to help less technical people like yourself, but at this point feedback has been positive and I will just update the instructions in the HL repo. Based on your other posts, I see you have it working now and I will comment in those other topics.

No. This may be seen in OH 3.0 as an addon or core feature, or it may just be included as a default feature (no need to install).

I’m not sure what needs interpreting, but these instructions (and the ones in your other topic) are wrong and will confuse others (everyone please disregard these and follow the instructions in the OP!). I see you have now created another topic with instructions for installing Jython (:roll_eyes:) and I will respond more over there. Please remove these instructions.

I added a comment with the exact steps I did so you can comment on how I failed (would be hard to know what I did wrong without knowing what I did) :slight_smile: - I dont want to delete them so others can see what not to do, but I did put them inside a “hide” tag with a “doesnt work” comment for reference so it doesnt clutter the thread. I know this may be very surprising but I’m extremely technical…just not with openhab. I’ve been finding that a very common trend though: those that have been using it for years forget how complicated it truly is - but for good reason: its feature-rich! But the catch-22 is that to do 1 thing, you need to research and figure out 10 other things, this here is no exception. I needed “Interpreted steps” because I tried following the OP steps and couldn’t get it to work…tried other things, different orders, and on and on…all day. In the end I got “it” to work by only doing the steps in https://openhab-scripters.github.io/openhab-helper-libraries/Getting%20Started/Installation.html, unfortunately not this guide or jar. Also, in the end I’m not sure how this post relates to the steps in the link (I trust it does, I just don’t understand openhab enough at this point. An explanation would be great for NOOBS :slight_smile: ). I look forward to your comment in my other post, that’s exactly what I was looking for. I will update my steps there accordingly. I updated the title including “WIP”. I appreciate all the efforts, feedback, and thank you!

I found a bug and uploaded a new version where the python.path is now properly appended to any specified in EXTRA_JAVA_OPTS.

The new version also moves the cachdir to $OPENHAB_USERDATA/tmp, so it can be deleted from $OPENHAB_CONF.

I’m working on including the component scripts and logging configuration too.

1 Like