diff --git a/blueprints/automation/consumable_notification.yaml b/blueprints/automation/consumable_notification.yaml index 7fb938f..c60f337 100644 --- a/blueprints/automation/consumable_notification.yaml +++ b/blueprints/automation/consumable_notification.yaml @@ -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: @@ -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: @@ -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') }}" @@ -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 }}" @@ -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 }}" @@ -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 }}" @@ -130,7 +150,3 @@ actions: message: "clear_notification" data: tag: "{{ notification_id }}" - else: - - action: persistent_notification.dismiss - data: - notification_id: "{{ notification_id }}"