Move {% raw %}

This commit is contained in:
Fabian Affolter 2018-11-11 23:37:47 +01:00
parent 586ea56edc
commit 4998875ac8
No known key found for this signature in database
GPG Key ID: E23CD2DD36A4397F

View File

@ -14,6 +14,7 @@ In Home Assistant 0.19 we introduced a new powerful feature: variables in script
The trigger data made is available during [template](/docs/configuration/templating/) rendering as the `trigger` variable. The trigger data made is available during [template](/docs/configuration/templating/) rendering as the `trigger` variable.
{% raw %}
```yaml ```yaml
# Example configuration.yaml entries # Example configuration.yaml entries
automation: automation:
@ -23,28 +24,29 @@ automation:
action: action:
service: notify.notify service: notify.notify
data_template: data_template:
message: >{% raw %} message: >
Paulus just changed from {{ trigger.from_state.state }} Paulus just changed from {{ trigger.from_state.state }}
to {{ trigger.to_state.state }}{% endraw %} to {{ trigger.to_state.state }}
automation 2: automation 2:
trigger: trigger:
platform: mqtt platform: mqtt
topic: /notify/+ topic: /notify/+
action: action:
service_template: >{% raw %} service_template: >
notify.{{ trigger.topic.split('/')[-1] }}{% endraw %} notify.{{ trigger.topic.split('/')[-1] }}
data_template: data_template:
message: {% raw %}'{{ trigger.payload }}'{% endraw %} message: '{{ trigger.payload }}'
``` ```
{% endraw %}
## {% linkable_title Important Template Rules %} ## {% linkable_title Important Template Rules %}
There are a few very important rules to remember when writing automation templates: There are a few very important rules to remember when writing automation templates:
1. You ***must*** use `data_template` in place of `data` when using templates in the `data` section of a service call. 1. You **must** use `data_template` in place of `data` when using templates in the `data` section of a service call.
1. You ***must*** use `service_template` in place of `service` when using templates in the `service` section of a service call. 1. You **must** use `service_template` in place of `service` when using templates in the `service` section of a service call.
1. You ***must*** surround single-line templates with double quotes (`"`) or single quotes (`'`). 1. You **must** surround single-line templates with double quotes (`"`) or single quotes (`'`).
1. It is advised that you prepare for undefined variables by using `if ... is not none` or the [`default` filter](http://jinja.pocoo.org/docs/dev/templates/#default), or both. 1. It is advised that you prepare for undefined variables by using `if ... is not none` or the [`default` filter](http://jinja.pocoo.org/docs/dev/templates/#default), or both.
1. It is advised that when comparing numbers, you convert the number(s) to a [`float`](http://jinja.pocoo.org/docs/dev/templates/#float) or an [`int`](http://jinja.pocoo.org/docs/dev/templates/#int) by using the respective [filter](http://jinja.pocoo.org/docs/dev/templates/#list-of-builtin-filters). 1. It is advised that when comparing numbers, you convert the number(s) to a [`float`](http://jinja.pocoo.org/docs/dev/templates/#float) or an [`int`](http://jinja.pocoo.org/docs/dev/templates/#int) by using the respective [filter](http://jinja.pocoo.org/docs/dev/templates/#list-of-builtin-filters).
1. While the [`float`](http://jinja.pocoo.org/docs/dev/templates/#float) and [`int`](http://jinja.pocoo.org/docs/dev/templates/#int) filters do allow a default fallback value if the conversion is unsuccessful, they do not provide the ability to catch undefined variables. 1. While the [`float`](http://jinja.pocoo.org/docs/dev/templates/#float) and [`int`](http://jinja.pocoo.org/docs/dev/templates/#int) filters do allow a default fallback value if the conversion is unsuccessful, they do not provide the ability to catch undefined variables.