]> git.basschouten.com Git - openhab-addons.git/commitdiff
Update README.md (#12168)
authordigitlength <62958838+digitlength@users.noreply.github.com>
Sat, 5 Feb 2022 19:44:45 +0000 (19:44 +0000)
committerGitHub <noreply@github.com>
Sat, 5 Feb 2022 19:44:45 +0000 (20:44 +0100)
Added outgoing data section

bundles/org.openhab.transform.jinja/README.md

index b11e28e58bb70ce6b1b86afafa782fd85be71eaf..0f02011a3baac351af7e965cd49d26154564a775 100644 (file)
@@ -14,22 +14,52 @@ Basically on [Processing incoming data](https://www.home-assistant.io/docs/confi
 
 ## Examples
 
-### Basic Example
+### Basic Examples
+
+#### Incoming data
 
 Given the value
 
-```
+```json
 {"Time":"2019-01-05T22:45:12","AM2301":{"Temperature":4.7,"Humidity":93.7},"TempUnit":"C"}
 ```
 
 the template
 
-::: v-pre
-`{{value_json['AM2301'].Temperature}}`
-:::
+```
+{{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 an 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
+
+```json
+{"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
 
 * Wikipedia on [Jinja](https://en.wikipedia.org/wiki/Jinja_(template_engine).