Hi,
I started with nearly the first available openhab version (0.x) in 2012/2013. The rules was written in Java. With changing to the openhab version 2 I was very happy, because of using python many thinks was really easy… functions could be imported and used in different rules, variable names could be changed dynamically.
But now I wanted to change to version 4 and it seems that python isn’t supported any more.
I hope that is a misunderstanding from my side. Please, please, correct me if I’m wrong.
If not, what is the preferred, powerful language to use, if I don’t want to change for the next openhab versions?
All my python files, have 10677 lines of code. I would be happy to reuse them.
thanks a lot for your feedback. The hope is rising again
I added to my addons.cfg
automation = jythonscripting
And after restart I can see that it’s installed
But then I got the error message
Error during evaluation of script ‘/etc/openhab/automation/jython/python/personal/wetter.py’: ImportError: No module named core in /etc/openhab/automation/jython/python/personal/wetter.py at line number 1
My script starts like this
from core.rules import rule
from core.triggers import when
import math
from datetime import datetime
from org.joda.time import DateTime
from org.joda.time import Days
from core.actions import PersistenceExtensions
from core.date import to_python_datetime #https://community.openhab.org/t/jython-elapsed-time-millis-and-joda-time-functions/81570
from org.eclipse.smarthome.model.script.actions.Exec import executeCommandLine
from core.actions import HTTP
import json
import subprocess
# für Test folgende 2 Zeilen aktivieren
#import personal.mylib
#reload(personal.mylib)
from personal.mylib import fncZeicheTabelle
Do I need to replace the core or did I missed something?
I guess you are using the helper libraries which are not working anymore, because the openhab api changed a lot in the meantime and there is no one who maintains this library anymore.
I took over the maintainer role of python scripting binding and I will rewrite/create a new helper library based on my own learning during the last years. It will be based on my own helper script, but cleaned and simpler.
For now, you can use only the openhab/python core api without the helper library.
thanks for jumping in.
What does that mean for my openhab4 installation? Can I use rules like…
@rule("Fenster wird geschlossen")
@when("Item EG_Kind3_FensterKontakt_FensterOffen changed to CLOSED")
@when("Item EG_Garderobe_FensterKontakt_FensterOffen changed to CLOSED")
@when("Item EG_Wohn_FensterKontakt_TuerTerrasseOffen changed to CLOSED")
@when("Item EG_Kueche_FensterKontakt_TuerReOffen changed to CLOSED")
@when("Item EG_Kueche_FensterKontakt_TuerLiOffen changed to CLOSED")
@when("Item EG_WC_FensterKontakt_FensterOffen changed to CLOSED")
@when("Item OG_Bad_FensterKontakt_FensterOffen changed to CLOSED")
@when("Item OG_Kind1re_FensterKontakt_FensterEckOffen changed to CLOSED")
@when("Item OG_Kind1re_FensterKontakt_BalkonTuerOffen changed to CLOSED")
@when("Item OG_Kind2li_FensterKontakt_FensterEckOffen changed to CLOSED")
@when("Item OG_Kind2li_FensterKontakt_BalkonTuerOffen changed to CLOSED")
@when("Item OG_Buero_FensterKontakt_FensterOffen changed to CLOSED")
@when("Item OG_Schlaf_FensterKontakt_FensterLangReOffen changed to CLOSED")
@when("Item OG_Schlaf_FensterKontakt_FensterHochLiOffen changed to CLOSED")
@when("Item OG_AnkleideFensterKontakt_FensterOffen changed to CLOSED")
def rFensterWirdGeschlossen(event):
rFensterWirdGeschlossen.log.warn(u"Das {} wurde geschlossen".format(event.itemName))
for rollladen in lutRolJalMitFenster:
# welches Fensterkontakt gehört zum Fenster
if lutRolJalMitFenster[rollladen][lutRolJalMitFensterKontakt] == event.itemName:
# gibt es etwas zu tun?
# holen den letzten Treffer in der Liste
# loesche gespeicherte Werte
restorePosIfPossible(rFensterWirdGeschlossen.log, rollladen, rmAll=True)
try:
tFensterOffen[event.itemName].cancel()
del tFensterOffen[event.itemName]
rFensterWirdGeschlossen.log.error(u"Timer fuer Fensterkonakt {} wurde geloescht".format(event.itemName))
except:
pass
# Treffer es kann abgebrochen werden
break
If yes, how can I use/install your helper scripts to my openhab4 installation?
for now, I do not official support my helper libraries. They are just for people who like to explore and provide technical feedback.
During the next months (maybe September/October) I will provide a first official preview of my rewritten helper libraries in an external git project. Preview means the api is not final and complete and the target group are early adapters who wants to influence the final version.
When the new helper libraries are becoming stable, I will merge and include them in the official openhab release.
If you want to explore my helper libs, just clone and copy the files from github to $OPENHAB_CONF/automation/jython/lib/shared
and import them with
from shared.helper import rule, getItemState, sendCommand
from shared.triggers import CronTrigger, ItemStateChangeTrigger
but keep in mind the final version will be different.
btw. the main motivation for rewriting the helper libraries is to remove the complexity. I will only implement features to cover ~95% of use cases. This will reduce the code size a lot and will decrease the maintenance effort for the future. The rest has to be done by accessing the openhab api directly, which is still possible, because every openhab api is available in jython.
Ultimately you are going to have to rewrite your rules to work in OH 4. Not to be glib, but that’s the cost that comes with not upgrading more frequently.
If you want to keep using Python you have two choices.
Use HABApp which runs separately from and in parallel to openHAB, interacting with OH through the REST API. It’s very powerful, offers Python 3 (Jython currently only offers the long since end of life Python 2 which still leaves me uncomfortable) and has a following. But it’s an independent implementation of rules so your existing rules will largely need to be rewritten.
Use the Jython automation which I would label as experimental at this point given it doesn’t have a completed helper library yet. And since the helper library is a rewrite, you’ll have to rewrite your rules accordingly.
Outside of Python you have a number of choices. Since you have to largely rewrite anyway they are worth a review.
Blockly: great if you are not already a programmer, maintainers are very active
JS Scripting: probably the most popular language right now, Blockly “compiles” into JS Scripting, the maintainers are very active
jRuby: very powerful and complete with a vibrant community of users, maintainers are very active
Rules DSL: I don’t recommend new development in Rules DSL; all the other options are better, support for new (and even some old) features is lagging behind
Groovy: has a following but lacks good documentation, I think it uses the raw Java APIs so it doesn’t really need much active development.
Thanks Holger,
I will try if after the summer break.
Then I will try your helper libs from github, knowing that it’s still on work.
Lot’s of thanks for your help and project work!