From b6d9b8ba5b976d1dd36baa15ba92cbd2acfbcfe8 Mon Sep 17 00:00:00 2001
From: DubhAd
Date: Wed, 17 Oct 2018 22:17:03 +0100
Subject: [PATCH] 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`.
---
.../_docs/configuration/templating.markdown | 20 ++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/source/_docs/configuration/templating.markdown b/source/_docs/configuration/templating.markdown
index b1c3fa06491..7e11dae2ec0 100644
--- a/source/_docs/configuration/templating.markdown
+++ b/source/_docs/configuration/templating.markdown
@@ -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.
+## {% 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
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!