Unavailable / Unknown Entity Monitoring - Template Sensor

I got this, I meant to add it to the ignored_entities entities
like right now I have

ignored_entities:
entities:
- binary_sensor.updater
- binary_sensor.fios_router_wan_status
- binary_sensor.garage_back_door
- binary_sensor.garage_doors
- button.backup_reboot
- button.backup_shutdown
- button.tessy_flash_lights
- button.tessy_horn
- sensor.stevens_phone_charger_type
- sensor.refrigerator_temperature_measurement
- sensor.refrigerator_thermostat_cooling_setpoint
- switch.dryer_power_off
- switch.top_load_washer_power_off
- sensor.stevens_s22_ultra_charger_type
- update.home_assistant_supervisor_update
- binary_sensor.octoprint_printing

i was hoping to add another group like
ignored_entites_search
entities:
- \S+tessy_\S*
- ^(device_tracker)\S+

I understand. What Iā€™m telling you is you canā€™t use templates in yami group configurations so you have to build them into the template itself. You can use regular expressions there.

that stinks, I was hoping to just add it to a group and not change the actual ā€œsensorā€

I did as was instructed but I now have an issue. my unavailable entities is below but Iā€™m getting an ā€œInvalid config for [group]: Entity ID ^(button|switch){1}(.octoprint_)\S+ is an invalid entity ID for dictionary value @ data[ā€˜groupā€™][ā€˜ignored_entities_searchā€™][ā€˜entitiesā€™ā€ and so on. What did I mess up?

sensor:
  - platform: template
    sensors:
      unavailable_entities:
        friendly_name: Unavailable Entities
        unit_of_measurement: entities
        icon_template: "{{ 'mdi:check-circle' if is_state('sensor.unavailable_entities','0') else 'mdi:alert-circle' }}"
        value_template: >
          {{ states|selectattr('state','in',['unavailable','unknown','none'])|rejectattr('domain','eq','group')
          |rejectattr('entity_id','in',state_attr('group.ignored_entities','entity_id'))
          |rejectattr('entity_id','search','^(button|switch){1}(\.octoprint_)\S+')
          |rejectattr('entity_id','search','\S+tessy_\S*')
          |rejectattr('entity_id','search','^(device_tracker)\S+')
          |rejectattr('entity_id','search','^(sensor)\S+(speaker_alarms|speaker_timers|display_alarms|display_timers)')
          |list|count }}
        attribute_templates:
          entities: >
            {{ states|selectattr('state','in',['unavailable','unknown','none'])|rejectattr('domain','eq','group')
            |rejectattr('entity_id','in',state_attr('group.ignored_entities','entity_id'))
            |rejectattr('entity_id','search','^(button|switch){1}(\.octoprint_)\S+')
            |rejectattr('entity_id','search','\S+tessy_\S*')
            |rejectattr('entity_id','search','^(device_tracker)\S+')
            |rejectattr('entity_id','search','^(sensor)\S+(speaker_alarms|speaker_timers|display_alarms|display_timers)')
            |map(attribute='entity_id')|list }}

Ok I am really lost, I updated my unavailable entitys to below and it will not filter out using the searches. Any help would be great.

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 = 60 %}
            {% set ignored = state_attr('group.ignored_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)
                |selectattr('state','in',['unavailable','unknown'])
                |rejectattr('entity_id','search','^(button|switch){1}(.octoprint_)\S+')
                |rejectattr('entity_id','search','\S+tessy_\S*')
                |rejectattr('entity_id','search','^(device_tracker)\S+')
                |rejectattr('entity_id','search','^(camera\.wyze_cam)\S+')
                |rejectattr('entity_id','search','^(sensor)\S+(speaker_alarms|speaker_timers|display_alarms|display_timers)')
                %}
            {% if ignored != none %}
              {% set entities =  entities|rejectattr('entity_id','in',ignored) %}
            {% endif %}
            {{ entities|map(attribute='entity_id')|list }}

Why not using only 1 rejectattr?


                |rejectattr('entity_id','search','device_tracker|master|wyze_cam')

Because some of the regedit is more complex. I just wanted to seperate them ench. But even with the rejectattr search it is still putting it in.

Set it back to the default template then add your filters one at a time, test them, them move on once youā€™ve got the current one working.

First thing I see is this |rejectattr('entity_id','search','^(device_tracker)\S+') Why use regex here?

You want to filter out all entities in the domain device tracker?
|rejectattr('domain','eq','device_tracker')

You want to filter out all entities that contain ā€œcamera.wyze_camā€ in their entity_id?
|rejectattr('entity_id','search','camera.wyze_cam')

Etc. etc.

I just reverted, it was easier, below is my code. Now I have a question about display. What is the best way to have a card where I would click on the entity and go to itā€™s info page?

sensor:
  - platform: template
    sensors:
      unavailable_entities:
        friendly_name: Unavailable Entities
        unit_of_measurement: entities
        icon_template: "{{ 'mdi:check-circle' if is_state('sensor.unavailable_entities','0') else 'mdi:alert-circle' }}"
        value_template: >
          {{ states|selectattr('state','in',['unavailable','unknown','none'])|rejectattr('domain','eq','group')
          |rejectattr('entity_id','in',state_attr('group.ignored_entities','entity_id'))
          |rejectattr('domain','eq','device_tracker')
          |rejectattr('domain','eq','number')
          |rejectattr('entity_id','search','camera.wyze_cam')
          |rejectattr('entity_id','search','tessy_')
          |rejectattr('entity_id','search','_do_not_disturb')
          |rejectattr('entity_id','search','^(button|switch){1}(.octoprint_)\S+')
          |rejectattr('entity_id','search','^(sensor)\S+(speaker_alarms|speaker_timers|display_alarms|display_timers|_estimated_distance)')
          |list|count }}
        attribute_templates:
          entities: >
            {{ states|selectattr('state','in',['unavailable','unknown','none'])|rejectattr('domain','eq','group')
            |rejectattr('entity_id','in',state_attr('group.ignored_entities','entity_id'))
            |rejectattr('domain','eq','device_tracker')
            |rejectattr('domain','eq','number')
            |rejectattr('entity_id','search','camera.wyze_cam_')
            |rejectattr('entity_id','search','tessy_')
            |rejectattr('entity_id','search','_do_not_disturb')
            |rejectattr('entity_id','search','^(button|switch){1}(.octoprint_)\S+')
            |rejectattr('entity_id','search','^(sensor)\S+(speaker_alarms|speaker_timers|display_alarms|display_timers|_estimated_distance)')
            |map(attribute='entity_id')|list }}

You really need to format your code when you post. Also, if youā€™re posting a wall of text consider hiding it with a summary. This is way too hard to read on mobile and difficult to copy and paste without having to reformat it. Seriously, try copying your sensor definition above and pasting it back into your code editor. Youā€™re asking people to spend their time helping your, the least you can do is make it as easy as possible for them.

Here's my sensor config as an example
  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
      state: >
        {% set entities = state_attr(this.entity_id,'entity_id') %}
        {% if entities != none %} {{ entities|count }} {% endif %}
      attributes:
        entity_id: >
          {% set ignore_seconds = 60 %}
          {% set ignored = state_attr('group.ignored_unavailable_entities','entity_id') %}
          {% set ignore_ts = (now().timestamp() - ignore_seconds)|as_datetime %}
          {% set entities = states|rejectattr('domain','in',['group','geo_location'])
              |rejectattr('entity_id','in',expand(integration_entities('browser_mod'))|map(attribute='entity_id')|list)
              |rejectattr('entity_id','in',expand(integration_entities('gdacs'))|map(attribute='entity_id')|list)
              |rejectattr('entity_id','in',expand(integration_entities('github'))|map(attribute='entity_id')|list)
              |rejectattr('entity_id','in',expand(integration_entities('glances'))|map(attribute='entity_id')|list)
              |rejectattr('entity_id','in',expand(integration_entities('hassio'))|map(attribute='entity_id')|list)
              |rejectattr('entity_id','in',expand(integration_entities('openuv'))|map(attribute='entity_id')|list)
              |rejectattr('entity_id','in',expand(integration_entities('utility_meter'))|map(attribute='entity_id')|list)
              |rejectattr('entity_id','in',expand(integration_entities('waqi'))|map(attribute='entity_id')|list)
              |rejectattr('entity_id','search','jlaptop_chrome|jlaptop_edge|jwork_chrome|jphone_app|sphone_app')
              |rejectattr('entity_id','search','jason_laptop_media_player|jason_phone_media_player|sheri_phone_media_player')
              |rejectattr('entity_id','search','_timers|_alarms|_do_not_disturb|_alarm_volume')
              |rejectattr('entity_id','search','sensor.daily_energy_consumption')
              |rejectattr('entity_id','search','_next_alarm')
              |rejectattr('last_changed','ge',ignore_ts)
              |selectattr('state','in',['unavailable','unknown']) %}
          {% if ignored != none %}
            {% set entities =  entities|rejectattr('entity_id','in',ignored) %}
          {% endif %}
          {{ entities|map(attribute='entity_id')|list }}

Anyway the simplest way is to display the sensor with clickable entities is to use an auto-entities card.

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

image

1 Like

First thank you for this. It is great.

Second I did what you did, and it worked. Sorry for the formatting earlier.

This is much nicer. BTW is there anyway to get a count at the top of the card?

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.