Skip to content

Instantly share code, notes, and snippets.

@pdjohntony
Last active November 20, 2022 18:17
Show Gist options
  • Select an option

  • Save pdjohntony/696cba4256446e4c48a8154247503918 to your computer and use it in GitHub Desktop.

Select an option

Save pdjohntony/696cba4256446e4c48a8154247503918 to your computer and use it in GitHub Desktop.
ha-bp-repeating-reminder-notification
blueprint:
name: Repeating Reminder Notification
description: |
Trigger an alert based on the state of a given sensor.
The Alert is send to a mobile app device and repeats as long as the sensor is in the given state.
An additonal action can be specified. This might be useful to tts the message.
Modified from "Nagging Alerting Notification Automation"
## Changes made
Added high priorty
Added support for custom notification channel
Added support for custom notification tag
Added support for custom notification color
Fixed inputs for group_targets
---------------------------------------------------------------------------------------------------------------------------
domain: automation
source_url: https://gist.github.com/pdjohntony/696cba4256446e4c48a8154247503918
input:
sensor_entity:
name: Sensor Entity
description: "Sensor that triggers an alert"
default:
selector:
entity:
alert_state:
name: Sensor Alert state
description: "Sensor state that triggers the alert notification"
default: "on"
initial_delay:
name: Initial Alert Delay
description: "Time to wait until an alert notification will be send (inital)"
default: 120
selector:
number:
min: 0
max: 1440
unit_of_measurement: minutes
repeat_delay:
name: Repeat Alert Delay
description: "Time to wait until an alert notification will be send (subsequently)"
default: 120
selector:
number:
min: 0
max: 1440
unit_of_measurement: minutes
max_alerts:
name: Max Alert Notifications
description: "How often should the alert get triggered while the alert is active"
default: 3
selector:
number:
min: 0
max: 100
unit_of_measurement: count
notify_device:
name: Device to notify
description: "Device needs to run the official Home Assistant app to receive notifications."
default: false
selector:
device:
integration: mobile_app
notify_group:
name: Notification Group
description: The name of the notification group to call.
default: ""
notify_message:
name: Notifcation Message (Optional)
description: 'Default: "Alert {{ entity_name }} triggered"'
default: "Alert {{ entity_name }} triggered"
resolved_message:
name: Message when the alert is resolved (Optional)
description: 'Default: "Alert {{ entity_name }} resolved"'
default: ""
alert_action:
name: Alert Action (Optional)
description: "Action to run while the alert is active. You can reuse the {{ notify_message }} variable"
default: []
selector:
action:
resolved_action:
name: Resolved Action (Optional)
description: "Action to run after an alert was resolved. You can reuse the {{ resolved_message }} variable"
default: []
selector:
action:
dismiss_entity:
name: Dismiss Alert (Optional)
description: "Input Boolean to dismiss an alert"
default:
selector:
entity:
domain: input_boolean
condition_entity:
name: Condition Entity (Optional)
description: "Condition Entity before an alert gets triggered"
default:
selector:
entity:
condition_entity_state:
name: Condition Entity state (Optional)
description: "State of the condition entity"
default: "on"
notification_channel:
name: Notification Channel
description: Notification Channel to use, allows you to use a custom notification sound in your phone.
default: "General"
notification_tag:
name: Notification Tag
description: Notification Tag to use, allows you to update/overwrite/removew notifications.
default:
notification_color:
name: Notification Color
description: Color of the notification. You may use color names like blue or red, or hex format #FF0042
default: "blue"
mode: restart
max_exceeded: silent
variables:
sensor_entity: !input sensor_entity
entity_name: "{{ state_attr(sensor_entity,'friendly_name') }}"
notify_message: !input notify_message
resolved_message: !input resolved_message
alert_action: !input alert_action
alert_state: !input alert_state
dismiss_entity: !input dismiss_entity
resolved_action: !input resolved_action
send_notification: "false"
initial_delay: !input initial_delay
repeat_delay: !input repeat_delay
condition_entity: !input condition_entity
condition_entity_state: !input condition_entity_state
group_target: !input notify_group
notification_channel: !input notification_channel
notification_tag: !input notification_tag
notification_color: !input notification_color
trigger:
- platform: state
entity_id: !input sensor_entity
to: !input alert_state
- platform: homeassistant
event: start
condition:
- condition: template
value_template: "{{ is_state(sensor_entity, alert_state) }}"
- condition: template
value_template: "{{ condition_entity == None or is_state(condition_entity, condition_entity_state) }}"
action:
- choose:
- conditions: "{{ dismiss_entity != None }}"
sequence:
- service: input_boolean.turn_on
data:
entity_id: !input dismiss_entity
# Initial Wait
- wait_for_trigger:
- platform: template
value_template: "{{ not is_state(sensor_entity, alert_state)}}"
- platform: template
value_template: "{{ dismiss_entity != None and not is_state(dismiss_entity, 'on') }}"
timeout:
minutes: !input initial_delay
# None = alert was not resolved or dimissed in the specified wait-time thus we need to send notifications.
- variables:
send_notification: "{{ wait.trigger == None }}"
- repeat:
count: !input max_alerts
sequence:
- variables:
repeat_count: "{{ repeat.index }}"
# Break conditions (aka. stop the loop)
- condition: template
value_template: "{{ is_state(sensor_entity, alert_state)}}"
- condition: template
value_template: "{{ dismiss_entity == None or is_state(dismiss_entity, 'on') }}"
- choose:
- conditions: "{{ not group_target }}"
sequence:
# Notification Actions
- domain: mobile_app
type: notify
device_id: !input notify_device
# Bug: Expressions defined in the notify_message are not resolved within the scope of the sequence
message: !input notify_message
data:
priority: high
channel: '{{notification_channel}}'
tag: '{{notification_tag}}'
color: '{{notification_color}}'
- choose:
- conditions: "{{ alert_action is defined and alert_action|length > 0 }}"
sequence: !input alert_action
- conditions: "{{ group_target is defined }}"
sequence:
- service: "notify.{{ group_target }}"
data:
message: !input notify_message
data:
priority: high
channel: '{{notification_channel}}'
tag: '{{notification_tag}}'
color: '{{notification_color}}'
- choose:
- conditions: "{{ alert_action is defined and alert_action|length > 0 }}"
sequence: !input alert_action
# Wait
- wait_for_trigger:
- platform: template
value_template: "{{ not is_state(sensor_entity, alert_state)}}"
- platform: template
value_template: "{{ dismiss_entity != None and not is_state(dismiss_entity, 'on') }}"
timeout:
minutes: !input repeat_delay
# Repeat finished
- choose:
# If Alert was dismissed
- conditions: "{{ send_notification and dismiss_entity != None and not is_state(dismiss_entity, 'on') }}"
sequence:
- service: system_log.write
data:
message: "Alert {{ entity_name }} dismissed"
level: warning
# If Alert was resolved
- conditions: "{{ resolved_message != None and send_notification and not is_state(sensor_entity, alert_state) }}"
sequence:
- choose:
- conditions: "{{ not group_target }}"
sequence:
- domain: mobile_app
type: notify
device_id: !input notify_device
message: !input resolved_message
data:
priority: high
channel: '{{notification_channel}}'
tag: '{{notification_tag}}'
color: '{{notification_color}}'
- choose:
- conditions: "{{ resolved_action is defined and resolved_action|length > 0 }}"
sequence: !input resolved_action
- conditions: "{{ group_target is defined }}"
sequence:
- service: "notify.{{ group_target }}"
data:
message: !input resolved_message
data:
priority: high
channel: '{{notification_channel}}'
tag: '{{notification_tag}}'
color: '{{notification_color}}'
- choose:
- conditions: "{{ resolved_action is defined and resolved_action|length > 0 }}"
sequence: !input resolved_action
- choose:
- conditions: "{{ dismiss_entity != None }}"
sequence:
- service: input_boolean.turn_off
data:
entity_id: !input dismiss_entity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment