openhab-addons/bundles/org.openhab.transform.jinja
Holger Friedrich 6e49c6e6ec
[transform] Code optimization for Java17: instanceof matching and multiline strings (#15483)
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
2023-08-24 06:41:36 +02:00
..
src [transform] Code optimization for Java17: instanceof matching and multiline strings (#15483) 2023-08-24 06:41:36 +02:00
NOTICE added migrated 2.x add-ons 2020-09-21 03:37:19 +02:00
pom.xml Apply spotless 2023-07-24 01:20:31 +02:00
README.md Fix Markdown warnings in README.md (#14187) 2023-01-09 17:51:12 +01:00

Jinja Transformation Service

Transforms a value using a jinja template.

The main purpose of this transformer is the use in the home assistant discovery. Therfore not all features of the home assistant templating are supported. Basically on Processing incoming data

Available variables

Variable Description
value The incoming value.
value_json The incoming value parsed as JSON.

Examples

Basic Examples

Incoming data

Given the value

{"Time":"2019-01-05T22:45:12","AM2301":{"Temperature":4.7,"Humidity":93.7},"TempUnit":"C"}

the template

{{value_json['AM2301'].Temperature}}`

extracts the string 4.7.

Outgoing data

The JINJA transformation can be used to publish simple JSON strings through, for example, the HTTP Binding's commandTransformation parameter.

Say we have a String Item which holds the following value:

This is my string

Adding the following into the commandTransformation parameter of your HTTP Thing Channel

JINJA:{"msgtype":"m.text", "body":"{{value}}"}

will send the following string out of openHAB

{"msgtype":"m.text", "body":"This is my string"}

{{value}} will be replaced by whatever the value of your Item is.

Note that if using *.things files you must escape quotation marks, for example:

commandTransformation = "JINJA:{\"msgtype\":\"m.text\", \"body\":\"{{value}}\"}"

Further Reading