From 12b4363a50c6ec5f041a1a75b8cd90673ebecb28 Mon Sep 17 00:00:00 2001 From: jugla <59493499+jugla@users.noreply.github.com> Date: Mon, 9 May 2022 13:09:44 +0200 Subject: [PATCH] add unavailable status with an example (#22607) --- source/_docs/configuration/templating.markdown | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/_docs/configuration/templating.markdown b/source/_docs/configuration/templating.markdown index 7d72fd79f3f..c8c15ef65b6 100644 --- a/source/_docs/configuration/templating.markdown +++ b/source/_docs/configuration/templating.markdown @@ -72,7 +72,7 @@ Not supported in [limited templates](#limited-templates). - Iterating `states` will yield each state sorted alphabetically by entity ID. - Iterating `states.domain` will yield each state of that domain sorted alphabetically by entity ID. - `states.sensor.temperature` returns the state object for `sensor.temperature` (avoid when possible, see note below). -- `states('device_tracker.paulus')` will return the state string (not the object) of the given entity or `unknown` if it doesn't exist. +- `states('device_tracker.paulus')` will return the state string (not the object) of the given entity, `unknown` if it doesn't exist, `unavailable` if the object exists but is not yet available. - `is_state('device_tracker.paulus', 'home')` will test if the given entity is the specified state. - `state_attr('device_tracker.paulus', 'battery')` will return the value of the attribute or None if it doesn't exist. - `is_state_attr('device_tracker.paulus', 'battery', 40)` will test if the given entity attribute is the specified state (in this case, a numeric value). Note that the attribute can be `None` and you want to check if it is `None`, you need to use `state_attr('sensor.my_sensor', 'attr') == None`. @@ -119,6 +119,10 @@ Other state examples: Paulus is at {{ states('device_tracker.paulus') }}. {% endif %} +#check sensor.train_departure_time state +{% if states('sensor.train_departure_time') in ("unavailable", "unknown") %} + {{ ... }} + {% set state = states('sensor.temperature') %}{{ state | float + 1 if is_number(state) else "invalid temperature" }} {% set state = states('sensor.temperature') %}{{ (state | float * 10) | round(2) if is_number(state)}}