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

I had assumed you read the manual installation instructions to get the libraries installed

1 Like


Step 8 is the one that has you create (or to be more specific rename) the configuration.py file.

Very well then. Good luck!

Firstup a primer. Look for the Just tell me already!! title down below if you already know all this.

Openhab has included a python rule engine into its UI in OH3. This means you can write and interact with your own python scripts inside the web interface rules section. When you’re building a rule in the UI, one of the options for Then will be Python scripting.

At this point the Python rule engine uses Python version 2.7, so once setup, you’re basically just exploiting your Python 2.7 skillz. How cool :slight_smile:

To get setup, Openhab 3 Python in the UI is very nearly ready to go, but there’s a few parts missing.

To be fair, the Python engine is there in its entirety, so you can write Python code, but there are very few available libraries available to you.

You can absolutely reinvent the wheel yourself and get things happening, but the more common practice is to include standard Helper Libraries that do a lot of the work for you. Certainly whenever you ask someone “How do I…?” they will reference libraries and the functions therein rather than breaking down the code in those libraries.

But fear not, while Openhab 3 doesn’t yet have a bundled set of libraries to work with, some of our diligent community members have picked up the slack.

Just tell me already!!

@5iver has upgraded the old OH2.5 Jython libraries and @JimT has made them available as a Pull Request.

You can find the package here: https://openhab-scripters.github.io/openhab-helper-libraries

And the instructions for installing are here: https://openhab-scripters.github.io/openhab-helper-libraries/Getting Started/Installation.html (The link to the latest package version for download is in Step: 7)

(Actually, I haven’t followed the full list. I found out about all this in non sequential increments so I was desperately just trying to patch. See below for a breakdown of what I did and didn’t do)

Once you’ve got them in, you’ll need to know what the libraries contain and how to use their functions, you can read into that here: https://docs.python.org/2.7/

You’ll also need to know how to access OpenHab components from within your code. Item states for example. You’ll find a nice primer on this here: https://openhab-scripters.github.io/openhab-helper-libraries/Guides/But How Do I.html#get-the-state-of-an-item

I can’t guarantee this is all perfect, but as a noob, I discovered what I detailed above and managed to get a Python scripts working from the UI.

So this exact process worked for me?

I actually didn’t follow the full list from the Jython Libraries Instalation Instructions. I found out about all this in non sequential increments so my process was actually:

  • Install Python Add-on in: UI -> Settings -> Add-ons -> Automation + Jython Scripting

  • Download and extract … you know what, I listed all this in another reply, go look at that if you must know. Its the long one with heaps of code references.

  • Work through the install guide, skipping the bits I didn’t think I had to do

    1. skip
    2. I did this but didn’t have to. It did answer a question in my mind about logging though.
    3. See 2
    4. Skip, come back to it if I need to
    5. Didn’t think I’d need as I already have a Python interface in the UI
    6. Skip. Can do a restart later
    7. Did this. It is a newer version the the other one I downloaded.
    8. Did this, only did /automation/lib/python/, couldn’t locate another configuration.py.example to rename
    9. Did this
    10. Skipped. Thought I might have to come.back to it, but have been assured it is already taken care of in OH3 by the add-on.
    11. See 10
    12. instead of doing this, recreated the same conditions in UI. Basically, you just want to write to the log file every 10 seconds
    13. did a service openhab restart because of not having shut it down in step 6
    14. Not a real step. I think it was included to stop there being just 13 steps. That would be unlucky and invite problems :wink:
    15. see 14

Any Questions?

1 Like

That can’t seriously be your take away from all this. If I were you and i wanted to focus on one shared idea, I’d look at the one that lightens my workload.

Have a look at my reply above.

If you agree, and no one else objects, I’ll mark it as the solution.

1 Like

You have been flying to extremes in this thread and implied that Rich is not doing the right work. Rich is the most helpful user on this forum as far as I’m concerned. He has written countless how to’s and answers maybe half of all the topics opened on here by himself. There is no team for him to delegate to, everything about openHAB is volunteer based, everyone contributes what they can when they can.

That said, your above write-up is excellent, thank you for making such a concise and accurate reference. Steps #10 and 11 can be skipped entirely on OH3, the new add-on takes care of those internally.


You said I wasn’t being helpful. If I’m not being helpful and “silently cursed” for my efforts I will spend my time elsewhere. Doing anything else would be a waste of both of our time.

Frankly, once you said that I stopped reading and have moved on. I don’t have an infinite amount of time and can’t afford to waste it being unhelpful.

1 Like

Hello to all and good evening,

I ended in this thread coming from Jython helper libraries for OH3

After migrating and setting up jython in OH3 I keep getting this entry in the logs at every start-up:

2021-01-29 22:26:37.804 [INFO ] [ab.core.service.AbstractWatchService] - ScriptEngine for py not available
2021-01-29 22:26:37.805 [INFO ] [ab.core.service.AbstractWatchService] - ScriptEngine for py not available
2021-01-29 22:26:37.806 [INFO ] [ab.core.service.AbstractWatchService] - ScriptEngine for py not available
2021-01-29 22:26:37.811 [INFO ] [ab.core.service.AbstractWatchService] - ScriptEngine for py not available
2021-01-29 22:26:37.819 [INFO ] [ab.core.service.AbstractWatchService] - ScriptEngine for py not available
2021-01-29 22:26:37.821 [INFO ] [ab.core.service.AbstractWatchService] - ScriptEngine for py not available
2021-01-29 22:26:37.821 [INFO ] [ab.core.service.AbstractWatchService] - ScriptEngine for py not available
2021-01-29 22:26:37.824 [INFO ] [ab.core.service.AbstractWatchService] - ScriptEngine for py not available
2021-01-29 22:26:37.824 [INFO ] [ab.core.service.AbstractWatchService] - ScriptEngine for py not available
2021-01-29 22:26:37.828 [INFO ] [ab.core.service.AbstractWatchService] - ScriptEngine for py not available
2021-01-29 22:26:37.828 [INFO ] [ab.core.service.AbstractWatchService] - ScriptEngine for py not available
2021-01-29 22:26:37.832 [INFO ] [ab.core.service.AbstractWatchService] - ScriptEngine for py not available

Could someone help me how to get this sorted?

Thanks for all your help.

Best regards

Hello again,

I only now saw this thread marked as solved so I thought it would be better to post on the other thread.

Sorry and thanks again.

Best regards.

1 Like

You need to install the Python addon.

@rjduraocosta @rlkoshak this seems to happen on startup no matter what. Seems the Python Script Engine is not ready when the File Watcher scans the files. Once the Python SE is ready it will load all the Python files.

1 Like