-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunavailable_entities_notification-exclude-updates.yaml
182 lines (160 loc) · 5.75 KB
/
unavailable_entities_notification-exclude-updates.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
blueprint:
name: Unavailable entity detection & notification (Exclude Updates)
description: Regularly test all entities' status to check for unavailability.
domain: automation
source_url: https://github.com/DanGarion/ha-blueprint-tweaks/edit/main/unavailable_entities_notification-exclude-updaetes.yaml
# Blueprint Inputs
input:
time:
name: Time to test on
description: Test is run at configured time
default: '10:00:00'
selector:
time: {}
monday_enabled:
name: 'Monday'
description: 'Run test on Monday'
default: True
selector:
boolean:
tuesday_enabled:
name: Tuesday
description: 'Run test on Tuesday'
default: True
selector:
boolean:
wednesday_enabled:
name: Wednesday
description: 'Run test on Wednesday'
default: True
selector:
boolean:
thursday_enabled:
name: Thursday
description: 'Run test on Thursday'
default: True
selector:
boolean:
friday_enabled:
name: Friday
description: 'Run test on Friday'
default: True
selector:
boolean:
saturday_enabled:
name: Saturday
description: 'Run test on Saturday'
default: True
selector:
boolean:
sunday_enabled:
name: Sunday
description: 'Run test on Sunday'
default: True
selector:
boolean:
exclude:
name: Excluded Entities
description: Entities (e.g. smartphone) to exclude from detection. Only entities and devices are supported, areas must be expanded!
default: {}
selector:
target:
actions:
name: Actions
description: Notifications or similar to be run. {{entities}} is replaced with the names of unavailable entities.
selector:
action:
# Variables used in the automation
variables:
monday_enabled: !input 'monday_enabled'
tuesday_enabled: !input 'tuesday_enabled'
wednesday_enabled: !input 'wednesday_enabled'
thursday_enabled: !input 'thursday_enabled'
friday_enabled: !input 'friday_enabled'
saturday_enabled: !input 'saturday_enabled'
sunday_enabled: !input 'sunday_enabled'
current_day: '{{ now().weekday() | int }}'
exclude: !input 'exclude'
entities: >-
{% set result = namespace(includedEntities=[], excludedEntities = []) %}
{% if exclude.entity_id is defined %}
{% set result.excludedEntities = result.excludedEntities + ([exclude.entity_id] if exclude.entity_id is string else exclude.entity_id) %}
{% endif %}
{% if exclude.device_id is defined %}
{% if exclude.device_id is not list %}
{% set device_id_list = [exclude.device_id] %}
{% else %}
{% set device_id_list = exclude.device_id %}
{% endif %}
{% for device_id in device_id_list %}
{% set result.excludedEntities = result.excludedEntities + device_entities(device_id) %}
{% endfor %}
{% endif %}
{% if exclude.label_id is defined %}
{% if exclude.label_id is not list %}
{% set label_id_list = [exclude.label_id] %}
{% else %}
{% set label_id_list = exclude.label_id %}
{% endif %}
{% for label_id in label_id_list %}
{% set result.excludedEntities = result.excludedEntities + label_entities(label_id) %}
{% for area in label_areas(label_id) %}
{% set result.excludedEntities = result.excludedEntities + area_entities(area) %}
{% for device in area_devices(area) %}
{% set result.excludedEntities = result.excludedEntities + device_entities(device) %}
{% endfor %}
{% endfor %}
{% for device in label_devices(label_id) %}
{% set result.excludedEntities = result.excludedEntities + device_entities(device) %}
{% endfor %}
{% endfor %}
{% endif %}
{% if exclude.area_id is defined %}
{% if exclude.area_id is not list %}
{% set area_id_list = [exclude.area_id] %}
{% else %}
{% set area_id_list = exclude.area_id %}
{% endif %}
{% for area_id in area_id_list %}
{% set result.excludedEntities = result.excludedEntities + area_entities(area_id) %}
{% for device in area_devices(area_id) %}
{% set result.excludedEntities = result.excludedEntities + device_entities(device) %}
{% endfor %}
{% endfor %}
{% endif %}
{% for state in states | selectattr('state', 'eq', 'unavailable') %}
{% if state.state == 'unavailable' and not state.entity_id in result.excludedEntities and (not device_id(state.entity_id) or not device_attr(device_id(state.entity_id), 'disabled_by')) %}
{% if 'update' not in state.entity_id %}
{% set result.includedEntities = result.includedEntities + [state.name] %}
{% endif %}
{% endif %}
{% endfor %}
{{"⤵ \n- "}}{{result.includedEntities|join('\n- ')}}
# Triggers
trigger:
- platform: time
at: !input 'time'
# Conditions used to determine if the automation should run for the specific trigger event
condition:
# Check if the automation is supposed to be executed during that specific weekday
- condition: template
value_template: >-
{{
(current_day == 0 and monday_enabled) or
(current_day == 1 and tuesday_enabled) or
(current_day == 2 and wednesday_enabled) or
(current_day == 3 and thursday_enabled) or
(current_day == 4 and friday_enabled) or
(current_day == 5 and saturday_enabled) or
(current_day == 6 and sunday_enabled)
}}
# Check if the entities list is not empty
- condition: template
value_template: >-
{{ entities != "⤵ \n-"}}
# Actions
action:
- choose: []
default: !input 'actions'
mode: single
max_exceeded: silent