I am trying to calculate number of entities which have “unavailable” state:
template:
- sensor:
- name: strange_unavailables
icon: mdi:null
state_class: measurement
state: >-
{% set COUNT = states | rejectattr('domain','eq','update')
| rejectattr('entity_id','search','strange_unavailables')
| selectattr('state','eq','unavailable')
| list | count -%}
{{ COUNT }}
Sometimes I am getting this warning:
2023-04-20 04:19:16.405 WARNING (MainThread) [homeassistant.helpers.template_entity] Template loop detected while processing event: <Event state_changed[L]: entity_id=sensor.strange_unavailables, old_state=<state sensor.strange_unavailables=59; state_class=measurement, icon=mdi:null, friendly_name=strange_unavailables @ 2023-04-20T04:17:09.645658+03:00>, new_state=<state sensor.strange_unavailables=57; state_class=measurement, icon=mdi:null, friendly_name=strange_unavailables @ 2023-04-20T04:18:09.662040+03:00>>, skipping template render for Template[{% set COUNT = states | rejectattr(‘domain’,‘eq’,‘update’)
| rejectattr(‘entity_id’,‘search’,‘strange_unavailables’)
| selectattr(‘state’,‘eq’,‘unavailable’)
| list | count -%}
{{ COUNT }}]
Looks like when calculating a value, the “sensor.strange_unavailables” is somehow involved.
Can anyone tell me how can I improve my template to avoid these warnings?
Also, may be this warning comes from enumerating “states” - regardless of presence of “rejectattr('entity_id','search','strange_unavailables')
”.
Since this is a “warning” and a corr. value seems to be defined properly - surely I may not care about this warning. But I wonder is it possible to get rid of it… (do not advise me to filter it in logger)