This weekend, I did a long deferred and overdue update from 2.x to 4.1.1. I came across this thread because I’m also using file based Jython scripts and had exactly the same error as described in the title.
TL;DR: Everything is still working like a charm, with only minimal modifications!
But first of all: you guys are amazing! The developers as well as the ones giving support here are doing such a great and ambitioned job that I cannot find in 95% of commercial software.
Let me try to wrap it up:
- I’m on a ‘normal’ Debian, no Raspbian, Openhabian or whatsoever. So my installation is .deb-based
- I did a manual backup of all necessary files as well as the database, because I was pretty sure that a simple update over two major versions won’t do (and even if I had been confident, it’s always a good idea to have a backup)
- I have a wild mixture of file and JSON-DB based things and items, some simple DSL based rules, many complex Jython rules with a few system calls, and single JS-based transformations
So my first attempt was a naive update via apt install openhab
- expecting that I have to repair it over the next days and weeks, maybe install a new version from scratch.
And: wow! I was so wrong about it: first thing I saw after the update was that nearly all things and items were still available, sitemaps in my OpenHab app were working, I was really happy.
I also appreciate that the Jython scripting is now an official add-on and I could remove my experimental jython-standalone configuration. Really great so far! But unfortunately, my Jython rules did not work. I have to admit it was painful and I spent a few hours to find out the reasons, but here is what I did:
I recognized that my OpenHab JSR223 helper libraries were out of date, so I followed the instructions here to install them for OH3 compatibility:
One fatal error I made: since I’m only using Jython rules, I just updated the Jython related helper scripts, not the JS helper scripts! This leads to a situation where the 000_Startup.py
script is loaded, but not any other core or personal script.
The reason is most probably that there is an old script 000_startup_delay.js
that blocks the whole JSR223 script loading literally forever, because it is waiting for a condition that never becomes true. Made me crazy, because depending on the timing during restart, sometimes single scripts that I renamed to 000_*.py
were loaded, but most of the time they were not.
As soon as I recognized this and also updated the other helper scripts (JS and groovy, both mostly empty), I finally made quick progress.
I could not overcome the actual error about the 100_DirectoryTrigger.py
. Like @rlkoshak already pointed out: the whole watchdog internals seem to have changed in OH3/4, so without someone updating the helper scripts I guess you don’t have a chance to get this working again.
But it turned out: I can safely ignore this error (or just remove the respective file from the core
directory) - at least for my rules. I don’t exactly see what this script does for you anyway - modifications to my scripts are still watched and applied without a restart. And I don’t use custom directory triggers in my rules.
The only real changes I had to do in my Jython scripts were:
- Get rid of
org.joda.time
imports - Replace the logger calls with something appropriate (I decided to use the from
org.slf4j import LoggerFactory
from the sample scripts, with logger names beginning withorg.openhab.core.automation
)
That’s it! All my rules are working again!
I defined many custom rule classes with sophisticated item and cron triggers, timer invocations and even semaphores / thread locking mechanisms - and they just work!
In my understanding, as long as future JVMs support JSR223, it is totally clear that Jython scripts works, because the Java runtime doesn’t really care about the actual scripting language that you use. It is only the helper scripts that become outdated - but even them are only to help you save some code, they are not mandatory to work with the API. You can always write and maintain your own helper libraries.
For now, despite the still broken 000_DirectoryTrigger.py
, you can perfectly use it for OH4. That’s my point for today, for anyone who stumbles across this thread looking for help to get their Jython scripts up and running again.