how odd, template sensor using custom_templates:
- unique_id: alerts_notifying
state: >
{% from 'alerts.jinja' import alerts %}
{{alerts|count}}
name: >
{% from 'alerts.jinja' import alerts %}
{% set count = alerts|length %}
{% set phrase = 'Alert' if count == 1 else 'Alerts' %}
{{count}} {{phrase}} actief
icon: >
{% from 'alerts.jinja' import alerts %}
{% set count = alerts|length %}
mdi:numeric-{{count}}-box
returns 0 on all counts, while dev tools template
{% from 'alerts.jinja' import alerts %}
{{alerts}}
{{alerts|count}}
clearly shows thats not the case…
|count
or |length
dont make a difference in this case as can be seen
I moved to import that custom_template, because I had this expand:
state: >
{% set alerts = state_attr('binary_sensor.alerts','entity_id') %}
{{expand(alerts)
|selectattr('state','eq','on')|map(attribute='entity_id')|list|count}}
in all options before, and figured that might be more efficient (expanding only once, and then import)
this is my alerts.jinja
file:
{% set alerts = expand(state_attr('binary_sensor.alerts','entity_id'))
|selectattr('state','eq','on')|map(attribute='name')|list %}
{% set hubs_offline = expand(state_attr('group.hub_device_trackers','entity_id'))
|selectattr('state','eq','not_home')|list %}
{% set critical_off = expand('switch.critical_switches')
|selectattr('state','eq','off')|list %}
what’s more, when pasting the full template config in the dev tools, it clearly shows its correct…
so no wondering if this import is behind somehow, or what could it be?
thanks for having a look