What's the deal with Python rules in OpenHab 3?

The instructions for installing the Helper Library include a a step to create automation/lib/python/configuration.py. You skipped that step. Which instructions for installation did you follow?

Also note, if using the Helper Libraries, and especially if you will be creating and maintaining configurations for lots of instances, why create the rules through the UI in the first place?

I may have shown the import incorrectly. I haven’t used Python for a few months. Maybe it needs to be

from java.time include ZonedDateTime

It’s nothing specific to OH. Look up how imports work in Python and do that.

Python support is what it is in OH right now.

So why change? Rules DSL and. rules files are still supported the same as they ever where. You don’t have to use any other language. You don’t have to use the UI. You can continue on as you always have.

For Python you’ve already done it.

from core.log import logging, LOG_PREFIX

Note that this syntax is defined by Python, not openHAB.

For JavaScript see OH 3 Examples: Writing and using JavaScript Libraries in MainUI created Rules

For Rules DSL you are out of luck.

The docs are the way they are because no one has volunteered to write them better. Id write some myself and it’s on my to-do list but I’ve even more people bitching about the docs for Pages than I do for Rules. And frankly, a lot of the problems are caused by people who have run with Rules DSL rules for years suddenly deciding they absolutely must rewrite everything in a language they are unfamiliar with in a way they are unfamiliar with despite the fact that all the knowledge and work they already have with. rules files are still valid and still work.

The Helper Libraries are not a part of the openHAB project itself. Unless and until it becomes so, it will have it’s own documentation. I can’t fix that.

Python and JavaScript and Groovy all have their own syntax and ways of doing things like importing libraries, iterating lists, etc. I can’t fix that either. One would presume, and perhaps it needs to be said, that the OH docs are not going to teach you how to program in theses languages. They will cover how to interact with OH 3 stuff but not fundamentals to the language.

2 Likes