Clarity updates (#6889)

Added note about testing templates in the template tool

Added section about how `|` has priority over non-bracket operators

Some minor changes to steer people towards `states.('...')` rather than `states...state`.
This commit is contained in:
DubhAd 2018-10-17 22:17:03 +01:00 committed by Fabian Affolter
parent c62b5a2586
commit b6d9b8ba5b

View File

@ -107,6 +107,18 @@ If your template uses an `entity_id` that begins with a number (example: `states
Rendering templates with time (`now()`) is dangerous as updates only trigger templates in sensors based on entity state changes. Rendering templates with time (`now()`) is dangerous as updates only trigger templates in sensors based on entity state changes.
</p> </p>
## {% linkable_title Priority of operators %}
The default priority of operators is that the filter (`|`) has priority over everything except brackets. This means that:
{% raw %}
```yaml
{{ states('sensor.temperature') | float / 10 | round(2) }}
```
{% endraw %}
Would round `10` to 2 decimal places, then divide `states('sensor.temperature')` by that.
## {% linkable_title Home Assistant template extensions %} ## {% linkable_title Home Assistant template extensions %}
In templates, besides the normal [state object methods and properties](/topics/state_object/), there are also some extra things available: In templates, besides the normal [state object methods and properties](/topics/state_object/), there are also some extra things available:
@ -115,6 +127,8 @@ In templates, besides the normal [state object methods and properties](/topics/s
## {% linkable_title Examples %} ## {% linkable_title Examples %}
To test a template, go to the <img src='/images/screenshots/developer-tool-templates-icon.png' alt='template developer tool icon' class="no-shadow" height="38" /> template developer tools, create your template in the _Template editor_ and check the results on the right.
### {% linkable_title States %} ### {% linkable_title States %}
The next two statements result in same value if state exists. The second one will result in an error if state does not exist. The next two statements result in same value if state exists. The second one will result in an error if state does not exist.
@ -133,7 +147,7 @@ Print an attribute if state is defined. Both will return the same thing but the
{% raw %} {% raw %}
```text ```text
{% if states.device_tracker.paulus %} {% if states.device_tracker.paulus %}
{{ states.device_tracker.paulus.attributes.battery }} {{ state_attr('device_tracker.paulus', 'battery') }}
{% else %} {% else %}
?? ??
{% endif %} {% endif %}
@ -170,9 +184,9 @@ Print out a list of all the sensor states.
Paulus is at {{ states('device_tracker.paulus') }}. Paulus is at {{ states('device_tracker.paulus') }}.
{% endif %} {% endif %}
{{ states.sensor.temperature | float + 1 }} {{ states('sensor.temperature') | float + 1 }}
{{ (states.sensor.temperature | float * 10) | round(2) }} {{ (states('sensor.temperature') | float * 10) | round(2) }}
{% if states('sensor.temperature') | float > 20 %} {% if states('sensor.temperature') | float > 20 %}
It is warm! It is warm!