@@ -59,21 +59,21 @@ script:
59
59
60
60
Home Assistant adds extensions to allow templates to access all of the current states:
61
61
62
- - Iterating ` states` will yield each state sorted alphabetically by entity ID.
63
- - Iterating `states.domain` will yield each state of that domain sorted alphabetically by entity ID.
64
- - ` states.sensor.temperature` returns the state object for `sensor.temperature`.
65
- - ` states('device_tracker.paulus')` will return the state string (not the object) of the given entity or `unknown` if it doesn't exist.
66
- - ` is_state('device_tracker.paulus', 'home')` will test if the given entity is specified state.
67
- - ` is_state_attr('device_tracker.paulus', 'battery', 40)` will test if the given entity is specified state.
68
- - Filter `multiply(x)` will convert the input to a number and multiply it with `x`.
69
- - Filter `round(x)` will convert the input to a number and round it to `x` decimals.
70
- - ` now` will be rendered as current time in your time zone.
71
- - ` utcnow` will be rendered as UTC time.
72
- - ` as_timestamp` will convert datetime object or string to UNIX timestamp
73
- - ` distance()` will measure the distance in meters between home, entity, coordinates.
74
- - ` closest()` will find the closest entity.
75
- - ` relative_time(timestamp)` will format the date time as relative time vs now (ie 7 seconds)
76
-
62
+ - Iterating ` states` will yield each state sorted alphabetically by entity ID.
63
+ - Iterating `states.domain` will yield each state of that domain sorted alphabetically by entity ID.
64
+ - ` states.sensor.temperature` returns the state object for `sensor.temperature`.
65
+ - ` states('device_tracker.paulus')` will return the state string (not the object) of the given entity or `unknown` if it doesn't exist.
66
+ - ` is_state('device_tracker.paulus', 'home')` will test if the given entity is specified state.
67
+ - ` is_state_attr('device_tracker.paulus', 'battery', 40)` will test if the given entity is specified state.
68
+ - Filter `multiply(x)` will convert the input to a number and multiply it with `x`.
69
+ - Filter `round(x)` will convert the input to a number and round it to `x` decimals.
70
+ - ` now` will be rendered as current time in your time zone.
71
+ - ` utcnow` will be rendered as UTC time.
72
+ - ` as_timestamp` will convert datetime object or string to UNIX timestamp
73
+ - ` distance()` will measure the distance in meters between home, entity, coordinates.
74
+ - ` closest()` will find the closest entity.
75
+ - ` relative_time(timestamp)` will format the date time as relative time vs now (ie 7 seconds)
76
+ - ` float ` will format the output as float.
77
77
78
78
# # {% linkable_title Examples %}
79
79
@@ -93,9 +93,9 @@ Print an attribute if state is defined
93
93
` ` ` jinja2
94
94
{% raw %}
95
95
{% if states.device_tracker.paulus %}
96
- {{ states.device_tracker.paulus.attributes.battery }}
96
+ {{ states.device_tracker.paulus.attributes.battery }}
97
97
{% else %}
98
- ??
98
+ ??
99
99
{% endif %}{% endraw %}
100
100
` ` `
101
101
@@ -119,7 +119,12 @@ Print out a list of all the sensor states.
119
119
120
120
{% if states('sensor.temperature') | float > 20 %}
121
121
It is warm!
122
- {%endif %}{% endraw %}
122
+ {%endif %}
123
+
124
+ {{ as_timestamp(states.binary_sensor.garage_door.last_changed) }}
125
+
126
+ {{ as_timestamp(now) - as_timestamp(states.binary_sensor.garage_door.last_changed) }}
127
+ {% endraw %}
123
128
` ` `
124
129
125
130
# ## {% linkable_title Distance examples %}
@@ -183,4 +188,11 @@ It depends per component or platform but it is common to be able to define a tem
183
188
184
189
# Extract third prime number
185
190
{% raw %}{{ value_json.primes[2] }}{% endraw %}
191
+
192
+ # Format output
193
+ {% raw %}{{ "%+.1f" | value_json }}{% endraw %}
194
+
195
+ # Calculations
196
+ {% raw %}{{ value_json | multiply(1024) }}{% endraw %}
197
+ {% raw %}{{ value_json.used | multiply(0.0001) | round(0) }}{% endraw %}
186
198
` ` `
0 commit comments