The rest is more or less a direct forwarded Java API.
The advantages are significantly reduced maintenance effort, 100% access to openHAB core APIs, and the availability of new openHAB APIs without modifying the Python API.
For most use cases, the Pythonscripting API and the scope objects are perfectly sufficient. Experienced users can jump deeper into the openHAB Java API.
Pythonscripting focuses on people who want a āpureā access to openHAB functionality, without large abstraction layers. Oh, and you should like Python for things like that
I changed my opinion and implemented venv handling a few days after I wrote this answer. So venv setups is working since 4 month.
Yes, graalvm 25.0.0 is the version I was talking about. But I have not observed any major change. Except a python specific config which is now obsolete. Maybe this version is the base for more venv cleanups and simplifications.
Anyway. Venv setups can be used since 4 month with the latest marketplace version or with openHAB 5.1
Does this mean that it is already possible to setup several VEnvs inside a rule without logging into openHAB console? How can the VEnv be selected for each rule?
This limitation isnāt due to GraalVM. Itās more a lack of support in openHAB core. Currently, thereās no way to manage these kinds of settings for individual rules. Furthermore, various aspects of rule initialization would need to be reworked. All of this lies outside the scope of pythonscripting and is therefore not currently my focus.
My statement referred to general Venv support. Initially, I wanted to wait for the next major GraalVM release. However, after experimenting a bit, Iāve implemented it now.
I would like to write something like a Rule Binding.
The idea is to install the CarConnectivity Python API with a rule into a Venv. Then use another time triggered rule which calls the CarConnectivity CLI and copys the CLI results to Openhab items. I also donāt want to use MQTT.
These are the steps which need to be done manually on console to setup the Venv. I would like to do this in a rule.
first of all thanks to you @holger_hees for investing so much into the Python 3 binding. Finding this was a Christmas present I have a number of Jython rules that I want to migrate and see this as my way forward⦠And to finally upgrade to a recent Openhab version by doing so.
My rules need additional modules installed (e.g. requests). From what I understand, I need to setup a graalpy-based venv to support additional modules with the Python 3 binding (Python Scripting - Automation | openHAB).
Now I have the question how the upgrade process works with respect to the Python 3 binding. So e.g. from 5.1 to 5.2 in some months. From what I understand, bindings are linked to the Openhab version. So there will be a new binding version delivered with 5.2. For Python3, likely this will also include a new GraalPy version (looks like ~ every 2 months there is a new Graalpy version).
Iām running on docker. In my current setup, I have a dockerfile that installs Jython and the modules needed into the recent image. This allowed to upgrade by re-building the image and run Openhab with the upgraded image.
Looking at the installation process of the Python 3 binding, I assume the following process:
Fire up Openhab with the newer image but the existing configuration, userdata, etc.
Openhab automatically installs the latest Python3 bindung
Graalpy venv, as located in userdata, will have survived and be on a older version than the Python 3 binding
Graalpy itself will not exist anymore, as it was installed in the previous container itself (/opt/graalpy)
I need to connect a terminal to the running container and i) install the latest Graalpy version, ii) re-install venv and iii) re-install the required modules
Is my assumption correct / any suggestions?
Could the upgrade of Graalpy and the venv be moved into a dockerfile? If I could manually set the venv path (to something not under userdata), this would already allow doing so.
@Fuzzy Yes. Your assumptions are correct. Currently, a venv setup is tied to the correct graalvm version. This means, it must be re-initialized with each openhab release, if it contains a new graalvm version.
In your case, you could simply mount or symlink another venv directory in userdata.
I known that none of this is ideal. But I think it will be improved on the Graalvm side in the future. At least the Graal developers have once mentioned that they are not yet satisfied.
On openhab side, I may include a check that shows a warning when venv is enabled, but does not fit the openhab graalvm version. Furthermore, I will display the Venv Graalvm version in the pyhonscripting infos provided by openhab cli. There was only recently a user who also stumbled across it.
I myself also faced the problem that I used the requests module in jython. However, I was able to map all use cases using http action and currently do not use venv.
Firstly, thank you @holger_hees for this binding. Some years ago I used the old Jython binding but when it seemed to become unsupported I reluctantly went back to DSL. When 5.1 was released recently I spun up a test server and have been migrating my rules to the new Python3 binding and itās much nicer.
I saw that back in July that someone asked about the ability to turn off or filter the āRule executed in ā¦ā log messages, but after going through this thread I couldnāt see any update. I too am finding them quite noisy and would like to filter them out so just wondering if there is any update on this?
Hi, I am new python and have just managed to install the Python3 binding and have my first rule transfered from rules DSL and working. How do I select the correct interpreter in VScode? Keep getting the message āselect interpreterā.
Canāt find an answer on this, can you point me in the correct direction?
Iām not a Visual Studio Code user myself, but Iāll try to help.
First, you donāt need a Python interpreter to edit Python code. This means itās something additional to Visual Studio Code and not related to openHABās python scripting.
My guess is that it has something to do with syntax highlighting, and you can select the Python version being used, or your locally installed Python, which Visual Studio has detected. OpenHAB uses Python 3.12.8, by the way.
This can easily be found out using the OpenHAB CLI with the command pythonscripting info.
If you want to learn more about Visual Studio Code and Python, this might help you.
Thank you for your quick respons, went thru the link you mentioned and that was very helpfull, Iām now a few steps further and just found out that I have installed a wrong the graalPy version, (installed the AMD64 one as per instructions but am running on a RPI so had to install the aarch64. (Had an error message but apperantly I missed that yesterday.) Thanks for your help .