I installed the package and restarted I show errors in two automations . Where is my mistake?
What version of HA are you running?
Your HA version would be the one under Core. v2023.11.1. You should probably update, you are more than a year behind. I’m pretty sure that’s where your issue is, there have been some syntax changes since your version. Guess I need to figure out what version the syntax changed and update the required version for the package.
You might be able to get it to work if you change all instances of - trigger: to - platform and all instances of - action: to - service: Do not change the instances with no hyphen in front of them.
I updated the Core and everything worked Super Thank you
Good stuff. That was a big jump in versions. I’m surprised you didn’t have any other issues. There is going to be quite a few changes for you. You can read about them all here.
Edit: I was confused by my own sloppy copy and paste. Got it working correctly now.
I’ve finally had a chance to go back and look at some of my old bookmarks and had a really good look at your disabled device entities sensor. jq is a new one for me - very clever to use it on the entity_registry! I still haven’t completely figured out all the arguments you used yet. Gotta dive into the docs.
I’m going to sit on it for a bit, but I’m thinking about including it with the package. There really isn’t a point to reporting disabled entities with the unavailable entities sensor, but I’m wondering if constantly reading off the drive to get that info isn’t maybe killing a fly with a hammer. Maybe I’m overthinking it. Either way - pretty neat, thanks for sharing. If I put it in the package I’ll be sure credit you.
Thanks, I’m sure it could be improved, in fact someone did post an improvement later. I haven’t had any issues with it and honestly haven’t revisited it since I implemented it.
today i switched to the new package and i had to remove the trigger for the startup of the automation because the automation trigger this to early and gave me notifications that are not needed
It’s probably not needed anyway since there is a time_pattern trigger there. No one else has ever mentioned it being an issue, but I’ll keep it in mind and maybe remove it from the package next release. Thanks for the heads up.
Hello all!!
I have been using the original package happily for years and am incredibly thankful for @jazzyisj work on this template.
I am looking for opinions/ thoughts on a slightly different approach and possible help on how to implement it as I am not very impressive with writing complex template sensors.
As such, is there a way to get they package to publish the device name or integration that the unavailable/ unknown entity is related to? Rather then each individual entity. The hopes would be that duplicates would be reduced to 1 final result in the message to the user. I.e. if I had a device that had 5 unavailable entities, it would report the device id 1 time, a similar situation if the user chose to report at the integration level.
Thank you all for any thoughts/ examples/ideas on this.
This already exists if you are using the detailed notification in the example folder. I’m sure you could adapt the code in that example to meet your requirements.
There is also an example in the pinned issue on the git. You’ll have to update it to the new structure if you’re using that.
Edit: Also here’s a template I’ve been testing that lists unavailable devices and unavailable entities without a device. Haven’t really looked at it much. Try it and let me know!
Unavailable Devices and Entities Sensor
template:
- sensor:
- name: "Unavailable Devices Plus"
unique_id: unavailable_devices_plus #TEST
icon: "{{ iif(states(this.entity_id)|int(-1) > 0, 'mdi:alert-circle', 'mdi:check-circle') }}"
state: >
{% set devices = state_attr(this.entity_id, 'devices') %}
{{ devices | count if devices != none else -1 }}
attributes:
devices: >
{%- set items = namespace(value=[]) %}
{%- for entity in expand(state_attr('group.unavailable_entities', 'entity_id')) %}
{%- set items.value = items.value + [device_attr(entity.entity_id, "name") ~ '|' ~ device_id(entity.entity_id) ~ '|' ~ entity.entity_id] %}
{%- endfor %}
{%- set items.value = items.value | sort %}
{%- set lastdev = namespace(id='') %}
{%- set lastname = namespace(value='') %}
{%- set devices = namespace(items=[]) %}
{%- set entities = namespace(items=[]) %}
{%- set device_entities = namespace(count=0) %}
{%- for item in items.value %}
{%- set device = item.split("|")[0] %}
{%- set device_id = item.split("|")[1] %}
{%- set entity = item.split("|")[2] %}
{%- if device | lower == 'none' %}
{%- set entities.items = entities.items + [entity] %}
{%- elif lastdev.id != device_id and lastdev.id != "" %}
{%- set devices.items = devices.items + [lastname.value ~ ' [' ~ device_entities.count ~']'] %}
{%- set device_entities.count = 0 %}
{%- endif %}
{%- set lastdev.id = device_id %}
{%- set lastname.value = device %}
{%- set device_entities.count = device_entities.count + 1 %}
{%- endfor %}
{{ devices.items + entities.items }}
i have currently this running in my automation:
data:
notification_id: unavailable_entities
title: Unavailable Entities
message: >
{% set ns = namespace(result=[]) %} {% for s in
expand(state_attr('group.unavailable_entities', 'entity_id')) %}
{% set ns.result = ns.result + [
device_attr(s.entity_id, "name") ~ "|" ~ device_id(s.entity_id) ~ "|- **" ~ s.name ~ "**\n"
~ " - *entity_id*: " ~ s.entity_id ~ "\n"
~ " - *state*: " ~ s.state ~ "\n"
]
%}
{% endfor %} {% set ns.result = ns.result | sort %} {% set lastdev =
namespace( id="" ) %} {% set tarr = ns.result %} {% set ns.result = [] %} {%
for item in tarr %}
{% set dev = namespace( id="" ) %}
{% set entity = namespace( data="" ) %}
{% set dev.id = item.split("|")[1] %}
{% set entity.data = item.split("|")[2] %}
{% if lastdev.id != dev.id %}
{% if dev.id != 'None' %}
{% set ns.result = ns.result + [ "**<a href=\"/config/devices/device/" ~ dev.id ~ "\">" ~ device_attr(dev.id, "name") ~ "</a>**" ] %}
{% else %}
{% set ns.result = ns.result + [ "**Non-Device Entities**" ] %}
{% endif %}
{% set lastdev.id = dev.id %}
{% endif %}
{% set ns.result = ns.result + [ entity.data ] %}
{% endfor %} {{ ns.result | join('\n') }}
alias: Persistent Notification
action: persistent_notification.create
Thank you for responding!! I will give the template sensor a try this weekend as I begin to move away from version 1 of your git on this subject and begin setting up to move to v2. Thank you so much for the help you have given the community and myself on multiple other occasions. Very thankful to you!!
@jazzyisj Hey Jason! Hope all is well. I have had time to move over to the v2 template and all is working great!. I did want to ask you and the others if something is doable that I used to have working in the old version. There is a line where you could ignore things for so many seconds with this line:
Is this still doable?
{% set ignore_seconds = 300 %}
Here is my v2 template:
###################################################################################################
## PACKAGE: Unavailable Entities Sensor v2.2
## DESCRIPTION: Count and list entities with a state of unknown or unavailable
## REQUIREMENTS: Home Assistant v2024.8
## USAGE: https://github.com/jazzyisj/unavailable-entities-sensor/blob/main/README.md
###################################################################################################
# REQUIRED - This is the template sensor
template:
- sensor:
- name: "Unavailable Entities- NEW"
unique_id: unavailable_entities_new
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_entities_new', 'entity_id') %}
{{ entities | count if entities != none else -1 }}
# REQUIRED - Add individual entities to ignore to this group.
group:
ignored_entities_new:
entities:
- device_tracker.clarice
- light.tiki_bar_sign
- media_player.back_patio_speaker
- media_player.back_porch_speaker
- media_player.everywhere_outside
- media_player.guest_bedroom_tv
- media_player.nucome_speaker
- sensor.laptop_media_server
- sensor.lightning_near_home_lightning_azimuth
- sensor.lightning_near_home_lightning_distance
- sensor.master_bedroom_active_app
- sensor.master_bedroom_active_app_id
- sensor.washer_power_stats
- sensor.westonspc_activewindow
- notify.upstairs
- notify.basement
- notify.living_room
- sensor.quickstick_combo_basic
- light.living_room_chair_lamp
- device_tracker.westons_small_tablet
- device_tracker.kitchen_wall_tablet
- device_tracker.master_bedroom_tablet
# REQUIRED - This is required to create and update the monitored entities group. Updates once every minute.
automation:
- id: update_unavailable_entities_group_new
alias: "Update Unavailable Entities Group NEW"
description: "Update unavailable entities group. NEW"
mode: single
max_exceeded: silent
triggers:
- trigger: homeassistant
id: startup
event: start
- trigger: event
event_type: call_service
event_data:
domain: group
service: reload
- trigger: time_pattern
minutes: "/1"
actions:
# IMPORTANT - This is the template to edit to exclude entities with filters.
- action: group.set
data:
object_id: unavailable_entities_new
entities: >
{{ states
| rejectattr('domain', 'in', ['button', 'conversation', 'event', 'group', 'image',
'input_button', 'input_text', 'remote', 'tts', 'scene', 'stt', 'update'])
| rejectattr('entity_id', 'in', state_attr('group.ignored_entities_new', 'entity_id'))
| rejectattr('entity_id', 'search', 'octoprint_')
| rejectattr('entity_id', 'search', 'garage_door_low_battery_level')
| rejectattr('entity_id', 'search', 'garage_door_tampering')
| rejectattr('entity_id', 'search', 'garage_door_barrier')
| rejectattr('entity_id', 'search', 'weatheralerts_')
| rejectattr('entity_id', 'search', 'sonos')
| rejectattr('entity_id', 'search', 'active_app')
| rejectattr('entity_id', 'search', 'vacuum')
| rejectattr('entity_id', 'search', 'location')
| rejectattr('entity_id', 'search', 'soundbar')
| rejectattr('entity_id', 'search', 'media_player')
| rejectattr('entity_id', 'search', 'arcade')
| rejectattr('entity_id', 'search', 'paired')
| rejectattr('entity_id', 'search', 'blinds')
| rejectattr('entity_id', 'search', '_indicator_value')
| rejectattr('entity_id', 'search', '_firmware')
| rejectattr('entity_id', 'search', 'channel')
| rejectattr('entity_id', 'search', 'espresense_gym')
| rejectattr('entity_id', 'search', '_indicator_value')
| rejectattr('entity_id', 'eq', 'group.unavailable_entities_new')
| selectattr('state', 'in', ['unknown', 'unavailable'])
| map(attribute='entity_id') | list | sort }}
# OPTIONAL - Example automation to demonstrate how you can utilize this sensor, see example folder for more.
- id: unavailable_entities_notification_new
alias: "Unavailable Entities Notification New"
description: "Create persistent notification if unavailable entities, dismiss if none. NEW"
mode: restart
triggers:
- trigger: state
entity_id: group.unavailable_entities_new
attribute: entity_id
to: ~
for: 5 # throttle triggers and prevent blank notifications
conditions:
- condition: template
alias: "Sensor state is a valid numerical value"
value_template: "{{ is_number(states('sensor.unavailable_entities_new')) }}"
actions:
- if:
- condition: numeric_state
entity_id: sensor.unavailable_entities_new
below: 1
then:
- data:
notification_id: unavailable_entities_new
action: persistent_notification.dismiss
- data:
who: weston
title: Unavailable Devices-NEW
message: clear_notification
group: unavailable_entities
tag: unavailable_entities
action: script.text_notify
enabled: true
else:
- action: persistent_notification.create
data:
notification_id: unavailable_entities_new
title: "Unavailable Entities- NEW"
message: "{{ state_attr('group.unavailable_entities_new', 'entity_id') | join('\n') }}"
- data:
who: weston
title: Unavailable Entities- NEW
message: |-
{{ state_attr('sensor.unavailable_entities', 'entity_id') | join('
') }}
group: unavailable_entities
tag: unavailable_entities
action: script.text_notify
# - id: unavailable_entities_notification_new
# alias: "Unavailable Entities Notification- NEW"
# description: "Create persistent notification if unavailable entities, dismiss if none. NEW"
# mode: restart
# triggers:
# - trigger: state
# entity_id: group.unavailable_entities_new
# attribute: entity_id
# to: ~
# for: 5 # throttle triggers and prevent blank notifications
# conditions:
# - condition: template
# alias: "Sensor state is a valid numerical value"
# value_template: "{{ is_number(states('sensor.unavailable_entities_new')) }}"
# actions:
# - action: persistent_notification.create
# data:
# notification_id: unavailable_entities_new
# title: "Unavailable Entities NEW"
# message: >
# {% set ns = namespace(result=[]) %}
# {% for s in expand(state_attr('group.unavailable_entities_new', 'entity_id')) %}
# {% set ns.result = ns.result + [
# device_attr(s.entity_id, "name") ~ "|" ~ device_id(s.entity_id) ~ "|- **" ~ s.name ~ "**\n"
# ~ " - *entity_id*: " ~ s.entity_id ~ "\n"
# ~ " - *state*: " ~ s.state ~ "\n"
# ]
# %}
# {% endfor %}
# {% set ns.result = ns.result | sort %}
# {% set lastdev = namespace( id="" ) %}
# {% set tarr = ns.result %}
# {% set ns.result = [] %}
# {% for item in tarr %}
# {% set dev = namespace( id="" ) %}
# {% set entity = namespace( data="" ) %}
# {% set dev.id = item.split("|")[1] %}
# {% set entity.data = item.split("|")[2] %}
# {% if lastdev.id != dev.id %}
# {% if dev.id != 'None' %}
# {% set ns.result = ns.result + [ "**<a href=\"/config/devices/device/" ~ dev.id ~ "\">" ~ device_attr(dev.id, "name") ~ "</a>**" ] %}
# {% else %}
# {% set ns.result = ns.result + [ "**Non-Device Entities**" ] %}
# {% endif %}
# {% set lastdev.id = dev.id %}
# {% endif %}
# {% set ns.result = ns.result + [ entity.data ] %}
# {% endfor %}
# {{ ns.result | join('\n') }}
# Auto Entities Card
###################################################################################################
## DESCRIPTION: Using unavailable entities sensor with an auto entities card and fold entity row
## https://github.com/thomasloven/lovelace-auto-entities
## https://github.com/thomasloven/lovelace-fold-entity-row
###################################################################################################
# type: entities
# title: "Unavailable Entities Example"
# state_color: true
# show_header_toggle: false
# entities:
# - type: custom:auto-entities
# show_empty: true
# unique: true
# filter:
# include:
# - group: group.unavailable_entities
# sort:
# method: state
# card:
# type: custom:fold-entity-row
# padding: 0
# head:
# entity: sensor.unavailable_entities
Here is the v1 template and how the ignore seconds was being used:
Essentially I would like the home assistant to have a few minutes before it sends the list of entities that are problems (at start up and if possible when a new entity becomes not available outside of the start up process). Maybe I am thinking about all of this wrong. Please let me know if I am, maybe I’m not understanding everything completely and overcomplicating things.
###################################################################################################
## PACKAGE: Unavailable Entities Sensor
## DESCRIPTION: Count and list entities with a state of unknown or unavailable
## REQUIREMENTS: Home Assistant v2022.5
## USAGE: 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(-1) > 0, 'mdi:alert-circle', 'mdi:check-circle') }}"
state_class: measurement
unit_of_measurement: entities
state: >
{% set entities = state_attr(this.entity_id, 'entity_id') %}
{{ entities | count if entities != none else none }}
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','in',['button', 'conversation', 'event', 'group', 'image', 'input_button', 'input_text', 'remote', 'tts', 'scene', 'select', 'stt', 'automation', 'script', 'notify', 'update','number'])
| rejectattr('last_changed', 'ge', ignore_ts)
| rejectattr('entity_id', 'search', 'octoprint_')
| rejectattr('entity_id', 'search', 'garage_door_low_battery_level')
| rejectattr('entity_id', 'search', 'garage_door_tampering')
| rejectattr('entity_id', 'search', 'garage_door_barrier')
| rejectattr('entity_id', 'search', 'weatheralerts_')
| rejectattr('entity_id', 'search', 'sonos')
| rejectattr('entity_id', 'search', 'active_app')
| rejectattr('entity_id', 'search', 'vacuum')
| rejectattr('entity_id', 'search', 'location')
| rejectattr('entity_id', 'search', 'soundbar')
| rejectattr('entity_id', 'search', 'media_player')
| rejectattr('entity_id', 'search', 'arcade')
| rejectattr('entity_id', 'search', 'paired')
| rejectattr('entity_id', 'search', 'blinds') %}
{% set entities = entities | rejectattr('entity_id', 'in', ignored) if ignored != none else entities %}
{{ entities | map(attribute='entity_id') | reject('has_value') | list | sort }}
# OPTIONAL - Add entities you want to ignore to this group. Delete if not using group.
group:
ignored_unavailable_entities:
entities:
- device_tracker.clarice
- light.tiki_bar_sign
- media_player.back_patio_speaker
- media_player.back_porch_speaker
- media_player.everywhere_outside
- media_player.guest_bedroom_tv
- media_player.nucome_speaker
- sensor.laptop_media_server
- sensor.lightning_near_home_lightning_azimuth
- sensor.lightning_near_home_lightning_distance
- sensor.master_bedroom_active_app
- sensor.master_bedroom_active_app_id
- sensor.washer_power_stats
- sensor.westonspc_activewindow
# OPTIONAL Example automation to demonstrate how you can utilize this sensor, other examples in examples folder
# automation:
# - id: unavailable_entities_notification
# alias: "Unavailable Entities Notification"
# description: "Create persistent notification if unavailable entities, dismiss if none."
# mode: restart
# trigger:
# - platform: state
# entity_id: sensor.unavailable_entities
# attribute: entity_id
# to: ~
# condition:
# - condition: template
# alias: "Sensor state is a valid numerical value"
# value_template: >
# {{ is_number(trigger.from_state.state)
# and is_number(trigger.to_state.state) }}
# action:
# - if:
# - condition: numeric_state
# entity_id: sensor.unavailable_entities
# below: 1
# then:
# - service: persistent_notification.dismiss
# data:
# notification_id: unavailable_entities
# else:
# - service: persistent_notification.create
# data:
# notification_id: unavailable_entities
# title: "Unavailable Entities"
# message: "{{ state_attr('sensor.unavailable_entities', 'entity_id') | join('\n') }}"
I just added ignore_seconds back into the latest release (today). You weren’t the first person to ask for it. I figured it wouldn’t be necessary because you can adjust the time_pattern trigger, but I guess it is…
Thank you Jason. I’m still a monkey with home assistant, I must admit.
I figured there was a way to use the time pattern to do this. But then I realized that probably wouldn’t create a delay on the startup trigger which is where my problem is I believe.
Thank you that again I am also thankful the dashboard template you gave on the git.
Meh, even adjusting the time pattern trigger it would still pick up entities that had just become unavailable just before it ran so it’s not really the same thing. So the ignore_seconds parameter still has a purpose. Like I said, you weren’t the first to ask about it.
And thanks for reminding me about the startup trigger. I meant to remove it. It’s kind of redundant, it’s going to run with the time_pattern anyway. I’m going to delete it and redo the release.
That might actually be where your issue was, not the lack of ignore_seconds.
Ahh, I follow you now. Thank you for helping again. Your talent far outweighs mine. Thank you again for help everyone as this is a very useful one.
Hello everyone and I apologize if this is an easy question regarding this great template. Is there a way to have the template only update/ create a notification after a new unavailable device has been in the unavailable group for a certain amount of time.
As in, don’t send a message about an unavailable entity unless it’s been unavailable for 15 minutes or something like that. (The group hasn’t changed it’s entities for that period of time)
I’m not good enough at reading/ understanding the templates to know if it already does something of this nature or if that was never the intent.


