Thanks so much! Now it works like a charm.
For others reading and wanting the same thing:
The sensor:
unavailable:
friendly_name: 'Sensors that need attention'
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') }}
…and the automation that updates the sensor:
alias: "System - Refresh sensor.unavailable"
trigger:
platform: time_pattern
minutes: '/1'
action:
service: homeassistant.update_entity
data:
entity_id: sensor.unavailable