This performs a selective merge of the current docs into the "stable" branch that will hold the default docs for the 3.0.2 release (until they're replaced with the current ones once 3.1 is released). * Backport bindings docs that looked applicable to 3.0 * Revert UI components changes not in stable Signed-off-by: Yannick Schaus <github@schaus.net> Co-authored-by: openHAB Build Server <infrastructure@openhab.org> Co-authored-by: stefan-hoehn <stefan.hoehn@aoe.com> Co-authored-by: jimtng <2554958+jimtng@users.noreply.github.com> Co-authored-by: Matt <lawrence.matt@gmail.com> Co-authored-by: Jerome Luckenbach <github@luckenba.ch> Co-authored-by: Kai Kreuzer <kai@openhab.org> Co-authored-by: Felix Schneider <45742226+Trysupe@users.noreply.github.com> Co-authored-by: Hilbrand Bouwkamp <hilbrand@h72.nl> Co-authored-by: J-N-K <J-N-K@users.noreply.github.com> Co-authored-by: Eiko Wagenknecht <eiko.wagenknecht@web.de> Co-authored-by: Alexander Behring <github.com@alexander-behring.eu> Co-authored-by: Matthew Skinner <matt@pcmus.com> Co-authored-by: Christoph Weitkamp <github@christophweitkamp.de> Co-authored-by: Patrick Fink <mail@pfink.de> Co-authored-by: Gifford47 <49484063+Gifford47@users.noreply.github.com> Co-authored-by: Seganku <seganku@users.noreply.github.com> Co-authored-by: digitlength <62958838+digitlength@users.noreply.github.com> Co-authored-by: Ross Kennedy <rossko@culzean.clara.co.uk> Co-authored-by: Fabian Wolter <github@fabian-wolter.de> Co-authored-by: Arjan Mels <43108771+arjanmels@users.noreply.github.com> Co-authored-by: Jonathan Gilbert <github.10.jgilbert@xoxy.net> Co-authored-by: Richard Koshak <rkoshak@users.noreply.github.com> Co-authored-by: Wolfgang Schueschen <76775650+WolfgangSn@users.noreply.github.com> Co-authored-by: Gareth Western <gareth@garethwestern.com> Co-authored-by: Bob A <bobadair@users.noreply.github.com> Co-authored-by: Sami Salonen <ssalonen@gmail.com> Co-authored-by: Peter Schraffl <p.schraffl@gmx.at> Co-authored-by: Georgios Moutsos <50378548+jossuar@users.noreply.github.com> Co-authored-by: Markus Storm <markus.storm@gmx.net> Co-authored-by: JensHoRi <47488279+JensHoRi@users.noreply.github.com> Co-authored-by: Felix <24674809+fex01@users.noreply.github.com> Co-authored-by: Koen Schockaert <54985218+QbusKoen@users.noreply.github.com> Co-authored-by: Ethan Dye <mrtops03@gmail.com> Co-authored-by: Senne Croughs <38940112+sencro@users.noreply.github.com> Co-authored-by: Ben Clark <ben@benjyc.uk> Co-authored-by: Sam Spencer <43712250+samsp99@users.noreply.github.com> Co-authored-by: chingon007 <76529461+chingon007@users.noreply.github.com> Co-authored-by: Wouter Born <github@maindrain.net> Co-authored-by: mueller-ma <mueller-ma@users.noreply.github.com> Co-authored-by: aurelio1 <aurelio@caliaro.net> Co-authored-by: Bernd Weymann <bernd.weymann@gmail.com> Co-authored-by: Martin Hogg <hoggm2@hotmail.co.uk> |
||
---|---|---|
.. | ||
readme.md |
readme.md
id | label | title | type | description | since | install |
---|---|---|---|---|---|---|
jythonscripting | Jython Scripting | Jython Scripting - Automation | automation | This add-on provides [Jython](https://www.jython.org/) 2.7.2 that can be used as a scripting language within automation rules and which eliminates the need to download Jython and create `EXTRA_JAVA_OPTS` entries for `bootclasspath`, `python.home` and `python.path`. | 3x | auto |
{% include base.html %}
Jython Scripting
This add-on provides Jython 2.7.2 that can be used as a scripting language within automation rules and which eliminates the need to download Jython and create EXTRA_JAVA_OPTS
entries for bootclasspath
, python.home
and python.path
.
The python.home
system property is set to the path of the add-on.
The python.path
system property is set to $OPENHAB_CONF/automation/lib/python
, but any existing python.path
will be appended to it.
Creating Jython Scripts
When this add-on is installed, you can select Jython as a scripting language when creating a script action within the rule editor of the UI.
Alternatively, you can create scripts in the automation/jsr223
configuration directory.
If you create an empty file called test.py
, you will see a log line with information similar to:
... [INFO ] [.a.m.s.r.i.l.ScriptFileWatcher:150 ] - Loading script 'test.py'
To enable debug logging, use the console logging commands to enable debug logging for the automation functionality:
log:set DEBUG org.openhab.core.automation
Script Examples
Jython scripts provide access to almost all the functionality in an openHAB runtime environment.
As a simple example, the following script logs "Hello, World!".
Note that print
will usually not work since the output has no terminal to display the text.
The openHAB server uses the SLF4J library for logging.
from org.slf4j import LoggerFactory
LoggerFactory.getLogger("org.openhab.core.automation.examples").info("Hello world!")
Jython can import Java classes.
Depending on the openHAB logging configuration, you may need to prefix logger names with org.openhab.core.automation
for them to show up in the log file (or you modify the logging configuration).
::: tip Note
Be careful with using wildcards when importing Java packages (e.g., import org.slf4j.*
).
This will work in some cases, but it might not work in some situations.
It is best to use explicit imports with Java packages.
For more details, see the Jython documentation on
Java package scanning.
:::
The script uses the LoggerFactory to obtain a named logger and then logs a message like:
... [INFO ] [.openhab.core.automation.examples:-2 ] - Hello world!