-
Notifications
You must be signed in to change notification settings - Fork 21
/
package_unavailable_entities.yaml
88 lines (81 loc) · 3.43 KB
/
package_unavailable_entities.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
###################################################################################################
## 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"
unique_id: unavailable_entities
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', 'entity_id') %}
{{ entities | count if entities != none else -1 }}
# REQUIRED - Add individual entities to ignore to this group.
group:
ignored_entities:
entities: []
# REQUIRED - This is required to create and update the monitored entities group. Updates once every minute.
automation:
- id: update_unavailable_entities_group
alias: "Update Unavailable Entities Group"
description: "Update unavailable entities group."
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
entities: >
{{ states
| rejectattr('domain', 'in', ['button', 'conversation', 'event', 'group', 'image',
'input_button', 'input_text', 'remote', 'tts', 'scene', 'stt'])
| rejectattr('entity_id', 'in', state_attr('group.ignored_entities', 'entity_id'))
| rejectattr('entity_id', 'eq', 'group.unavailable_entities')
| 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
alias: "Unavailable Entities Notification"
description: "Create persistent notification if unavailable entities, dismiss if none."
mode: restart
triggers:
- trigger: state
entity_id: group.unavailable_entities
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')) }}"
actions:
- if:
- condition: numeric_state
entity_id: sensor.unavailable_entities
below: 1
then:
- action: persistent_notification.dismiss
data:
notification_id: unavailable_entities
else:
- action: persistent_notification.create
data:
notification_id: unavailable_entities
title: "Unavailable Entities"
message: "{{ state_attr('group.unavailable_entities', 'entity_id') | join('\n') }}"