sure;
type: custom:vertical-stack-in-card
cards:
- type: entities
title: Entities Unavailable
show_header_toggle: false
style:
.: |
"#states > div:nth-child(n+1) > fold-entity-row":
$:
"#head > entity-row-maker > hui-section-row":
$: |
div.divider {
height: 0px;
}
div.label {
font-weight: bold;
}
entities:
- sensor.entities_uun
- sensor.entities_unavailable
- entity: script.update_entities_uun
secondary_info: last-triggered
- type: divider
- entity: automation.dismiss_unavailable_notification
secondary_info: last-triggered
- entity: automation.unavailable_notification
secondary_info: last-triggered
- entity: automation.check_for_unavailable_entities
secondary_info: last-triggered
- type: custom:fold-entity-row
head:
type: section
label: Unknown entities
entities:
- type: custom:hui-markdown-card
content: |
{{ state_attr('sensor.entities_uun','Unknown')}}
- type: custom:fold-entity-row
head:
type: section
label: Unknown sensors
entities:
- type: custom:hui-markdown-card
content: |
{{ state_attr('sensor.entities_uun','Unknown sensors')}}
- type: custom:fold-entity-row
head:
type: section
label: 'Unavailable'
entities:
- type: custom:hui-markdown-card
content: |
{{ state_attr('sensor.entities_uun','Unavailable')}}
- type: custom:fold-entity-row
head:
type: section
label: 'None'
entities:
- type: custom:hui-markdown-card
content: |
{{ state_attr('sensor.entities_uun','None')}}
- type: custom:fold-entity-row
head:
type: section
label: 'Full list unfiltered'
entities:
- type: custom:hui-markdown-card
content: |
{{ state_attr('sensor.entities_uun','Full')}}
you might need some extra code …:
##########################################################################################
# Package package_unavailable_entities.yaml
# @mariusthvdb
##########################################################################################
homeassistant:
customize:
sensor.entities_uun:
templates:
icon_color: >
if (state > 0) return 'red';
return 'green';
sensor.entities_unavailable:
templates:
icon_color: >
if (state > 0) return 'red';
return 'green';
script.update_entities_uun:
icon: mdi:update
##########################################################################################
# Groups
##########################################################################################
group:
# for use in sensor.entities_uun, to be filled when opportunity and need arise
entity_blacklist:
entities:
- binary_sensor.updater
- customizer.customizer
- sensor.synology_dsm_average_disk_temp_volume_1
- sensor.totaal_actueel_sensors
- sensor.tradfri_7e182152044001a2_65663
- sensor.dark_sky_precip
- sensor.brussel_noord_essen
- sensor.essen_brussel_noord
- sensor.hue_dimmer_switch_1
- sensor.hue_dimmer_switch_2
- sensor.solaredge_current_power
- sensor.solaredge_last_updatetime
- sensor.solaredge_lastday_energy
- sensor.solaredge_lastmonth_energy
- sensor.solaredge_lastyear_energy
- sensor.solaredge_lifetime_energy
##########################################################################################
# Sensors
##########################################################################################
sensor:
# https://gist.github.com/jazzyisj/45fce29d825b8f9b29c5974444299d90
# https://community.home-assistant.io/t/sensor-unavailable-offline-detection/147618/10
# https://community.home-assistant.io/t/how-to-list-all-sensors-with-state-unavailable-none-or-unknown/154606
- platform: template
sensors:
entities_unavailable:
entity_id:
- script.update_entities_uun
- automation.check_for_unavailable_entities
friendly_name: Entities Unavailable
value_template: >
{% set ignore_list = ['light.driveway','light.garden_backyard','light.garden_terrace',
'light.porch_outdoors','light.parking_light'] if
is_state('binary_sensor.outside_daylight_sensor','on') else [] %}
{% set unavailable = states|selectattr('state','eq','unavailable')
|rejectattr('entity_id','in',state_attr('group.entity_blacklist','entity_id'))
|rejectattr('entity_id','in',ignore_list)
|rejectattr('domain','eq','media_player')
|map(attribute='entity_id')
|list %}
{{ unavailable|count }}
icon_template: >
{% if states('sensor.entities_unavailable')|int > 0 %} mdi:thumb-down
{% else %} mdi:thumb-up
{% endif %}
entities_uun:
entity_id:
- script.update_entities_uun
- automation.check_for_unavailable_entities
friendly_name: Entities U/U/N
value_template: >
{% set ignore_list = ['light.driveway','light.garden_backyard','light.garden_terrace',
'light.porch_outdoors','light.parking_light'] if
is_state('binary_sensor.outside_daylight_sensor','on') else [] %}
{{ 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','history_graph','media_player'])
|map(attribute='entity_id')
|list|length }}
attribute_templates:
Unknown: >
{% set unknown = states|selectattr('state','eq','unknown')
|rejectattr('entity_id','in',state_attr('group.entity_blacklist','entity_id'))
|rejectattr('domain','in',['group','history_graph'])
|map(attribute='entity_id')
|list %}
{% if unknown|count == 0 %} 0
{% else %}
{{ unknown|count }}:
{{ '\n' + unknown|join(',\n') }}
{% endif %}
Unknown sensors: >
{% set unknown = states.sensor|selectattr('state','eq','unknown')
|rejectattr('entity_id','in',state_attr('group.entity_blacklist','entity_id'))
|map(attribute='entity_id')
|list %}
{% if unknown|count == 0 %} 0
{% else %}
{{ unknown|count }}:
{{ '\n' + unknown|join(',\n') }}
{% endif %}
Unavailable: >
{% set ignore_list = ['light.driveway','light.garden_backyard','light.garden_terrace',
'light.porch_outdoors','light.parking_light'] if
is_state('binary_sensor.outside_daylight_sensor','on') else [] %}
{% set unavailable = states|selectattr('state','eq','unavailable')
|rejectattr('entity_id','in',state_attr('group.entity_blacklist','entity_id'))
|rejectattr('entity_id','in',ignore_list)
|rejectattr('domain','eq','media_player')
|map(attribute='entity_id')
|list %}
{% if unavailable|count == 0 %} 0
{% else %}
{{ unavailable|count }}:
{{'\n'}}{{ unavailable|join(',\n') }}
{% endif %}
None: >
{% set none_ = states|selectattr('state','eq','none')
|map(attribute='entity_id')
|list %}
{% if none_|count == 0 %} 0
{% else %}
{{ none_|count }}:
{{ '\n' + none_|join(',\n') }}
{% endif %}
Full: >
{% set full = states|selectattr('state','in',['unavailable','unknown','none'])
|map(attribute='entity_id')
|list %}
{{ full|count}}:
{{ '\n' + full|join(',\n') }}
icon_template: >
{% if states('sensor.entities_uun')|int > 0 %} mdi:thumb-down
{% else %} mdi:thumb-up
{% endif %}
##########################################################################################
# Scripts
##########################################################################################
script:
update_entities_uun:
alias: Update entities UUN
sequence:
- service: homeassistant.update_entity
entity_id: sensor.entities_uun
##########################################################################################
# Automations
##########################################################################################
automation:
- alias: 'Unavailable Notification'
id: 'Unavailable Notification'
trigger:
platform: state
entity_id: sensor.entities_unavailable
condition:
condition: template
value_template: >
not is_state('sensor.entities_uun','0')}}
action:
- delay:
seconds: 30
- service: script.update_entities_uun
- condition: template
value_template: >
{{ states('sensor.entities_uun')|int > trigger.to_state.state|int }}
- condition: template
value_template: >
{{ trigger.to_state.state|int > trigger.from_state.state|int }}
- service: persistent_notification.create
data_template:
title: 'Entities Unavailable!'
message: >
### Unavailable entities: {{ '\n' + state_attr('sensor.entities_uun','Unavailable').split(', ')
| join('\n') }}
notification_id: 'entities_uun_alert'
- alias: 'Dismiss Unavailable Notification'
id: 'Dismiss Unavailable Notification'
trigger:
platform: template
value_template: >
{{is_state('sensor.entities_uun','0') and is_state('sensor.entities_unavailable','0')}}
condition:
condition: template
value_template: >
{{is_state('sensor.entities_uun','0') and is_state('sensor.entities_unavailable','0')}}
action:
service: persistent_notification.dismiss
data:
notification_id: 'entities_uun_alert'
- alias: 'Check for unavailable entities'
id: 'Check for unavailable entities'
trigger:
platform: time_pattern
minutes: '/5'
condition:
condition: or
conditions:
- condition: template
value_template: >
{{not is_state('sensor.entities_unavailable','0')}}
- condition: template
value_template: >
{{not is_state('sensor.entities_uun','0')}}
- condition: template
value_template: >
{{is_state('persistent_notification.entities_uun_alert','notifying')}}
action:
- service: script.update_entities_uun
- condition: template
value_template: >
{{is_state('sensor.entities_uun','0')}}
- service: automation.trigger
entity_id: automation.dismiss_unavailable_notification