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 }}
- name: âUnavailable Entitiesâ
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.
Let me try again. I thought I had it in a code block
And again, it was working up until i sent to 2023.4.6.
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 }}
I donât recall any change in HA that would cause it not to work and I donât see anything wrong here. Iâm assuming you didnât alter the template at all?
There is a slightly updated version on the git. I would start by removing the package (just move the file out of the directory), then reload your templates and delete the orphaned entity. Then redo the package with the newest version (you should be able to copy and paste your entity_id section from the old file). Reload your templates and then see what happens. Let me know how you make out.
Thanks for looking into it, as i was scrolling up to et the GIT link, i saw a post from apr 6 with the same problem. It was solved by simply removing the unit of measure line
Ah yeah. Forgot about that. You can either delete that or add the following if you want to keep the unit of measurement.
state_class: measurement
Hey I have been using my below template and need to add one little piece. I want to filter out entities of disabled devices. What do I need to add to the filter?
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','none'])%}
{% if ignored != none %}
{% set entities = entities|rejectattr('entity_id','in',ignored) %}
{% endif %}
{{ entities|map(attribute='entity_id')|list }}
The in documentation is pretty thorough and there are several examples in the git issues and discussions.
When you disable a device the entities become âunavailableâ. Add those entities to the ignored_entities group or add a filter in the template.
If there are unique common elements to the in the device entitiy idâs you can add search filters. Examples are provided in the documentation.
If the devices are all part of one integration you can ignore the integration entirely.
If you still need assistance, please provide a list of the entity idâs you wish to filter out.
I know I could do this, but I was hoping to just add all the entities of disabled devices.
If I do this
{{device_entities(device_attr('',''))}}
I can at least get all the devices but not if disabled
I was thinking about your request and Iâm actually fooling around with some templates right now to determine disabled devices and automatically excluded them from the sensor.
Iâll get back to ya.
Awesome, thank you
So as you discovered, the issue here is that when a device is disabled device_entities() doesnât report any entities.
If it DID, this little hacky template (there is probably a more elegant way to accomplish this) would work and we could utilize it in the unavailable entities template. It would have been a good addition to the template if it did work! But no dice. So I guess my advice above stands. Youâll have to add the entities required manually.
{%- set devices = namespace(device_id=[]) %}
{%- for item in states|map(attribute='entity_id')|list %}
{%- if device_attr(item,'disabled_by') != none %}
{%- set devices.device_id = devices.device_id + [device_id(item)] %}
{%- endif %}
{%- endfor %}
{%- set disabled = devices.device_id|unique|list %}
{% for item in disabled %}
{{ item }}
{{ device_attr(item,'name') }}
{{ device_entities(item) }}
{% endfor %}
Well at least you tried, thanks anyway.
How would I exclude all entity IDs from a specific Integration without adding them to a group âAlexa Media Playerâ for example? I have over 120+ entity IDs for these.
Template and documentation have been updated with new syntax and to exclude new stateless domains (button, scene, event etc.) by default.
Is there anyway just to show entity thatâs are unavailable, currently its showing unavailable and unknown entities which isnât what. I need
Replace this
{% 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', ['button', 'event', 'group', 'input_button', 'input_text', 'scene'])
| rejectattr('last_changed', 'ge', ignore_ts) %}
{% set entities = entities | rejectattr('entity_id', 'in', ignored) if ignored != none else entities %}
{{ entities | map(attribute='entity_id') | reject('has_value') | list | sort }}
With this
{% 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', ['button', 'event', 'group', 'input_button', 'input_text', 'scene'])
| selectattr('state','eq','unavailable')
| rejectattr('last_changed', 'ge', ignore_ts) %}
{% set entities = entities | rejectattr('entity_id', 'in', ignored) if ignored != none else entities %}
{{ entities | map(attribute='entity_id') | list | sort }}
I love this sensor however I have just added a device that has added a set of entities beginning with âsensor.byteâ which I do not want to know about however when I put '- sensor.byte_* â in my ignore entities group they still show. I obviously got the syntax wrong or do i need to add a rejectattr to the sensor code itself.