Assistance with iPhone notification actions & the alert integration

I’m trying to setup a system where, when any of a couple of contact sensors are opened:

  • a critical alert is sent to my iPhone as a notification (via an automation), with the option to acknowledge / silence it
  • if not acknowledged / silenced initially, repeated non-critical alerts are sent to the same phone via notification (via the alert integration), until the contact sensor either closes or I acknowledge / silence the ongoing alerts.

The code I’m using at the moment is as follows (with dummy sensor names):

automations:
  - id: 'automation_door_opened_critical_alert'
    alias: "Door Opened - Critical Alert"
    trigger:
    - platform: state
      entity_id: binary_sensor.door_sensor
      to: "on"
    action:
      - service: notify.mobile_app_the_matt_phone
        data:
          title: "Door opened!"
          message: "The door has been opened!"
          data:
            push:
              sound:
                name: "default"
                critical: 1
                volume: 1.0
            actions:
            - action: "{{ alert_silence }}"
              title: "SILENCE"

  - id: "automation_handle_alert_silencing"
    alias: "Handle alert silencing"
    trigger:
    - platform: event
      event_type: mobile_app_notification_action
      event_data:
        action: "{{ alert_silence }}"
    action:
      - service: notify.mobile_app_the_matt_phone
        data:
          title: "Alert Silenced"
          message: "The most recent alert has been silenced."
      - service: alert.turn_off
        target:
          entity_id: alert.alert_door_opened

alert:
  alert_door_opened:
    name: "Door is still open!"
    done_message: "Door has been closed."
    entity_id: binary_sensor.door_sensor
    state: "on"
    repeat:
     - 2
    can_acknowledge: true
    skip_first: true
    data:
      actions:
        - action: "{{ alert_silence }}"
          title: "SILENCE"
    notifiers:
      - mobile_app_the_matt_phone

The parts relating to the initial critical alerts via automation are working fine - notification is shown on my phone, and if I tap its “SILENCE” action on my phone I receive the “The most recent alert has been silenced” notification + the ongoing alert doesn’t send any notifications (i.e. has been successfully turned off).

Likewise, the triggering of the ongoing alert works fine - the repeated notifications are received, and they have a “SILENCE” action attached.

However, if I tap the “SILENCE” action on these ongoing alerts, nothing happens - the automation_handle_alert_silencing automation never fires.

Any suggestions as to why it’s not working properly / how to fix?

Thanks.

Anyone? Completely stuck unfortunately :frowning:

I have the same problem @noshitertertert . Did you figure it out?

Ok, I just found out the solution. The trigger event type must be ios.notification_action_fired

Hi Javier,

I’m very late returning to this (sorry!), but wanted to say a big thanks for posting the solution you found.

After a bit of fudging around it appears to have worked for me too. I thought it didn’t originally - but then it suddenly started working as I was fiddling with other parts of the automation_handle_alert_silencing automation and alert_door_opened alert entry - so assume I must’ve also messed something else up when I was last working on this.

FWIW I ended up including three triggers in my automation_handle_alert_silencing automation, all looking for the same actionable notification return data ({{ alert_silence }} in my example) - mobile_app_notification_action, ios.notification_action_fired and ios.action_fired.

Seemed prudent as I’ve ended up sending the actionable notifications to a notifier group that could include devices other than my iPhone (+ Apple Watch) in the future. Apparently ios.action_fired is used for Apple Watch actions vs ios.notification_action_fired for iPhones (according to Actionable Notifications - HowTo and examples), and I assume mobile_app_notification_action is somewhat generic and should hopefully cover Android devices / any other target I use for an actionable notification in the future.

Thanks.

1 Like