From ba69fb63dcda8e99c9434df7854eeb4a5a55acb2 Mon Sep 17 00:00:00 2001 From: Marius <33354141+Mariusthvdb@users.noreply.github.com> Date: Mon, 19 Dec 2022 15:48:57 +0100 Subject: [PATCH] add states() example to considerations (#25289) --- source/_integrations/template.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/_integrations/template.markdown b/source/_integrations/template.markdown index 43b9ab93ea3..b6f5209a048 100644 --- a/source/_integrations/template.markdown +++ b/source/_integrations/template.markdown @@ -329,7 +329,9 @@ If the template accesses every state on the system, a rate limit of one update p ### Startup -If you are using the state of a platform that might not be available during startup, the Template Sensor may get an `unknown` state. To avoid this, use `is_state()` function in your template. For example, you would replace {% raw %}`{{ states.switch.source.state == 'on' }}`{% endraw %} with this equivalent that returns `true`/`false` and never gives an `unknown` result: +If you are using the state of a platform that might not be available during startup, the Template Sensor may get an `unknown` state. To avoid this, use the `states()` function in your template. For example, you should replace {% raw %}`{{ states.sensor.moon.state }}`{% endraw %} with this equivalent that returns the state and never results in `unknown`: {% raw %}`{{ states('sensor.moon') }}` {% endraw %}. + +The same would apply to the `is_state()` function. You should replace {% raw %}`{{ states.switch.source.state == 'on' }}`{% endraw %} with this equivalent that returns `true`/`false` and never gives an `unknown` result: {% raw %}