This add-on provides support for Python 3 that can be used as a scripting language within automation rules. It is based on GraalPy from the GraalVM project.
Also included is a helper library to support automation in openHAB. It provides access to common openHAB functionality within rules including items, things, actions, logging and more.
Please note this binding is in beta stage. There is also a major known bug which may require restarting openhab after installation. If you see an exception like “Native library already loaded in another classloader”, you must restart openHAB until this exception disappears.
This bug is fixed in openhab5, but can’t be backported.
The recommended way to use, is currently only with filebased scripts in “/conf/automation/python/”. Any other usage like, scripts created in WebUI or python as a transformation service will raise the mentioned exception too. A restart will not help here. You must clean the unsupported use cases and reinstall (uninstall & install) the binding
If you want to discuss this binding or you found a bug, feel free to join the community forum thread
Quick Start
- Install this binding via marketplace
- Check your logs for an exception like “Native library already loaded in another classloader”. In this case, restart openHAB until this exception disappears
- Wait for a log message like “Deploy helper libs into…” which means the helper lib is initialized
- Put your scripts into “/conf/automation/python/” and your modules into “/conf/automation/python/lib/”.
README and Documentation
Please refer to the helper library README.md for detailed information about the usage.
Help Wanted
Please don’t be afraid to create PRs, refactor code, add documentation
Ressources
Last published Date
Last Update: 25.03.3035 18:14
Changelog
Version 25.03.3035 18:14
- move helper libs from private repo to openhab repo
- fix script unload/cleanup
- update to graalpy 24.2.0 (version for openhab5 is using osgiified graalvm)
- simplified createTimer implementation
- helperlib fix to support upcomming graalpy 24.2.0
- code cleanups and refactorings based on feedback and code reviews
Version 24.02.2025 18:06
- script context cleanup/close fix for compiled scripts (e.g. transformation scripts)
- log prefix for UI based and transformation scripts fixed
- logging cleanup and simplification
Version 23.02.2025 20:57
- add scope, Registry and logger auto injected for UI based rules
Version 23.02.2025 12:02
- added scope object and import wrapper
- for details check here
- added IntervalCondition to triggers
- cleanup and minor helper lib api changes
- cleanup and simplification of helper lib deployment (no hardcoded filenames anymore)
- use OSGI-ified version of polyglot in openhab 5 (this fixes openhab/openhab-addons#18054 in openhab >= 5)
- migrate openhab helper lib into his own repository
- This makes it easier to decouple release cycles between openhab and helper lib
Version 06.02.2025 07:30
- fixed memory leak on rule reloading (old script engine is properly closed)
- fixed tranformation service ‘PY3’
- fixed log prefix
- fixed lifecycleTracker
- cleanups
Version 03.02.2025 17:34
- fixed postUpdate, postUpdateIfDifferent, sendCommand and sendCommandIfDifferent for openhab value types like UP/DOWN etc)
Version 03.02.2025 08:30
- code cleanup of internal trigger validation
- various helper lib code cleanups
- added Registry.setItemMetadata and Registry.removeItemMetadata
- improved README.md
Version 02.02.2025 20:26
- Fixed “Run Now” - UI in 4.3+
Version 27.01.2025 08:58
- rule decorator for functions in addition to classes to allow much simpler rules
- allow import of script modules in addition to lib modules
- fixes for WebUI based rules (currently still not working because of another major bug)
- internal graal binding cleanups and simplifications
- cleanups in triggers helper module
Version 23.01.2025 12:08
- added “when” and “onlyif” decorator support
- Item.getPersistance renamed to Item.getPersistence
- fixed TimeOfDayTrigger and DateTimeTrigger
Version 22.01.2025 10:58
- initial release