Did anything change recently that would have resurrected this issue?
I started getting high CPU usage recently and HA became sluggish it was almost not functional (Ok maybe it wasn’t that bad but it’s definitely below expectation).
I went thru all of my integrations and removed everything and nothing helped…until I remembered about the discussion of the “unavailable sensors” template causing issues.
So I had two sensors set up using different templates for a few months now with no issues…until recently.
After removing those two sensors everything calmed down and CPU load is back to normal.
here is a screenshot of the differences between with the templates and without. It’s pretty stark:
the first low section is with neither template active. then the 100% load is with both active. then I disabled one of them. re-enabled both. then disabled both again.
here are the templates:
sensor:
- platform: template
sensors:
unavailable_entities:
#entity_id: sensor.time
friendly_name: Unavailable Entities
unit_of_measurement: items
icon_template: >
{% if states('sensor.unavailable_entities')|int == 0 %} mdi:check-circle
{% else %} mdi:alert-circle
{% endif %}
value_template: >
{% set update = states('sensor.time') %}
{{expand(states.binary_sensor, states.sensor, states.switch, states.variable, states.media_player, states.light)|selectattr('state', 'in', ['unavailable','unknown','none'])
|reject('in', expand('group.entity_blacklist'))
|reject('eq', states.group.entity_blacklist)
|list|length}}
attribute_templates:
entities: >
{% set update = states('sensor.time') %}
{{expand(states.binary_sensor, states.sensor, states.switch, states.variable, states.media_player, states.light)|selectattr('state', 'in', ['unavailable','unknown','none'])
|reject('in', expand('group.entity_blacklist'))
|reject('eq' , states.group.entity_blacklist)
|reject('eq' , states.group.battery_status)
|map(attribute='entity_id')|list|join(', ')}}
sensors_unavailable:
friendly_name: 'Entities that need attention'
entity_id: sensor.time
value_template: >
{{ states | selectattr('state', 'in', ['unavailable', 'unknown', 'none']) | list | length }}
attribute_templates:
entities: >
{{ states | selectattr('state', 'in', ['unavailable', 'unknown', 'none']) | map(attribute='entity_id') | list | join('\n') }}
Again, did something change recently that would have caused the issue to re-appear?