From 26a1714b1a9d8aff0a6b8b5382df4c701a3f5a54 Mon Sep 17 00:00:00 2001 From: Petro31 <35082313+Petro31@users.noreply.github.com> Date: Mon, 10 Jan 2022 07:01:52 -0500 Subject: [PATCH] Add is_number test (#21110) --- .../_docs/configuration/templating.markdown | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/source/_docs/configuration/templating.markdown b/source/_docs/configuration/templating.markdown index 60eed9e7316..4e69c06e69e 100644 --- a/source/_docs/configuration/templating.markdown +++ b/source/_docs/configuration/templating.markdown @@ -208,6 +208,28 @@ The same thing can also be expressed as a filter: {% endraw %} +{% raw %} + +```text +{% for energy in expand('group.energy_sensors') if is_number(energy.state) %} + {{ energy.state }} + {%- if not loop.last %}, {% endif -%} +{% endfor %} +``` + +{% endraw %} + +The same thing can also be expressed as a test: + +{% raw %} + +```text +{{ expand('group.energy_sensors') + | selectattr("state", 'is_number') | join(', ') }} +``` + +{% endraw %} + ### Devices - `device_entities(device_id)` returns a list of entities that are associated with a given device ID. Can also be used as a filter.