Migrating my rules to Jython

Tags: #<Tag:0x00007f616f5ebbe0> #<Tag:0x00007f616f5eb870>

I use mariadb and have not been able to reproduce this. It would help if you could distill it down to the simplest form.

I will try to set up a test scene. Anyway can I somehow update the RuleEngine? I saw that it will be available as a bundle soon, how could I migrate to that?
I still have the manually installed version…

Once it is available, you’ll just need to reverse the steps in the installation… shutdown OH, remove the lines from EXTRA_JAVA_OPTS, remove /automation/lib/python/core and /automation/lib/python/community, restart OH, and install the addons. Currently, I’ve separated the libraries, so there will be two addons, if everything is accepted… one for Jython and one for the helper libraries. I’ll be getting these out for beta testing soon, but I want to include the component scripts too.

Also I still have this problem and I don’t know how can I debug this either.
I have tried setting up the simplest test case.

Calling the PersistanceExtension service once to get an average of an item for the last 5 min and printing it to the log.
With one of my items, I always get None. The others work as it should, it prints the average of the last 5 min.
So it looks like there is no persisted data available. However when looking at a chart, there is, for example openHAB draws the chart for this item as well…


Well just for the record: I moved to influxdb, because I had other problems with mysql as well (like Grafana graphing was not correct) and this problem is also gone.
However I can’t say what was wrong with mysql…

1 Like

Hello to all,

Sorry to step in, I don’t know if this is the right place or I should create a new topic, but here it goes. I have set up a test system with the helpers library and manual installation, for starting the journey to migrate all my rules to jython and I noticed the following:

  • I have a test rule that fire when a member of group received a command, all is working good except when I change the items file and add/delete a member of that specific group the rule does not fire/fires respectively. It does not behave acordingly to the new items definitions unless I change the rule, insert a comment etc., and save the rule so that it loads again.

Is this normal behavior or am missing some step in the setup procedure of jython and the helpers library?

Thanks for all you support and help.

This is normal behavior. As it was explained to me, Member of triggers get converted to separate triggers for each Item when the .py file is loaded. When you change the Group membership you need to reload the .py file in order to recreate the rule triggers that reflect the changes Group membership.

In Rules DSL, this reloading appears to happen automatically for you.

Thanks @rlkoshak for your prompt reply and always superb support.

I recently explained this behavior here…

And yes… please start a new topic. This one is already filled up with a lot of information and it is hard to search through it all.

Thanks @5iver for pointing me the direction to that post. I did not find it.

Next time I will do so. It makes perfect sense.

1 Like

I happened across another issue that made me think of your problem. You’re probably not going to troubleshoot it further if you’re happy using a different db for persistence, but did you check the timezone?

Well, when debugging the Grafana graphs, I had an intention that the timestamps are not matching in influx and mysql, because mysql timestamps seemed not unix timestamps, but I did not find any info on this or any explanation…

1 Like

Can I somehow import Python packages to Rule files properly?

I have tried it like this:

from core.rules import rule
from core.triggers import when
from core.actions import Transformation
from core.actions import Exec

from org.joda.time import DateTime

import sys
sys.path.insert(1, "/etc/openhab2/scripts/pyawair/pyawair")

from pyawair.auth import AwairAuth
from pyawair.data import *
from pyawair.objects import *

But I always get a some kind of error (which I can’t really understand where it comes from):

ImportError: No module named requests in <script> at line number 12

Line number 12 is from pyawair.data import *
I mean I know that the imported thing has an import for requests, but that one is installed on the server, so I don’t know how I could install it so that the bundled python interpreter could access it…

If I remove that one I get:

SyntaxError: mismatched input ':' expecting RPAREN in /etc/openhab2/scripts/pyawair/pyawair/objects.py at line number 13 at column number 34

Line 13 is: from pyawair.objects import *
So it seems like some package issue but I don’t know what is the real problem. It would make my setup much cleaner if I could use them like this and I don’t have to call these scripts with the Exec lib…

How did you install your modules?

Through CLI with pip

And to which folder? Jython should find the files. the pip command should simmilar to the following

pip install --target=d:\somewhere\other\than\the\default package_name

Ok thanks! And the target should be which folder? Where the jython path is set like:


That is the right path in your Dpython path.

Thanks for your help, it seems that the package problem is gone.

Now I get again this:

SyntaxError: mismatched input ':' expecting RPAREN in /etc/openhab2/scripts/pyawair/pyawair/objects.py at line number 13 at column number 34

Which is I think it is because Python3 syntax is used in these files.
So I assume that the Jython engine is based on Python 2.7?

Yes that’s true only Python 2.7

1 Like