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

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

Sorry for the stupid question, but if this post requires most of the steps from the “standard install method” in the other link, then what is the difference? I see there is an additional jar - but is this supposed to be an easier way to install it, or add functionality? Or neither, were testing the jar itself in order to get this into PaperUI? Thanks!

Brilliant! I wish I had seen this before I tried doing a first-time installation. :roll_eyes:

Good thing I have a backup, which I can restore and start over. :wink:

All of the Python stuff is bundled into the jar file so you don’t have to download and install it from Jython directly. The command line flags to pass to openHAB to make it work is also done for you.

Easier way to install it.

Technically, you don’t need step 2 because openHAB is already shutdown in step 6 of the helper library installation.

And, shouldn’t steps 1 and 3 be moved to the helper library instructions? Step 1 would then become step 0, and step 3 would be inserted after step 6.

Also, I find this part of step 4 is confusing. Am I’m supposed to do this before step 5? Where do I copy these from?

Scott is referring to the core directory in the helper libraries zip to be copied from Core/automation/jsr223/python/core to /conf/automation/jsr223/python/core. This is what should be copied in there:

├── 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

Note that the script 100_OsgiEventTrigger.py currently gives an error in the log, but it is a known issue.