If you ask yourself if you should use OpenHab’s “native” Rules DSL language to write your rules, you are in luck, because here’s the only and definitive answer.
I’ve switched yesterday to jsr223/Jython - after writing about 10 rule files in OH’s “native” rule language (Rules DSL / Xtend), which then became unreliable to load & work. After hours I found out that the variable name “ruleName” is causing problems. Wow.
Fixed, moved on, wrote most of the things I need, worked some days. Now again problems: I have to re-save .items and .rules after OH starts, to make rules work (undefined items, non-running rules). There’s no clear pattern, maybe file names are also in issue.
Some rules work, some not. Searched the forum - other people with similar problems, and at best, Voodoo-fixes. It’s just broken stuff. And foreseeable that I will lose more and more time with this, and will not get a rock solid home automation. I cannot always fear “Is everything really running?”, and do babysitting…
So I decided to bite the python , before the Rules DSL bites me again. I have never used Python before.
Some time ago, out of curiosity, I had a look into the JavaScript Nashorn language ref, and the Python ref, and I liked the Python’s features, and the code more. Good bye curly bracket nonsense. {{{}}} They have undoubtedly been invented to allow developers to release more hot-bugfix releases, with clear release notes like “This update allows you to use our app more easily”.
Python’s code semantic is also not perfect, as it requires proper indentation, but it’s a lot less cluttered than curly bracket code.
(A simple “end” would solve so many problems in both languages)
Apart from that, the last Nashorn has already died, and to me it looks that JavaScript (and Groovy) may become less attention in OH’s future than Python. It could be riding a dead horse, it seems to me.
Also Python is more attractive to me since it can be used to program the Raspberry Pi, but honestly I will likely not find the time in this live to play with that…
So, Python:
In one day I had installed jsr223 / Jython, wrote some helper functions for logging, timer use, etc, and converted two rather tiny rules to Python. Not that bad.
Coding in Python is not really harder than in the Rules DSL.
And Functions, waahhhh! You only know WHAT a killer-feature that is if you don’t have them (in Rules DSL).
The key to make it to jsr223/Jython were for me the good and clear instructions I found (much too late), after some irritating link hopping from the OH jsr223 page, to github and what not.
Click here!
Installation — openHAB Helper Libraries documentation
Click now!
Or at least today!
Last chance!
Click and win! It’s almost serious!
I really should have do (find) THAT from the beginning, and if you read this and ask yourself what rule language you should begin with: JSR223 and Python!
This is the truth, the only valid and possible answer - everything else is completely wrong, even if stated in a reply otherwise. Be wise and do it, and also don’t forget to elect me as your next president - you will not regret, I promise!
(Error: This post reached the maximum count of smileys.)