-
Notifications
You must be signed in to change notification settings - Fork 6
/
notify_when_entities_unavailable.yaml
264 lines (231 loc) · 9 KB
/
notify_when_entities_unavailable.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#############################################################################################
################ DON'T FORGET TO CHANGE THE NOTIFICATION SERVICE IN LINE 50! ################
#############################################################################################
#######################################################
### Sensor for unavailable entities, also good for UI.
### Updates immediately as soon as entities change.
#######################################################
template:
- sensor:
- name: "Unavailable Entities"
state: "{{ expand('group.monitored_entities') | selectattr('state', 'in', ['unavailable', 'unknown', 'none']) | join(', ', attribute='attributes.friendly_name') | truncate(252) or 'Online' }}"
#######################################################
### Helper
#######################################################
input_text:
unavailable_entities_temp_state:
automation:
#######################################################
### Alert about entities becoming unavailable or online
#######################################################
- id: Unavailable Entities - Notify
alias: Unavailable Entities - Notify
variables:
from_state: "{{ states('input_text.unavailable_entities_temp_state') }}"
from_state_list: "{{ from_state.split(', ') }}"
to_state: "{{ trigger.to_state.state if trigger.to_state.state != 'Online' else '' }}"
to_state_list: "{{ to_state.split(', ') }}"
became_online: "{{ from_state_list | reject('in', to_state_list) | join(', ') }}"
became_unavailable_list: "{{ to_state_list | reject('in', from_state_list) | list }}"
became_unavailable: "{{ became_unavailable_list | join(', ') }}"
other_unavailable_entities: "{{ to_state_list | reject('in', became_unavailable_list) | join(', ') }}"
trigger:
- platform: state
entity_id: sensor.unavailable_entities
#Let other entities change as well so that we don't spam.
#Has to be a minimum of 1 second, otherwise you won't get ONLINE notifications (because of the way I wrote this).
for:
seconds: 10
action:
- service: notify.shlomi #Notifies me via telegram. Change this to your preferred service (such as: persistent_notification.create).
data:
message: |
{% if became_unavailable != '' -%}🚨 Became <b>UNAVAILABLE</b>: {{ became_unavailable }}
------{%- endif %}
{%- if became_online != ''%}
✅ Became <b>ONLINE</b>: {{ became_online }}
------{%- endif %}
{% if other_unavailable_entities != '' %}🚨 Still <b>UNAVAILABLE</b>: {{ other_unavailable_entities }}{% else %}✅ Everything else is ONLINE!{%- endif %}
- service: input_text.set_value
data:
entity_id: input_text.unavailable_entities_temp_state
value: ""
#######################################################
### When entities start changing,
### store the initial state temporarily so that
### we could tell which entities have changes.
#######################################################
- id: Unavailable Entities - Store Temp State
alias: Unavailable Entities - Store Temp State
mode: restart
trigger:
- platform: state
entity_id: sensor.unavailable_entities
condition:
alias: "Temp State is Empty"
condition: template
value_template: "{{ is_state('input_text.unavailable_entities_temp_state', '') }}"
action:
service: input_text.set_value
data:
entity_id: input_text.unavailable_entities_temp_state
value: "{{ '' if trigger.from_state.state == 'Online' else trigger.from_state.state }}"
#######################################################
### Enable/Disable notifications on HA start/shutdown
#######################################################
- id: Unavailable Entities - Pause Notifications on Start and Shutdown
alias: Unavailable Entities - Pause Notifications on Start and Shutdown
trigger:
- platform: homeassistant
event: start
id: turn_on
- platform: homeassistant
event: shutdown
id: turn_off
action:
- if:
- alias: "Home Assistant is starting, wait for 1 minute"
condition: template
value_template: "{{ trigger.id == 'turn_on' }}"
then:
delay:
minutes: 2
- service: "automation.{{ trigger.id }}"
data:
entity_id: automation.unavailable_entities_notify
#######################################################
### Group of monitored entities.
### Add any entities you want to be notified about.
#######################################################
group:
monitored_entities:
entities:
- light.living_room_side_lamp
- switch.living_room_entrance
- switch.living_room_hallway
- switch.living_room_main
- switch.living_room_tv_light
- light.living_room_curtain_light
- light.balcony_main
- light.balcony_string_lights
- switch.balcony_string_lights_toggle
- light.kitchen_counter
- switch.kitchen_island
- light.kitchen_pantry
- switch.hallway_toggle_front
- switch.hallway_toggle_back
- light.hallway_front
- light.hallway_back
- light.toilet_main
- light.office_bff_light
- light.office_bff_light_toggle
- light.office_main
- switch.office_main_toggle
- switch.guests_main
- switch.guests_main_toggle
- switch.bathroom_heater
- switch.water_boiler
- sensor.solar_system_temperature
- light.bathroom_main
- light.bathroom_laundry
- switch.riley_main
- switch.riley_scene_toggle
- sensor.riley_main_toggle
- light.bedroom_closet
- switch.bedroom_entrance
- switch.bedroom_entrance_toggle_left
- switch.bedroom_entrance_toggle_right
- switch.bedroom_main
- switch.bedroom_main_toggle_left
- switch.bedroom_main_toggle_right
- switch.bedroom_scene
- switch.bedroom_scene_left
- light.bedroom_scene_right
- binary_sensor.fridge
- binary_sensor.freezer
- binary_sensor.bedroom_closet_motion
- binary_sensor.bathroom_closet_leak
- binary_sensor.bathroom_floor_leak
- binary_sensor.kitchen_closet_leak
- binary_sensor.air_conditioner_leak
- switch.front_door_camera_module
- binary_sensor.toilet_presence
- binary_sensor.toilet_motion
- switch.subwoofer
- cover.living_room_shutter_switch
- cover.guests_shutter_switch
- cover.bedroom_shutter_switch
- cover.living_room_curtain
- cover.living_room_curtain_switch
- binary_sensor.balcony_window
- binary_sensor.kitchen_window
- binary_sensor.office_window
- binary_sensor.guests_window
- binary_sensor.riley_window
- binary_sensor.bedroom_window
- cover.office_shutter
- cover.office_curtain_motor
- cover.office_curtain_switch
- switch.lower_gate
- switch.upper_gate
- binary_sensor.doorbell
- remote.living_room
- remote.office
- remote.guests
- remote.riley
- remote.bedroom
- binary_sensor.rain
- switch.intercom
- light.stairs
- switch.stairs_toggle
- binary_sensor.stairs_motion
- sensor.living_room_climate_temperature
- sensor.office_climate_temperature
- sensor.guests_climate_temperature
- sensor.riley_climate_temperature
- sensor.bedroom_climate_temperature
- sensor.bedroom_closet_climate_temperature
- binary_sensor.bathroom_window
- switch.shelly_3em
- binary_sensor.big_freezer
- sensor.outside_climate_temperature
- cover.kitchen_shutter_switch
- cover.kitchen_curtain_switch
- cover.kitchen_curtain_motor
- lock.front_door
- cover.bedroom_curtain_motor
- cover.bedroom_curtain_switch
- switch.toilet_vent
- sensor.water_boiler_temperature
- sensor.riley_hue_remote_action
- sensor.shlomi_hue_remote_action
- sensor.inbal_hue_remote_action
- sensor.office_hue_remote_action
- sensor.toilet_light_toggle_action
- sensor.kitchen_light_toggle_action
- binary_sensor.riley_door
- binary_sensor.bedroom_door
- binary_sensor.toilet_door
- binary_sensor.bathroom_door
#Smoke Sensors
- binary_sensor.hallway_front_smoke
- binary_sensor.hallway_back_smoke
- binary_sensor.electricity_closet_smoke
#Fans
# - switch.gray_fan_smart_plug
- fan.living_room_fan
- fan.office_fan
# - fan.balcony_fan
# - fan.riley_fan
- fan.bedroom_fan
#Smart Plugs
# - switch.white_yule_tree
# - switch.green_yule_tree
# - switch.yogurt_maker
#TVs & Media Players
- media_player.living_room_tv
- media_player.bedroom_tv
- media_player.balcony_tv
#Laundry Machine
- binary_sensor.laundry_machine_door
- switch.laundry_machine