I have an actionable notification setup to give me an alert when my garage door is open after dark. I have two actions: Close Garage and Mute Alert. The catch is that I set up the alert with a script so that it could be repeated every 5 minutes if not acted upon. I am trying to figure out two things:
- Can it be paired down and simplified.
- It needs to be migrated away from using categories as explained here, but I cannot quite figure it out because of the complexity of my actions. Does the IOS section change? The script? The action automations? How do I handle setting the alert as critical?
Below is code that I am currently using:
#### Helpers
input_boolean:
away_mode:
name: Away Mode
initial: off
garage_alert:
name: Garage Alert
initial: off
garage_alert_mute:
name: Garage Alert Mute
#### Initial Automation triggered by garage door being open after dark
automation:
alias: 'Garage Alert'
initial_state: true
trigger:
- platform: template
value_template: "{{ is_state('cover.garage_door', 'open') and is_state('binary_sensor.afterdark', 'on') and is_state('input_boolean.away_mode', 'off') }}"
for: '00:02:00'
- platform: template
value_template: "{{ is_state('cover.garage_door', 'open') and is_state('input_boolean.away_mode', 'on') }}"
action:
- service: input_boolean.turn_on
entity_id: input_boolean.garage_alert
- service: script.garage_alert
#### Script executed by automation so that the notification is critical and repeats every 5 minutes
script:
garage_alert:
sequence:
- alias: Garage alert repeat
repeat:
while:
- condition: state
entity_id: input_boolean.garage_alert
state: 'on'
- condition: state
entity_id: input_boolean.garage_alert_mute
state: 'off'
- condition: template
value_template: "{{ repeat.index <= 60 }}"
sequence:
- service: notify.mobile_app_victorc_iphone
data:
title: "Warning"
message: "Garage Door is Open"
data:
apns_headers:
'apns-collapse-id': 'garage-alerts'
push:
badge: 1
category: "garage_alert"
sound:
name: default
critical: 1
volume: 1.0
thread-id: "garage-alert"
- delay: '00:05:00'
#### IOS actionable notificatioins
ios:
push:
categories:
- name: Garage Alert
identifier: 'garage_alert'
actions:
- identifier: 'CLOSE_GARAGE'
title: 'Close Garage'
activationMode: 'background'
authenticationRequired: true
destructive: false
- identifier: 'MUTE_GARAGE_ALERT'
title: 'Mute Alert'
activationMode: 'background'
authenticationRequired: true
destructive: false
#### Automations associated wth the IOS actions
automation:
- alias: 'Mute Garage Alert'
trigger:
platform: event
event_type: ios.notification_action_fired
event_data:
actionName: MUTE_GARAGE_ALERT
action:
service: input_boolean.turn_on
data:
entity_id: input_boolean.garage_alert_mute
- alias: 'Close Garage Door'
trigger:
platform: event
event_type: ios.notification_action_fired
event_data:
actionName: CLOSE_GARAGE
action:
service: cover.close_cover
entity_id: cover.garage_door
- alias: 'Garage Door Closed'
trigger:
platform: state
entity_id: cover.garage_door
to: 'closed'
condition:
condition: state
entity_id: input_boolean.garage_alert
state: 'on'
action:
- service: input_boolean.turn_off
data:
entity_id:
- input_boolean.garage_alert
- input_boolean.garage_alert_mute
- delay: 00:00:10
- service: notify.mobile_app_victorc_iphone
data:
message: "Garage Door is Closed"
data:
push:
badge: 0
thread-id: "garage-alert"