This package creates a group of entities that have no value (a state of unknown or unavailable) and a sensor that provides a count of the entities in this group.
The sensor can be used to help you discover entities which should to be disabled or deleted and help you identify misbehaving or failed devices.
The structure for this sensor has changed from the original version. You can read about the changes here.
Home Assistant v2024.8 is the minimum version required to use this package.
The auto-entities and fold-entity-row plugins is required to use the example lovelace card.
The fold-entity-row plugins is required to use the example lovelace card.
The easiest way to use this sensor is to install it as a package.
If you already have packages enabled in your configuration, download package_unavailable_entities.yaml
to your packages directory.
To enable packages in your configuation, create a folder in your config directory named packages
and add the following line to your configuration.yaml
file.
homeassistant:
packages: !include_dir_named packages
To create this sensor without using packages simply copy the relevant code to an appropriate place in your configuration.yaml file. The example notification automation is optional.
NOTE! You must reload automations, templates, and group entities after adding this package!
You will likely have many devices and/or entities which you do not need to monitor or that often have states of unknown or unavailable. These devices and entities can be excluded from the sensor. Excluding a device excludes all of it's entities.
Disabled devices and entities and devices and entities labeled ignored
in the UI are excluded from the sensor by default. To use a different label name, change the ignore_label
value in the group template to the desired value. The label is not case sensitive. This is the recommended way to exclude entities.
In addition to excluding entities using labels in the UI, entities can also be excluded with additional filters in the template, or by adding them to the group.ignored_entities
definition.
Domains that are "stateless" (button, scene, event etc) or that don't make sense to monitor are excluded by default. To monitor these domains remove them from the ignored domains filter.
Example - remove the input_button
domain.
|rejectattr('domain', 'in', ['button', 'event', 'group', 'input_text', 'scene'])
If you wish to ignore additional domains you can also add them to the ignored domains filter.
Example - add the switch
domain.
|rejectattr('domain', 'in', ['button', 'event', 'group', 'input_button', 'input_text', 'scene', 'switch'])
To ignore specific entities, add them to the group.ignored_unavailable_entities
declaration.
Search Test
If you have multiple entities to ignore that share a common uniquly identifiable portion of their entity_id name you can exclude them without having to add each individual sensor to the ingore_entities group by adding filters using a search test to the template.
|rejectattr('entity_id', 'search', 'wifi_')
Be as specific as possible in your filters so you don't exclude unintended entities! For example, if you have the following sensors in your configuration and just want to exclude just the wifi signal strengh sensors, rejecting a search of 'wifi_' will also exclude binary_sensor.wifi_connected
.
- binary_sensor.wifi_connected
- sensor.wifi_downstairs
- sensor.wifi_upstairs
You can also use regex pattern matching in a seach rejectattr (selectattr) filter.
|rejectattr('entity_id', 'search', '(_alarm_volume|_next_alarm|_alarms)')
The filter above effectively combines these three filters.
|rejectattr('entity_id', 'search', '_alarm_volume')
|rejectattr('entity_id', 'search', '_next_alarm')
|rejectattr('entity_id', 'search', '_alarms')
Contains Test
The contains test can also be used if required. Regex matching is not available for the contains test.
|rejectattr('entity_id', 'contains', 'wifi_')
You can exclude entities from a specific integration by using an in
test for the entity_id and the integration_entities() function.
|rejectattr('entity_id', 'in',integration_entities('hassio'))
You can exclude entities from a specific integration by using an in
test for the entity_id and the device_entities() function.
|rejectattr('entity_id', 'in',device_entities('fffe8e4c87c68ee60e0ae84c295676ce'))
automation:
~~~
action:
- action: group.set
data:
object_id: unavailable_entities
entities: >
{% set ignore_seconds = 60 %}
{% set ignore_label = 'ignored' %}
{% set ignored_domains = ['button', 'conversation', 'event', 'group', 'image',
'input_button', 'input_text', 'remote', 'tts', 'scene', 'stt', 'update'] %}
{% set ignore_ts = (now().timestamp() - ignore_seconds)|as_datetime %}
{% set disabled_device_entities = state_attr('sensor.disabled_device_entities', 'entities')
| regex_replace(find='\[|\]|\{|\}|\'entity_id\':', replace='') %}
{% set ignored_devices = label_devices(ignore_label | lower) %}
{% set ignored_device_entities = namespace(value=[]) %}
{% for device in ignored_devices %}
{% set ignored_device_entities.value = ignored_device_entities.value + device_entities(device) %}
{% endfor %}
{{ states
| rejectattr('domain', 'in', ignored_domains)
| rejectattr('entity_id', 'in', disabled_device_entities)
| rejectattr('entity_id', 'in', state_attr('group.ignored_entities', 'entity_id'))
| rejectattr('entity_id', 'in', ['group.unavailable_entities', 'group.ignored_entities'])
| rejectattr('entity_id', 'in', ignored_device_entities.value)
| rejectattr('entity_id', 'in', label_entities(ignore_label | lower))
| rejectattr('last_changed', 'ge', ignore_ts)
| rejectattr('entity_id', 'search', 'browser_')
| rejectattr('entity_id', 'search', '_alarm_volume|_next_alarm|_alarms')
| rejectattr('entity_id', 'contains', '_memory_percent')
| rejectattr('entity_id', 'in', integration_entities('hassio'))
| rejectattr('entity_id', 'in', device_entities('fffe8e4c87c68ee60e0ae84c295676ce'))
| selectattr('state', 'in', ['unknown', 'unavailable'])
| map(attribute='entity_id') | list | sort }}
See Home Assistant Templating for additional options.
You can configure the sensor to only monitor entities you specify instead of monitoring all entities and specifing the entities to ignore by using select or selectattr filters instead of reject and rejectattr filters. Remember, filters are cumlative and entities may be already excluded by previous filters.
This is useful to create sensors that monitor specific domains, integrations etc. You can create as many groups and related sensors as you need. The following example monitors only the sensor
domain from the Shelly integration that contain the string _power
in the entity_id.
template:
- sensor:
- name: "Unavailable Shelly Power Entities"
unique_id: unavailable_shelly_power_entities
icon: "{{ iif(states(this.entity_id)|int(-1) > 0, 'mdi:alert-circle', 'mdi:check-circle') }}"
state_class: measurement
state: >
{% set entities = state_attr('group.unavailable_shelly_power_entities', 'entity_id') %}
{{ entities | count if entities != none else -1 }}
automation:
~~~
action:
- action: group.set
data:
object_id: unavailable_shelly_power_entities
entities: >
{{ states.sensor
| selectattr('entity_id', 'in', integration_entities('shelly'))
| selectattr('entity_id', 'contains', '_power')
| selectattr('state', 'in', ['unknown', 'unavailable'])
| map(attribute='entity_id') | list | sort }}
There is an example automation provided in the package that will display unavailable entities as a persistent notification. You can change this automation to meet your requirements. This automation is enabled by default. You can comment it out or delete it if not required. See the examples folder for more automations.
To display a list of unavailable entities open the more-info dialogue of group.unavailable_entities.
Using the auto-entities and fold-entity-row plugins is an excellent way to display your unavailable entities sensor in your UI.
Closed Fold Entity Row
Open Fold Entity Row