Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 35 additions & 19 deletions blueprints/automation/consumable_notification.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ blueprint:
Create a notification when a consumable reaches its warning threshold,
and update it when the consumable is fully depleted. The notification
is dismissed when the consumable is replaced. Supports persistent
notifications (default) or mobile app notifications.
notifications and/or mobile app notifications.
domain: automation
input:
consumable_sensor:
Expand All @@ -26,12 +26,18 @@ blueprint:
min: 0
max: 365
unit_of_measurement: days
persistent_notification:
name: Persistent Notification
description: >-
Show a persistent notification in the Home Assistant UI.
default: true
selector:
boolean:
notify_devices:
name: Mobile Devices (Optional)
description: >-
Select devices running the official Home Assistant app to receive
notifications. Leave empty to use persistent notifications in the
Home Assistant UI.
notifications.
default: []
selector:
device:
Expand All @@ -50,6 +56,7 @@ triggers:
variables:
consumable_sensor: !input consumable_sensor
warning_days_override: !input warning_days_override
persistent_notification: !input persistent_notification
notify_devices: !input notify_devices
use_mobile: "{{ notify_devices | length > 0 }}"
device_name: "{{ device_attr(consumable_sensor, 'name') }}"
Expand All @@ -70,6 +77,15 @@ actions:
- condition: template
value_template: "{{ is_depleted }}"
sequence:
- if:
- condition: template
value_template: "{{ persistent_notification }}"
then:
- action: persistent_notification.create
data:
title: "{{ display_name }} Needs Replacement"
message: "{{ device_link }} {{ consumable_name }} is due for replacement."
notification_id: "{{ notification_id }}"
- if:
- condition: template
value_template: "{{ use_mobile }}"
Expand All @@ -84,16 +100,19 @@ actions:
data:
tag: "{{ notification_id }}"
clickAction: "{{ device_url }}"
else:
- action: persistent_notification.create
data:
title: "{{ display_name }} Needs Replacement"
message: "{{ device_link }} {{ consumable_name }} is due for replacement."
notification_id: "{{ notification_id }}"
- conditions:
- condition: template
value_template: "{{ is_warning }}"
sequence:
- if:
- condition: template
value_template: "{{ persistent_notification }}"
then:
- action: persistent_notification.create
data:
title: "{{ display_name }} Replacement Soon"
message: "{{ device_link }} {{ consumable_name }} has {{ days_remaining }} days remaining."
notification_id: "{{ notification_id }}"
- if:
- condition: template
value_template: "{{ use_mobile }}"
Expand All @@ -108,16 +127,17 @@ actions:
data:
tag: "{{ notification_id }}"
clickAction: "{{ device_url }}"
else:
- action: persistent_notification.create
data:
title: "{{ display_name }} Replacement Soon"
message: "{{ device_link }} {{ consumable_name }} has {{ days_remaining }} days remaining."
notification_id: "{{ notification_id }}"
- conditions:
- condition: template
value_template: "{{ is_normal }}"
sequence:
- if:
- condition: template
value_template: "{{ persistent_notification }}"
then:
- action: persistent_notification.dismiss
data:
notification_id: "{{ notification_id }}"
- if:
- condition: template
value_template: "{{ use_mobile }}"
Expand All @@ -130,7 +150,3 @@ actions:
message: "clear_notification"
data:
tag: "{{ notification_id }}"
else:
- action: persistent_notification.dismiss
data:
notification_id: "{{ notification_id }}"