Habbapp - migrating from jython questions

Since jython is a dying thing I’m planning on migrating my rules to HABapp. It does include a good amount of time and effort therefore I want migrate as many rules as possible without changing them or approach (the already made) solutions differently.
At first glance there are some challenges with actions, but I can work around them I think without much effort.
I do however use persistence many times with functions like “averageSince” and “updatedSince”, are there any replacements for these? AFAIK, these are not mentioned in the docs. :thinking:

HABApp is different and not a drop in replacement.
So if you want to keep your rules the same things will get quirky and probably hard.
Why don’t you keep the working rules running and start slowly experimenting with HABApp.
It won’t get in your way and you can use a mixture of both without problems.

E.g. in HABApp all items have the timestamp of the last change and last update.
So it’s just

if datetime.now() - self.my_item.last_change > timedelta(minutes=3):
   # item changed 

No need for persistence.

You can do item.get_persistence_data().average() but this will load all data from openHAB so it’s not quite the same. Depending on the average interval this might work well.
An alternative could be the AggregationItem from HABApp (again depending on the interval and data changes).

Ok, thanks. Yeah you might be right, I will have to run things mixed for a while.
But I think I’ll create a “wrapper” lib for my persistence data simulating the same functions, I think it will save me some time :crazy_face: (or be a waste of time …time will show!)

I know this is an old question, but I am also searching for the right direction to go with my python/jython rules. I have thousands of lines of python rules and I simply don’t have the time to do a complete rewrite in javascript, and honestly from what I’ve seen by looking at HABapp, which does look very nice, but it doesn’t seem nearly as clean or as easy, plus I’m a python2.7 baby.

So, my idea is to use the OpenHAB Remote Binding, and create a separate OpenHAB instance that handles only the jython/python rules. I’m working on a python script/rule that will also autogenerate or update a single items file with all the mirrored items/groups necessary channel names. I’ll continue updating both the main (which would actually be the remote) openHAB server, and the jython (which would be considered the local) OpenHAB server until such time that we find out that jython on OH4 or OH5 or whenever has died. Then I will just freeze the Jython OpenHAB server at the last working milestone for jython, and it would then bascially just be a jython rule-engine. It would have no bindings or anything else on it except what would be needed to run the jython rules and communicate with the main house OpenHAB server.

Maybe over time I could figure out python 3 and slowly bring my rules over to HABapp, but it would be a years-long process based on having to actually be a participant in the rest of life! I wish there was a OpenHAB native way to keep Jython alive, maybe this is the closest thing to it…

Imho, I don’t find python3 that different from 2.7 that it gives me any trouble or challenge at all. I did use a little time to understand how to use HabApp but when I got some rules migrated I got the hang of it and the rest was more or less just “doing” and less exploring to figure out how…

I made an extra effort now in the last couple of weeks getting all my jython files migrated or converted to HabApp and I don’t regret it for a minute. Jython seems to be a dying thing (in openhab at least) and most 3rd part libraries and modules are written for python3 nowadays. Wouldn’t it be better to use the time on a more “futureproof” solution than keeping alive something that’s probably gonna make you lots of trouble and challenges? :thinking:

1 Like

Ah, thank you so much for your opinion! Do you find that rule speed and things happening (like other lights coming on when you flip a linked switch) are as fast through HABapp as they were when jython was running within openhab?

I will begin looking into HABapp more closely and start with a few simple rules. You’re right though, it would be silly to spend time stuck in 2.7 when 3+ is the future of python.

Thank you!

Haven’t noticed any speed difference between jython and habapp at all to be honest nor have I experienced any problems related to timing or similar.
The bigges challenges in migrating have been solving the “actions” and “persistence” since HabApp is using the rest api. Actions was actually not that big of a deal, I only use mail and pushover as notifications so I just used 3rd party modules for that.
Persistence was more of a challenge since I wanted to have a drop-in replacement, so I wrote my own little influxdb library for it. I probably could have skipped this and done as Spaceman_Spiff said, take another approach on it, but for me this was the best solution. :slight_smile:

Wow, fast reply! I was wondering about notifications. I was thinking maybe I would have to send a string back through via a proxy item and have a notification happen via Javascript or something like that. I like having notifications happen through the Openhab app on my android, but maybe that is old school…

I don’t actually think I have any perstance interaction through jython now, so that may not be a big deal. But, because I like python so much I think I have built puthon dicts that sort of emulate persistence in certain cases. Probably not that efficient!

I may have more questions for you as I begin the HABapp transition. Thanks again for your help!

1 Like

Just a heads up - HABApp will support actions in one of the upcoming releases (probably end of summer). Then you can use thing actions natively.

Speed is normally very good:
Typical round trip times are ~30ms which means send a value to openhab, have openhab process it and then have openHAB send it back to HABApp and read it in HABApp again.
You can enable the ping in the HABApp config and see for yourself.

1 Like

Just a hint:
I am in the middle of porting stuff from Jython and ChatGPT is of great help.
I paid the extra 20$ for GPT4.
You can drop whole code modules and ask to port from Jython to Python.
It even explains Python3 specifics on code snippets.

Can anybody report using GPT too?

I’m not using GPT and I am not sure if it would make sense.
Transitioning from Jython to Python is imho no big issue, the hard part is to learn the HABApp internals.
Simply migrating rules from Jython to Python without using the HABApp technology will lead to quirky rules.