Unavailable / Unknown Entity Monitoring - Template Sensor

Add the unavailable entities sensor to the card config.

type: custom:auto-entities
filter:
  template: "{{ state_attr('sensor.unavailable_entities','entity_id') }}"
sort:
  method: state
card:
  type: entities
  title: "Unavailable Entities"
  show_header_toggle: false
entities:
  - sensor.unavailable_entities

image

Or if you want to get fancy use a fold entities row in your card to hide the list until you click the chevron.

type: entities
title: "Unavailable Entities"
show_header_toggle: false
entities:
  - type: custom:auto-entities
    show_empty: true
    unique: true
    filter:
      template: "{{ state_attr('sensor.unavailable_entities','entity_id') }}"
    sort:
      method: state
    card:
      type: custom:fold-entity-row
      padding: 0
      head:
        entity: sensor.unavailable_entities

image

image

I like that idea. I’m also toying with using the card to filter while having the ability to see anything I want filtered out. This way I don’t need to restart, its all part of the card.
Thank you so much for the help.

1 Like

Could you please edit that post and fix it?

how add the code?

sensor:
    - name: "Unavailable Sensors"
      unique_id: unavailable_sensors 
      icon: "{{ iif(states(this.entity_id)|int(0) > 0,'mdi:alert-circle','mdi:check-circle') }}"
      unit_of_measurement: entities
....
....

i need to start like this:

- platform: template
  sensors:
    unavailable_entities:

thanks

template:
  - sensor:
      - name: "Unavailable Entities"
        unique_id: unavailable_entities
        icon: "{{ iif(states(this.entity_id)|int(0) > 0,'mdi:alert-circle','mdi:check-circle') }}"
        unit_of_measurement: entities
        state: "{{ entities|count if entities != none else none }}"

You’re trying to use the old yaml template configuration. No longer recommended.

thanks, i found here a good solution:

ohh i see you have here a nice example:

i take this :wink:

i see now how many entities have a state = Unavailable
But how can i output a “name” List or other List from the items?

There is an example automation in the package that creates a persistent notification with either a simple or detailed list of unavailable/unknown entities.

Have you looked at that? If persistent notifications aren’t your bag you can use the code used there in an HTML template card or something.

Hi, First of all, thanks for the code of this wonderful sensor.
I’m trying to send a notification to a Telegram group modifying a little the code you wrote for the detailed notification, but… it’s not working as expected.

The sensor is working fine, just when i try to fomat it using (using it in developers tab):

- service: notify.telegram
  data:
    title: "Entidades no disponibles"
    message: >
       {% set ns = namespace(result=[]) %}
       {% for s in expand(state_attr('sensor.unavailable_entities', 'entity_id')) %}
           {% set ns.result = ns.result + [
                   s.name ~ "\n"
                      ~ "  - Entity_id: " ~ s.entity_id ~ "\n"
                      ~ "  - Estado: " ~ s.state ~ "\n"
                 ]
            %}
        {% endfor %}                                                
        {{ ns.result | join('\n') }}

the result code is:

- service: notify.telegram
  data:
    title: "Entidades no disponibles"
    message: >
       
       
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
        
           
                                                        
         Controlinputselect2
  - Entity_id: automation.controlinputselect2
  - Estado: unavailable

loc2
  - Entity_id: automation.loc2
  - Estado: unavailable

login
  - Entity_id: automation.login
  - Estado: unavailable

Why i have a lot of blank / spaces at the beggining ?

Not sure. Your code works fine for me.

Can you do a screenshot like I did of the actual developer tools template?

Tested.

Using the code as you did, it works too.

just when i use:

- service: notify.telegram
  data:
    title: "Entidades no disponibles"
    message: >

Is when it creates a lot of blank space, and i receive a message at the logs with:

Let me try to check again, to see how i can solve this.

Thanks !!!

I get this error message in the logs since the update to 2023.03. Is there something about the template sensor that should be adjusted?

Logger: homeassistant.components.sensor
Source: components/sensor/__init__.py:597
Integration: Sensor (documentation, issues)
First occurred: 14:15:07 (1 occurrences)
Last logged: 14:15:07

Sensor sensor.unavailable_entities has device class None, state class None and unit entities thus indicating it has a numeric value; however, it has the non-numeric value: (<class 'str'>); Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+template%22

same here, plus with 2023.4 it doesn’t show the attributes in the dialog menu

See: HA 2023.4.0 no longer shows my template sensor attribute list - #3 by pedolsky

1 Like

Thank you for the nice sensor and the automation!
I also really like the detailed notification, this is also working except the devices names of ZHA devices are not schown correctly

Can anyone help to fix this?

@jazzyisj This Template sensor is awesome, saved me a couple times in the past, as I have it display unavailable sensors on the home dashboard.
I upgraded to HA 2023.4.6 and my sensor for unavailable_entities went ‘unavailable’!
I upgraded to 2023.5.4 and still remains unavailable. Not sure why.
I appreciate any pointers in what to look for to fix this

Can you post your template?

It is in the Config/Packages folder and I have the include statement in the configuration.yaml

homeassistant:
  packages: !include_dir_named packages
  customize: !include customize.yaml```

###################################################################################################

Package - Unavailable Entities Sensor

Count and list entities with a state of unavailable or unknown

Home Assistant v2022.5 required. See README for customization options.

https://github.com/jazzyisj/unavailable-entities-sensor/blob/main/README.md

###################################################################################################

REQUIRED - This is the template sensor

template:

  • sensor:
    • name: “Unavailable Entities”
      unique_id: unavailable_entities
      icon: “{{ iif(states(this.entity_id)|int(0) > 0,‘mdi:alert-circle’,‘mdi:check-circle’) }}”
      unit_of_measurement: entities
      state: >
      {% set entities = state_attr(this.entity_id,‘entity_id’) %}
      {% if entities != none %} {{ entities|count }} {% endif %}
      attributes:
      entity_id: >
      {% set ignore_seconds = 300 %}
      {% set ignored = state_attr(‘group.ignored_unavailable_entities’,‘entity_id’) %}
      {% set ignore_ts = (now().timestamp() - ignore_seconds)|as_datetime %}
      {% set entities = states|rejectattr(‘domain’,‘eq’,‘group’)
      |rejectattr(‘last_changed’,‘ge’,ignore_ts)
      |rejectattr(‘entity_id’,‘search’,‘alarm_volume|next_alarm|alarms’)
      |rejectattr(‘entity_id’,‘search’,'keymaster
      |identify|echo|next|media_player’)
      |rejectattr(‘entity_id’,‘search’,'button.ikea
      |button.dimmer
      |button.in
      ’)
      |rejectattr(‘entity_id’,‘search’,’_tablet|_pc|_ping|browser|rx|rx|tx|tx|2nd_bath|_switch’)
      |rejectattr(‘entity_id’,‘search’,‘device_tracker|uptime|uptime|_electrical|_consumption’)
      |rejectattr(‘entity_id’,‘search’,’_power|humidity|pressure|weatheralerts|sengled|protection’)
      |rejectattr(‘entity_id’,‘search’,'sensor.pi_hole
      ’)
      |selectattr(‘state’,‘in’,[‘unavailable’,‘unknown’]) %}
      {% if ignored != none %}
      {% set entities = entities|rejectattr(‘entity_id’,‘in’,ignored) %}
      {% endif %}
      {{ entities|map(attribute=‘entity_id’)|list }}

OPTIONAL - Uncomment and add entities you want to ignore to this group.

group:
ignored_unavailable_entities:
entities:
- sensor.1e0de372_f503aec8
- automation.keymaster_garage_changed_code
- automation.keymaster_garage_decrement_access_count
- binary_sensor.0937395f_3ad1290e
- binary_sensor.9d68a265_ade68988
- binary_sensor.dc13e6e8_9c97a4af
- binary_sensor.e3397bb5_ef3397f8
- sensor.network_throughput_in_eth0
- sensor.network_throughput_out_eth0
- sensor.fox_news
- sensor.hacs
- person.admin
- person.tablets
- scene.i_m_home
- automation.announce_arrival
- sensor.nortek_security_and_control_f_adt_wtr_1_b8d50b4c_device_temperature
- sensor.nortek_security_and_control_f_adt_wtr_1_b8d50b4c_device_temperature_2
- light.watch_sony_tv
- light.watch_sony_tv_2
- button.sony_xr_65a80j_reboot
- button.sony_xr_65a80j_terminate_apps
- button.syn920_reboot
- button.syn920_shutdown

OPTIONAL Example automation to demonstrate how you can utilize this sensor```

I don’t see anything wrong with a quick look, but you’ll need to format your comment correctly before I can help you. You only need to provide the template section.