forked from panhans/HomeAssistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentity_state_persistent_notification.yaml
557 lines (467 loc) · 16.9 KB
/
entity_state_persistent_notification.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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
blueprint:
name: "Entity State Notification"
description: "
**Features**
- monitor entities for a specific state and trigger a notification
- modify message, title, icon, color, channel, group etc
- persistent notification until entity leaves specified state
- periodical notification with stop functionality
- custom actions
- custom conditions
**Hints**
- if you want to test this automation, you need to change the state of an observed person. you can do this, in the developer options. Simply filter for your person entity, click on it and change the state to a zone used by this automation.
**Help & FAQ**: [Entity State Notification](https://community.home-assistant.io/t/entity-state-notification)
**Version**: 2.4.1
If you like my work and support feel free to support me.
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Q5Q3QEH52)
"
source_url: https://github.com/panhans/homeassistant/blob/main/blueprints/automation/panhans/entity_state_persistent_notification.yaml
domain: automation
input:
sensor_section:
name: Sensors
icon: mdi:broadcast
collapsed: true
input:
sensor_entity:
name: "🖲️ Observed Entities"
description: >
`target`
Entities which trigger the notification.
selector:
entity:
multiple: true
active_state:
name: "🟢 Notification State"
description: >
`target`
Target state that triggers the automation.
default: "on"
for_time_m:
name: "⏲️ State Duration"
description: >
`target`
Duration the entity must be in target state.
default:
hours: 0
minutes: 0
seconds: 0
selector:
duration:
mobile_notifcation_section:
name: Mobile Notification Settings
icon: mdi:chat
collapsed: true
input:
notify_device:
name: "📱 Device to notify"
description: >
`notification`
Device which gets a notification.
default:
selector:
device:
filter:
integration: mobile_app
notify_group:
name: "🫂 Notification Group"
description: >
`notification`
The name of the notification group to call. ('notify' for all devices)
default: ""
title:
name: "📕 Notification Title"
description: >
`notification`
Headline of your notifications.
default: "{{ entity_name }} is {{ active_state }}"
message:
name: "💬 Notification Message"
description: >
`notification`
Content of your notifications.
default: "Keep in mind: {{ entity_name }} is {{ active_state }}"
persistent_notification:
name: "🪨 Persistent Notification"
description: >
`notification`
If turned on you can't swipe away the notification. It only disappears if the observed entity leave the target state.
default: true
selector:
boolean:
ha_notification:
name: "🏠 Persistent HomeAssistant Notification"
description: >
`notification`
Creates a notification in your home assistant frontend.
default: false
selector:
boolean:
peridodic_notification_section:
name: Periodic Notification Settings
icon: mdi:refresh
collapsed: true
input:
period:
name: "🔄 Periodical Notification"
description: >
`periodical` `notification`
Sends notification periodically. 0 means off.
default:
hours: 0
minutes: 0
seconds: 0
selector:
duration:
stop_button_text:
name: "💬 Stop Button Text"
description: >
`periodical` `optional`
Text for stop button in the notification to interrupt the periodical send notifications.
default: "Stop notifying"
# periodic_importance:
# name: 🎛️ Notification Importance
# description: >
# `periodical`
# Set the importance of periodic notifications. The importance of the **first** notification will be take from the *Mobile Notification Appearance* section.
# Read [this](https://developer.android.com/develop/ui/views/notifications/channels?hl=de#importance) for further explanations.
# default: "high"
# selector:
# select:
# options:
# - high
# - default
# - low
# - min
# - none
mobile_appearance_section:
name: Mobile Notification Appearance
icon: mdi:palette
collapsed: true
input:
status_bar_icon:
name: "🌠 Status Bar Icon"
description: >
`Android` `optional`
Sets the status bar icon.
default: mdi:home-assistant
selector:
icon:
placeholder: mdi:home-assistant
# notification_importance:
# name: 🎛️ Notification Importance
# description: >
# `importance`
# Set the importance of periodic notifications.
# Read [this](https://developer.android.com/develop/ui/views/notifications/channels?hl=de#importance) for further explanations.
# default: "high"
# selector:
# select:
# options:
# - high
# - default
# - low
# - min
# - none
notification_color:
name: "🎨 Notification Color"
description: >
`Android` `optional`
Color of the notification
default: [100, 200, 240]
selector:
color_rgb:
channel:
name: "📭 Notification Channel"
description: >
`Android` `optional`
You can set a notification channel. In your companion app you can set e.g. a custom sound for notifications in this channel.
default: "General"
group:
name: "📑 Notification Group"
description: >
`Android` `optional`
Group notifications by using this identifier.
default: "espn-notification-group"
vibration_pattern:
name: "📳 Vibration Pattern"
description: >
`Android` `optional`
Pattern of the vibration when notification arrives."
default: "100, 100"
led_color:
name: "💡 Notification LED Color"
description: >
`Android` `optional`
Color of the phone LED after incoming notification."
default: [100, 200, 240]
selector:
color_rgb:
custom_section:
name: Custom Actions / Conditions
icon: mdi:cog
collapsed: true
input:
custom_condition:
name: "❌ Conditions"
description: >
`optional`
Condition that must be met for the notification to be triggered.
default: []
selector:
condition:
custom_action_on:
name: "🎬 Custom Action On"
description: >
`optional`
Custom action when your observed entity enters the target states.
default: []
selector:
action: {}
custom_action_off:
name: "🎬 Custom Action Off"
description: >
`optional`
Custom action when observed entity leave the target state. Keep in mind this action also will be fired if your custom condition doesn't match.
default: []
selector:
action: {}
variables:
active_state: !input active_state
sensor_entity: !input sensor_entity
group_target: !input notify_group
ha_notification: !input ha_notification
notify_device: !input notify_device
period: !input period
action_prefix: "STOP_{{this.entity_id}}"
notification_color: !input "notification_color"
notification_color_hex: "#{{ '%02x%02x%02x' | format(notification_color[0], notification_color[1], notification_color[2]) }}"
led_color: !input "led_color"
led_color_hex: "#{{ '%02x%02x%02x' | format(led_color[0], led_color[1], led_color[2]) }}"
# notification_importance: !input notification_importance
# periodic_importance: !input periodic_importance
trigger:
- platform: state
entity_id: !input "sensor_entity"
to: !input active_state
for: !input for_time_m
id: "on"
- platform: state
entity_id: !input "sensor_entity"
from: !input active_state
id: "off"
- platform: event
event_type: pntc_event
id: "period"
condition:
- condition: or
conditions:
- condition: and
conditions:
- condition: template
value_template: "{{ trigger.id == 'on' }}"
- condition: and
conditions: !input custom_condition
- condition: template
value_template: "{{ trigger.id == 'off' }}"
- condition: and
conditions:
- condition: template
value_template: "{{ trigger.id == 'period' and trigger.event.data.automation == this.entity_id }}"
- condition: and
conditions: !input custom_condition
action:
- variables:
is_period_trigger: "{{ trigger.id == 'period' }}"
sensor: |
{% if is_period_trigger %}
{{ trigger.event.data.s_entity }}
{% else %}
{{ trigger.from_state.entity_id }}
{% endif %}
entity_name: "{{ state_attr(sensor,'friendly_name') }}"
tag: "{{ this.entity_id.split('.')[1] + sensor.split('.')[1] }}"
action_tag: "{{ action_prefix }}_{{ sensor }}"
# importance: |
# {% if is_period_trigger %}
# {{ periodic_importance }}
# {% else %}
# {{ notification_importance }}
# {% endif %}
st_last_changed: |
{% if is_period_trigger %}
{{ trigger.event.data.st_last_changed }}
{% else %}
{{ as_timestamp([sensor] | expand | map(attribute='last_changed') | first) }}
{% endif %}
- if:
- condition: template
value_template: "{{ is_period_trigger or trigger.to_state.state == active_state }}"
then:
- if:
- condition: template
value_template: "{{ notify_device != none }}"
then:
- if:
- condition: template
value_template: "{{ now() != now() + timedelta(**period) }}"
then:
- service: 'notify.mobile_app_{{ device_attr(notify_device, "name") | slugify }}'
data:
title: !input title
message: !input message
data:
ttl: 0
priority: high
notification_icon: !input "status_bar_icon"
tag: "{{ tag }}"
persistent: !input persistent_notification
sticky: !input persistent_notification
channel: !input "channel"
group: !input "group"
color: "{{ notification_color_hex }}"
vibrationPattern: !input "vibration_pattern"
ledColor: "{{led_color_hex}}"
# importance: "{{ importance }}"
actions:
- action: "{{ action_tag }}"
title: !input stop_button_text
else:
- service: 'notify.mobile_app_{{ device_attr(notify_device, "name") | slugify }}'
data:
title: !input title
message: !input message
data:
ttl: 0
priority: high
notification_icon: !input "status_bar_icon"
tag: "{{ tag }}"
persistent: !input persistent_notification
sticky: !input persistent_notification
channel: !input "channel"
group: !input "group"
color: "{{ notification_color_hex }}"
# importance: "{{ importance }}"
vibrationPattern: !input "vibration_pattern"
ledColor: "{{led_color_hex}}"
- if:
- condition: template
value_template: "{{ group_target is defined and group_target != '' }}"
then:
- if:
- condition: template
value_template: "{{ now() != now() + timedelta(**period) }}"
then:
- service: notify.{{ group_target }}
data:
title: !input title
message: !input message
data:
ttl: 0
priority: high
notification_icon: !input "status_bar_icon"
tag: "{{ tag }}"
persistent: !input persistent_notification
sticky: !input persistent_notification
channel: !input "channel"
group: !input "group"
color: "{{ notification_color_hex }}"
vibrationPattern: !input "vibration_pattern"
ledColor: "{{led_color_hex}}"
# importance: "{{ importance }}"
actions:
- action: "{{ action_tag }}"
title: !input stop_button_text
else:
- service: notify.{{ group_target }}
data:
title: !input title
message: !input message
data:
ttl: 0
priority: high
notification_icon: !input "status_bar_icon"
tag: "{{ tag }}"
persistent: !input persistent_notification
sticky: !input persistent_notification
channel: !input "channel"
group: !input "group"
# importance: "{{ importance }}"
color: "{{ notification_color_hex }}"
vibrationPattern: !input "vibration_pattern"
ledColor: "{{led_color_hex}}"
- if:
- condition: template
value_template: "{{ ha_notification }}"
then:
- service: persistent_notification.create
data:
title: !input title
message: !input message
notification_id: "{{ tag }}"
else:
- service: notify.notify
data:
data:
tag: "{{ tag }}"
ttl: 0
priority: high
message: clear_notification
- service: persistent_notification.dismiss
data:
notification_id: "{{ tag }}"
- if:
- condition: template
value_template: "{{ now() != now() + timedelta(**period) }}"
- condition: template
value_template: "{{ trigger.id != 'off' }}"
then:
- wait_for_trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: "{{ action_tag }}"
timeout: !input period
- variables:
s_last_changed: |
{{ as_timestamp([sensor] | expand | map(attribute='last_changed') | first) }}
- service: system_log.write
data:
level: debug
message: >
Last Changed {{ s_last_changed }} Last Change Trigger {{ st_last_changed }}
- if:
- condition: template
value_template: "{{ states(sensor) == active_state }}"
- condition: template
value_template: "{{ wait.trigger == none }}"
- condition: template
value_template: "{{ st_last_changed == s_last_changed }}"
then:
- event: pntc_event
event_data:
s_entity: "{{ sensor }}"
automation: "{{ this.entity_id }}"
st_last_changed: "{{ s_last_changed }}"
- if:
- condition: template
value_template: "{{ is_period_trigger or trigger.to_state.state == active_state }}"
then:
- variables:
custom_action_on: !input custom_action_on
- if:
- condition: template
value_template: "{{ custom_action_on != none }}"
then:
- choose: []
default: !input "custom_action_on"
else:
- variables:
custom_action_on: !input custom_action_off
- if:
- condition: template
value_template: "{{ custom_action_off != none }}"
then:
- choose: []
default: !input "custom_action_off"
mode: parallel