-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Device_tracker_Monitor_and_Notifier.yaml
464 lines (419 loc) · 17.7 KB
/
Device_tracker_Monitor_and_Notifier.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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
blueprint:
name: Notify if selected Device_Tracker goes down and do something about it - 2024-06-04
author: SirGoodenough
description: >
This is intended to be used with pfSense HACS Integration:
[GitHub - travisghansen/hass-pfsense: pfSense integration with Home Assistant ](https://github.com/travisghansen/hass-pfsense)
. However it could be used with any device tracker that reports ```home``` when the
device is up and something else when it isn't.
It will create a persistent notification when triggered.
Triggers / notifications can be enabled for a time period each day and/or for
specific days of the week. There is also the ability to roll your own specific
notification or other action as an action statement.
I also found that Awesome Blueprints Matt has a blueprint to send this stuff
to your phone, so I referenced that here to be helpful if you are looking for that.
If you want to send these notifications to a mobile device, i suggest you look at
the following blueprint to use in conjunction with this blueprint. I am not
affiliated with that, but decided I didn't want to re-invent the wheel as
mobile HA is not something I do every day.
[![Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.](https://my.home-assistant.io/badges/blueprint_import.svg)](https://my.home-assistant.io/redirect/blueprint_import/?blueprint_url=https%3A%2F%2Fgit.luolix.top%2FEPMatt%2Fawesome-ha-blueprints%2Fblob%2Fmain%2Fblueprints%2Fautomation%2Fpersistent_notification_to_mobile%2Fpersistent_notification_to_mobile.yaml)
## 🐘 Requirements
### Persistent Notification Integration Required
You must have this integration enabled on your system to run the automation, since
the these notifications are generated by this integration. This should be
activated in your HA Instance by default, so unless you tweaked the default
configuration, you're good to go.
### [Persistent Notification Integration Docs ](https://www.home-assistant.io/integrations/persistent_notification/)
[Community link for this blueprint ](https://community.home-assistant.io/t/device-tracker-monitor-notifier/500688)
## 🗿Notice👮🏿♂️:
* Copies of the original Blueprint that were converted via the 'Take Control'
feature or other means are officially not supported by me.
* I may or may not be able to support you when you have a problem after you make changes
to my code, as some of the code is no longer mine.
* I & my license also require attribution as a link back to the original
should you use this code in your own creation.
* [Here is a link to my license & the original github post](https://github.com/SirGoodenough/HA_Blueprints?tab=License-1-ov-file)
expected to be followed & referenced as attribution should you use this code elsewhere.
source_url: https://github.com/SirGoodenough/HA_Blueprints/blob/master/Automations/Device_tracker_Monitor_and_Notifier.yaml
domain: automation
homeassistant:
min_version: 2024.6.0
input:
required_inputs:
name: Required input 👀
icon: mdi:alert-box
collapsed: false
description: >
This input is required for the blueprint to function and must be filled in.
input:
trackees:
name: Devices to Track
description: >
Select all the devices that you would like to track with this
Blueprint. Multiples are allowed.
selector:
entity:
filter:
- domain: device_tracker
multiple: true
level_1:
name: First action to take
icon: mdi:clock-time-one
collapsed: true
description: >
The first time the problem is detected, these are the actions and parameters.
The Blueprint will not error, but won't actually do anything if no changes
are made to this section.
input:
gone_for:
name: Time delay before reporting outage 1st time
description: >
This variable is here to allow a time delay before the
Blueprint starts doing anything. Sometimes you have a thing that likes
to dissapear for a short time but usually finds it's way home.
(BUT sometimes doesn't)
Or you are using this Blueprint to run an automatic reset action but
need a delay to make sure that there actually is a problem.
00:00:00.00 is the default which means as soon as the devices go
to away, it triggers.
default:
hours: 0
minutes: 0
seconds: 0
selector:
duration:
alt_notify:
name: Manual Notifications Level 1
description: >
Enter the action yaml for any specific notification or action
you would like to perform on the first notification.
This can be anything from a custom pushbullet or text message, a message
to the system log, a manual event to trigger something else, or a simple
TTS message to your Google Speaker. It can also be all of these things
at once. It could even be something like a reboot command to
right the ship.
Any action yaml statement that is valid will be executed.
default: []
selector:
action: {}
level_2:
name: Second action to take
icon: mdi:clock-time-two
collapsed: true
description: >
The second time the problem is detected, these are the actions and parameters.
The Blueprint will work if no changes are made to this section.
input:
gone_for_longer:
name: Time delay before reporting outage 2nd time
description: >
This variable is here to allow a time delay before the
Blueprint triggers a second time.
This means it was off longer than the first delay and whatever
you did to recover the first time didn't work leaving the device
```not home```.
Is useful if you are using this BP to restart stuck devices.
Default is set to an hour but in general use it should be set to
a value greater than the first delay.
default:
hours: 1
minutes: 0
seconds: 0
selector:
duration:
alt_notify_2:
name: Manual Notifications Level 2
description: >
Enter the action yaml for any specific notification or action
you would like to perform on the second notification.
This is what to do after the 2nd trigger delay.
Any action yaml statement that is valid will be executed.
Default is nothing so only a normal notification will happen with the
2nd trigger if left blank.
default: []
selector:
action: {}
level_3:
name: Third action to take
icon: mdi:clock-time-three
collapsed: true
description: >
The third time the problem is detected, these are the actions and parameters.
The Blueprint will work if no changes are made to this section.
input:
gone_for_still_longer:
name: Time delay before reporting outage 3rd time
description: >
This variable is here to allow a time delay before the
Blueprint triggers a third time.
This means it was off longer than the first + second delay and whatever
you did to recover the first two times didn't work leaving the device
```not home```.
Is useful if you are using this BP to restart stuck devices.
Default is set to 4 hours but in general use it should be set to
a value greater than the second delay.
default:
hours: 4
minutes: 0
seconds: 0
selector:
duration:
alt_notify_3:
name: Manual Notifications Level 3
description: >
Enter the action yaml for any specific notification or action
you would like to perform on the third notification.
This is what to do after the 3rd trigger delay.
Any action yaml statement that is valid will be executed.
Default is nothing so only a normal notification will happen with the
3nd trigger if left blank.
default: []
selector:
action: {}
level_4:
name: Forth and final action to take
icon: mdi:clock-time-four
collapsed: true
description: >
The fourth and final time the problem is detected, these are the actions and parameters.
The Blueprint will work if no changes are made to this section.
input:
gone_for_still_more_longer:
name: Time delay before reporting outage 4th time
description: >
This variable is here to allow a time delay before the
Blueprint triggers a fourth time.
This means it was off longer than all the delays and whatever
you did to recover the times didn't work leaving the device
```not home```.
Is useful if you are using this BP to restart stuck devices.
Default is set to 6 hours but in general use it should be set to
a value greater than the third delay.
default:
hours: 6
minutes: 0
seconds: 0
selector:
duration:
alt_notify_4:
name: Manual Notifications Level 4
description: >
Enter the action yaml for any specific notification or action
you would like to perform on the fourth notification.
This is what to do after the 3rd trigger delay.
Any action yaml statement that is valid will be executed.
Default is nothing so only a normal notification will happen with the
3nd trigger if left blank.
default: []
selector:
action: {}
optional_parameters:
name: Optional parameters🤓
icon: mdi:alert-octagon-outline
collapsed: true
description: >
These inputs set optional parameters that allow you to customize the intended actions.
Read the individual descriptions for more details.
The Blueprint will work if no changes are made to this section.
input:
skip_p_notifcation:
name: 'Choose to send persistent notification (or not).'
description: >
on/true means a Persistent Notification is sent, off/false
means it is not.
If you set this to off and do not add a manual notification method,
this blueprint then does nothing.
default: true
selector:
boolean:
notification_id:
name: Optional Persistent Notification ID
description: >
This is an optional parameter to be used for notifications to
mobile devices and other things.
This will be converted to all letters and / or numbers with no spaces,
so keep that in mind when referencing it later.
If you put an ID in here, the first message that is triggered will lock in
until you clear it. This will prevent any further notifications from this
blueprint until you clear the old message.
If you don't know what this is for, you probably should leave it blank.
default: []
selector:
text: {}
notify_enable_time:
name: Time of day to begin notifications
description: >
Set this for the time of day you want to allow notifications to begin.
Leave as is to always be enabled.
default: 00:00:00
selector:
time: {}
notify_disable_time:
name: Time of day to end notifications
description: >
Set this for the time of day you want notificatons to end.
Leave as is to always be enabled.
default: 00:00:00
selector:
time: {}
weekday:
name: Day of the week to allow notifications
description: >
Change options if you want to include or exclude any specific day.
All days are selected by default.
default:
- mon
- tue
- wed
- thu
- fri
- sat
- sun
selector:
select:
options:
- label: Monday
value: mon
- label: Tuesday
value: tue
- label: Wednesday
value: wed
- label: Thursday
value: thu
- label: Friday
value: fri
- label: Saturday
value: sat
- label: Sunday
value: sun
custom_value: false
multiple: true
additional_conditions:
name: Additional conditions
description: |
Extra conditions you may want to add to this automation
(Example: Home occupied, TV on, etc)
default: []
selector:
condition:
trigger:
- platform: state
id: level_1
entity_id: !input trackees
from: "home"
for: !input gone_for
- platform: state
id: level_2
entity_id: !input trackees
from: "home"
for: !input gone_for_longer
- platform: state
id: level_3
entity_id: !input trackees
from: "home"
for: !input gone_for_still_longer
- platform: state
id: level_4
entity_id: !input trackees
from: "home"
for: !input gone_for_still_more_longer
variables:
# Get the alt_notify_1 into a variable to test it for empty later.
alt_notify_var: !input alt_notify
# Get the alt_notify_2 into a variable to test it for empty later.
alt_notify_2_var: !input alt_notify_2
# Get the alt_notify_3 into a variable to test it for empty later.
alt_notify_3_var: !input alt_notify_3
# Get the alt_notify_4 into a variable to test it for empty later.
alt_notify_4_var: !input alt_notify_4
# Get the notification_id into a variable.
notification_id_var: !input notification_id
# Strip weirdness from the user supplied notification_id.
notify_id: '{{ notification_id_var | regex_replace("[^A-Za-z0-9]", "") }}'
# Grab the triggered entity attributes.
attr_raw: '{{ states[trigger.to_state.entity_id] }}'
# Strip the beginning and end garbage from those attributes.
attr: '{{ attr_raw.split(''; '')[1].split(''>'')[0] }}'
condition:
- alias: Only allow execution within selected Hours / Weekdays
condition: time
after: !input 'notify_enable_time'
before: !input 'notify_disable_time'
weekday: !input 'weekday'
- alias: User pick
condition: !input additional_conditions
action:
- alias: 'Persistent Notifications. Options are skip it, use a notification_id, or default to no id'
choose:
- conditions: '{{ skip_p_notification== false }}'
sequence: []
- conditions: '{{ notify_id | length > 0 }}'
sequence:
- alias: Notify interested parties WITH notification_id
service: persistent_notification.create
data:
title: '{{ states[trigger.to_state.entity_id].name + '' Status'' }}'
message: '{{ states[trigger.to_state.entity_id].name + '' is '' + states[trigger.to_state.entity_id].state }}
Full Attributes List:
{{ ''notification_id='' + notify_id }}
{% for item in attr.split('' '') %}
{{ item | replace( '','', ''\n'') | replace( ''@'', ''\n'')}}
{%- endfor %}
'
notification_id: '{{ notify_id }}'
default:
- alias: Notify interested parties WITHOUT notification_id
service: persistent_notification.create
data:
title: '{{ states[trigger.to_state.entity_id].name + '' Status'' }}'
message: '{{ states[trigger.to_state.entity_id].name + '' is '' + states[trigger.to_state.entity_id].state }}
Full Attributes List:
{% for item in attr.split('' '') %}
{{ item | replace( '','', ''\n'') | replace( ''@'', ''\n'')}}
{%- endfor %}
'
- alias: All the custom code is fired here
choose:
- conditions:
- alias: Check for Alternate Notifications Level 1
condition: and
conditions:
- condition: trigger
id: level_1
- condition: template
value_template:
'{{ not alt_notify_var in (''none'', ''null'', ''unavailable'', '''') }}'
sequence: !input 'alt_notify'
- conditions:
- alias: Check for Alternate Notifications Level 2
condition: and
conditions:
- condition: trigger
id: level_2
- condition: template
value_template:
'{{ not alt_notify_2_var in (''none'', ''null'', ''unavailable'', '''') }}'
sequence: !input 'alt_notify_2'
- conditions:
- alias: Check for Alternate Notifications Level 3
condition: and
conditions:
- condition: trigger
id: level_3
- condition: template
value_template:
'{{ not alt_notify_3_var in (''none'', ''null'', ''unavailable'', '''') }}'
sequence: !input 'alt_notify_3'
- conditions:
- alias: Check for Alternate Notifications Level 4
condition: and
conditions:
- condition: trigger
id: level_4
- condition: template
value_template:
'{{ not alt_notify_4_var in (''none'', ''null'', ''unavailable'', '''') }}'
sequence: !input 'alt_notify_4'
mode: parallel
max: 15
max_exceeded: silent