Migrating my rules to Jython

Tags: #<Tag:0x00007f8321710fb0> #<Tag:0x00007f8321710e48>


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