mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-23 01:06:52 +00:00
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:
parent
c62b5a2586
commit
b6d9b8ba5b
@ -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.
|
||||
</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 %}
|
||||
|
||||
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 %}
|
||||
|
||||
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 %}
|
||||
|
||||
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 %}
|
||||
```text
|
||||
{% if states.device_tracker.paulus %}
|
||||
{{ states.device_tracker.paulus.attributes.battery }}
|
||||
{{ state_attr('device_tracker.paulus', 'battery') }}
|
||||
{% else %}
|
||||
??
|
||||
{% endif %}
|
||||
@ -170,9 +184,9 @@ Print out a list of all the sensor states.
|
||||
Paulus is at {{ states('device_tracker.paulus') }}.
|
||||
{% 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 %}
|
||||
It is warm!
|
||||
|
Loading…
x
Reference in New Issue
Block a user