For example, instead of using a ‘wildcard’ like states
:
{{states|selectattr('state','in',['unavailable','unknown','none'])
|rejectattr('entity_id','in',ignore_list)
|rejectattr('entity_id','in',state_attr('group.entity_blacklist','entity_id'))
|rejectattr('domain','in',['group','media_player'])
|map(attribute='entity_id')
|list|length}}
specify the domains of the entities you actually want to monitor for state-changes:
{{expand(states.sensor, states.binary_sensor, states.light, states.switch, states.lock, states.fan)
|selectattr('state','in',['unavailable','unknown','none'])
|rejectattr('entity_id','in',ignore_list)
|rejectattr('entity_id','in',state_attr('group.entity_blacklist','entity_id'))
|map(attribute='entity_id')
|list|length}}
The eagle-eyed may have noticed that the second version no longer needs this line:
|rejectattr('domain','in',['group','media_player'])
because those domains are not listed in the first line.
EDIT
Observations:
Listeners will be created for every entity produced by the template’s first line. That means listeners will be created for the entities in ignore_list
and group.entity_blacklist
. In other words, this template will be evaluated even when one of those ignored/blacklisted entities changes state. That includes the sensor containing this template (i.e. self-referential: it is evaluated even when its own state changes).