diff --git a/source/_includes/integrations/using_templates.md b/source/_includes/integrations/using_templates.md new file mode 100644 index 00000000000..a4ec8c33ef5 --- /dev/null +++ b/source/_includes/integrations/using_templates.md @@ -0,0 +1,21 @@ +### Using templates + +For incoming data, a value template translates incoming JSON or raw data to a valid payload. +Incoming payloads are rendered with possible JSON values, so when rendering, the `value_json` can be used to access the attributes in a JSON based payload, otherwise the `value` variable can be used for non-json based data. + +Additional, the `this` can be used as variables in the template. The `this` attribute refers to the current [entity state](/docs/configuration/state_object) of the entity. +Further information about `this` variable can be found in the [template documentation](/integrations/template/#template-and-action-variables) + +{% note %} + +**Example value template with json:** + +With given payload: + +```json +{ "state": "ON", "temperature": 21.902 } +``` + +Template {% raw %}`{{ value_json.temperature | round(1) }}`{% endraw %} renders to `21.9`. + +{% endnote %} \ No newline at end of file diff --git a/source/_integrations/binary_sensor.rest.markdown b/source/_integrations/binary_sensor.rest.markdown index 27ea8469bb5..3c38f7a0f7f 100644 --- a/source/_integrations/binary_sensor.rest.markdown +++ b/source/_integrations/binary_sensor.rest.markdown @@ -151,6 +151,8 @@ params: type: [list, template] {% endconfiguration %} +{% include integrations/using_templates.md %} + ## Examples In this section you find some real-life examples of how to use this sensor. diff --git a/source/_integrations/command_line.markdown b/source/_integrations/command_line.markdown index b2875629ab0..2bf9e7f01e8 100644 --- a/source/_integrations/command_line.markdown +++ b/source/_integrations/command_line.markdown @@ -296,6 +296,8 @@ While `command` is accepting a template for `sensor` and `binary_sensor`, it's o {% endnote %} +{% include integrations/using_templates.md %} + ## Binary sensor To use your Command binary sensor in your installation, add the following to your {% term "`configuration.yaml`" %} file: diff --git a/source/_integrations/notify.rest.markdown b/source/_integrations/notify.rest.markdown index 39b7cb445a2..f88ff4827f1 100644 --- a/source/_integrations/notify.rest.markdown +++ b/source/_integrations/notify.rest.markdown @@ -80,3 +80,5 @@ data: {% endconfiguration %} To use notifications, please see the [getting started with automation page](/getting-started/automation/). + +{% include integrations/using_templates.md %} diff --git a/source/_integrations/rest.markdown b/source/_integrations/rest.markdown index 416253f78a6..5767809d4c0 100644 --- a/source/_integrations/rest.markdown +++ b/source/_integrations/rest.markdown @@ -189,3 +189,6 @@ binary_sensor: {% important %} Use either `resource` or `resource_template`. {% endimportant %} + + +{% include integrations/using_templates.md %} diff --git a/source/_integrations/scrape.markdown b/source/_integrations/scrape.markdown index 6dc49f142f5..d8a38008830 100644 --- a/source/_integrations/scrape.markdown +++ b/source/_integrations/scrape.markdown @@ -160,6 +160,8 @@ sensor: default: None {% endconfiguration %} +{% include integrations/using_templates.md %} + ## Examples In this section you find some real-life examples of how to use this sensor. There is also a [Jupyter notebook](https://nbviewer.jupyter.org/github/home-assistant/home-assistant-notebooks/blob/master/other/web-scraping.ipynb) available for this example to give you a bit more insight. diff --git a/source/_integrations/sensor.rest.markdown b/source/_integrations/sensor.rest.markdown index 94a9c6108a4..59952b54f20 100644 --- a/source/_integrations/sensor.rest.markdown +++ b/source/_integrations/sensor.rest.markdown @@ -164,6 +164,8 @@ $ curl -X GET http://192.168.1.31/temperature/ The response is expected to be a dictionary or a list with a dictionary as its 0th element. +{% include integrations/using_templates.md %} + ## Examples In this section you find some real-life examples of how to use this sensor. diff --git a/source/_integrations/snmp.markdown b/source/_integrations/snmp.markdown index 0c5a4a5e1d1..f3c91e57bc5 100644 --- a/source/_integrations/snmp.markdown +++ b/source/_integrations/snmp.markdown @@ -24,6 +24,9 @@ There is currently support for the following device types within Home Assistant: - [Presence detection](#presence-detection) - [Sensor](#sensor) + - [Finding OIDs](#finding-oids) + - [Examples](#examples) + - [Printer uptime minutes](#printer-uptime-minutes) - [Switch](#switch) {% important %} @@ -102,6 +105,8 @@ priv_key: See the [device tracker integration page](/integrations/device_tracker/) for instructions how to configure the people to be tracked. +{% include integrations/using_templates.md %} + ## Sensor The `snmp` sensor platform displays information available through the [Simple Network Management Protocol (SNMP)](https://en.wikipedia.org/wiki/Simple_Network_Management_Protocol). SNMP uses a tree-like hierarchy where each node is an object, and is mainly supported by network-oriented devices such as routers, modems and printers. diff --git a/source/_integrations/sql.markdown b/source/_integrations/sql.markdown index b2dea2735e5..a5d76797b88 100644 --- a/source/_integrations/sql.markdown +++ b/source/_integrations/sql.markdown @@ -130,6 +130,8 @@ There is no explicit configuration required for attributes. The integration will Note that in all cases only the first row returned will be used. +{% include integrations/using_templates.md %} + ## Examples In this section, you find some real-life examples of how to use this sensor. diff --git a/source/_integrations/switch.rest.markdown b/source/_integrations/switch.rest.markdown index fc16207d8a4..79c422324a4 100644 --- a/source/_integrations/switch.rest.markdown +++ b/source/_integrations/switch.rest.markdown @@ -102,6 +102,8 @@ verify_ssl: Make sure that the URL matches exactly your endpoint or resource. {% endimportant %} +{% include integrations/using_templates.md %} + ## Example ### Switch with templated value