Help to migrate actionable notifications

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:

  1. Can it be paired down and simplified.
  2. 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"
  1. It doesn’t look bloated at first glance. What sections do you think need simplified?
  2. iOS and script section will change.
ios:

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
                    sound:
                      name: default
                      critical: 1
                      volume: 1.0
                    thread-id: "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
            - delay: '00:05:00'

I wasn’t sure. Just seemed like a lot of code. But if it looks good, cool.

Thanks! So the ios: section is just blank then?

As far as I can tell. That’s all I have on my config anymore.

Double checking the docs, it looks like in the script “identifier:” needs to be “action:” instead. I also had to change “actionName” in the automations to “action”

1 Like