Actionable Notifications - HowTo and examples

This has come up a couple of times recently, so I thought I’d post some of my success with Actionable Notifications. They have gotten a lot simpler than they used to be, and they’re super nice if you’ve got an Apple Watch to use them.

The first thing you need to know, and this is important, is that Actionable Notification choices are not shown by default on an iPhone. You need to LONG PRESS on the notification to see them. Apple has no indicator showing an actionable notification is any different from a regular notification, so you either have to write text indicating this, or remember this fact.

An “Actionable Notification” disguised as a regular notification:


What happens after you “long tap”:

The necessary YAML to make the magic happen:

automation:
  - alias: Test Notify Mobile app
    trigger:
      platform: state
      entity_id: input_boolean.test_toggle
    action:
      service: notify.iphone
      data:
        title: "Check this out!"
        message: "Something happened at home!"
        data:
          actions:
            - action: "SOUND_ALARM" # The key you are sending for the event
              title: "Sound Alarm" # The button title
              icon: "sfsymbols:lock.fill"
            - action: "SILENCE_ALARM" # The key you are sending for the event
              title: "Silence Alarm" # The button title
              icon: "sfsymbols:airplane.departure"
            - action: "URI" # Must be set to URI if you plan to use a URI
              title: "Open Url"
              uri: "https://google.com" # URL to open when action is selected, can also be a lovelace view/dashboard   

  - alias: Test push on
    trigger:
      platform: event
      event_type: ios.notification_action_fired
      event_data:
        actionName: 'SOUND_ALARM'
    action:
      - service: notify.pushover_me
        data:
          message: 'SOUND ALARM'

  - alias: Test push off
    trigger:
      platform: event
      event_type: ios.notification_action_fired
      event_data:
        actionName: 'SILENCE_ALARM'
    action:
      - service: notify.pushover_me
        data:
          message: 'SILENCE ALARM'

What this looks like on an Apple Watch:
incoming-7D198770-7814-4A54-B997-E268B450630A.PNG

You can also setup actions for your HA app on Apple Watch to execute common tasks:
incoming-0823F3D2-096E-45B2-9D1E-1468D12CFFE9 2

incoming-EEAAAB95-2812-4E79-86DE-6883A1F867A8 2

Here’s the YAML for the above buttons:

ios:
  actions:
    - name: 'ARM_NIGHT'
      background_color: "#1c1741"
      label:
        text: "Alarm Night"
        color: "#1d00ff"
      icon:
        icon: weather-night
        color: "#1d00ff"
    - name: 'COMMON_LIGHTS_OFF'
      background_color: "#555555"
      label:
        text: "Common Off"
        color: "#DDDDDD"
      icon:
        icon: lightbulb
        color: "#000000" 
    - name: 'ARM_AWAY'
      background_color: "#411616"
      label:
        text: "Alarm Away"
        color: "#ff0003"
      icon:
        icon: lock
        color: "#ff0003"
    - name: 'SILENCE_DOOR_ALERT'
      background_color: "#411939"
      label:
        text: "Silence Door"
        color: "#ff00e3"
      icon:
        icon: bell-off
        color: "#ff00e3"
    - name: 'INTERIOR_LIGHTS_OFF'
      background_color: "#555555"
      label:
        text: "Interior Off"
        color: "#DDDDDD"
      icon:
        icon: lightbulb
        color: "#000000"
    - name: 'ARM_VACATION'
      background_color: "#172b41"
      label:
        text: "Vacation"
        color: "#03c7ff"
      icon:
        icon: island
        color: "#03c7ff"
    - name: 'GARAGE_CAR_DOOR_TOGGLE'
      background_color: "#413c17"
      label:
        text: "Garage Door"
        color: "#ff9d00"
      icon:
        icon: car-hatchback
        color: "#ff9d00"  
    - name: 'DISARM'
      background_color: "#2d4148"
      label:
        text: "Disarm Alarm"
        color: "#03ff00"
      icon:
        icon: lock-open
        color: "#03ff00"

And the resulting action triggers to make them do something when tapped:

automation:
  - alias: IOS Alarm Away
    trigger:
      - platform: event
        event_type: ios.notification_action_fired
        event_data:
          actionName: 'ARM_AWAY'
      - platform: event
        event_type: ios.action_fired
        event_data:
          actionName: 'ARM_AWAY'
    action:
      - service: alarm_control_panel.alarm_arm_away
        entity_id: alarm_control_panel.home
      - service: script.light_common_area_off
      - service: script.light_bedroom_area_off

  - alias: IOS Alarm Night
    trigger:
      platform: event
      event_type: ios.action_fired
      event_data:
        actionName: 'SOUND_ALARM'
    action:
      - service: alarm_control_panel.alarm_arm_night
        entity_id: alarm_control_panel.home
      - service: script.light_common_area_off

  - alias: IOS Alarm Vacation
    trigger:
      - platform: event
        event_type: ios.notification_action_fired
        event_data:
          actionName: 'ARM_VACATION'
      - platform: event
        event_type: ios.action_fired
        event_data:
          actionName: 'ARM_VACATION'
    action:
      - service: alarm_control_panel.alarm_arm_away
        entity_id: alarm_control_panel.home
      - service: input_boolean.turn_on
        entity_id: input_boolean.vacation
      - service: script.light_common_area_off
      - service: script.light_bedroom_area_off

  - alias: IOS Alarm Disarm
    id: ios_alarm_disarm
    trigger:
      platform: event
      event_type: ios.notification_action_fired
      event_data:
        actionName: 'DISARM'
    action:
      - service: alarm_control_panel.alarm_disarm
        entity_id: alarm_control_panel.home
      - service: input_boolean.turn_off
        entity_id: input_boolean.vacation

  - alias: IOS Common Lights Off
    id: ios_common_lights_off
    trigger:
      platform: event
      event_type: ios.action_fired
      event_data:
        actionName: 'COMMON_LIGHTS_OFF'
    action:
      - service: script.light_common_area_off

  - alias: IOS Interior Lights Off
    id: ios_interior_lights_off
    trigger:
      platform: event
      event_type: ios.action_fired
      event_data:
        actionName: 'INTERIOR_LIGHTS_OFF'
    action:
      - service: script.light_common_area_off
      - service: script.light_bedroom_area_off

  - alias: IOS Garage Car Door Toggle
    id: ios_garage_car_door_toggle
    trigger:
      platform: event
      event_type: ios.action_fired
      event_data:
        actionName: 'GARAGE_CAR_DOOR_TOGGLE'
    action:
      - service: cover.toggle
        data: {}
        target:
          entity_id: cover.garage_door

  - alias: IOS Silence Door Alert
    id: ios_silence_door_alert
    trigger:
      platform: event
      event_type: ios.action_fired
      event_data:
        actionName: 'SILENCE_DOOR_ALERT'
    action:
      - service: input_boolean.turn_on
        target:
          entity_id: input_boolean.alert_silence

Note the ARM_VACATION and ARM_AWAY which have two different methods of being triggered. The ios_action_fired is from the Watch and the ios.notification_action_fired is from an Actionable Notification, as below:

automation:
  - alias: "Tracker All Away"
    trigger:
      platform: state
      entity_id: group.persons_all
      to: not_home
      for:
        minutes: 30
    condition:
      - condition: state
        entity_id: alarm_control_panel.home
        state: disarmed
    action:
      service: notify.iphone
      data:
        title: "All Persons Away"
        message: "Set alarm?"
        data:
          actions:
            - action: "ARM_AWAY" # The key you are sending for the event
              title: "Away" # The button title
            - action: "ARM_VACATION"
              title: "Vacation"
            - action: "NOTHING"
              title: "Ignore"

Hope that helps! Have fun.

18 Likes

Awesome! Thanks for sharing!

Any idea how to use the “textInput” described here?

I have tried:
{{ trigger.event.data[“textInput”] }} like here or here
and {{ trigger.event.data.textInput }} to send a textInput snooze time to a script, but cannot get it working.

hi Bob ,
try this
{{ trigger.event.data[“reply_text”] }}
it’s working for me

Thanks for the help!

Hope this helps somebody as it took me a while to sort out syntax and annoying quotes.
Here is my Automation for a snoozeable alert with a custom input snooze time from the notification:

alias: Alarm actionable
description: send critical notification
trigger:
  - platform: numeric_state
    entity_id: sensor.my_sensor
    for:
      hours: 0
      minutes: 10
      seconds: 10
    below: '60'
    id: sensor_low
condition: []
action:
  - service: notify.mobile_app_my_iphone
    data:
      title: Alarm 
      message: LOW  {{ states('sensor.my_sensor') }}
      data:
        push:
          sound:
            name: default
            critical: 1
            volume: 1
        actions:
          - action: SNOOZE_30_MIN
            title: 'Snooze 30 Minutes'
          - action: SNOOZE_1_HOUR
            title: 'Snooze 1 Hour'
          - action: SNOOZE_CUSTOM
            title: 'Snooze Custom'
            behavior: textInput
            textInputButtonTitle: 'Snooze (min)'
            textInputPlaceholder: '15'
  - wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: SNOOZE_30_MIN
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: SNOOZE_1_HOUR
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: SNOOZE_CUSTOM
    continue_on_timeout: false
    timeout: '1:00'
  - service: script.snooze_notifications
    data:
      snooze_time_mins: >-
        {% if wait.trigger.event.data.action == "SNOOZE_30_MIN" %} 30  {%
        elif wait.trigger.event.data.action == "SNOOZE_1_HOUR" %} 60  {%
        elif wait.trigger.event.data.action == "SNOOZE_CUSTOM" %} {{
        wait.trigger.event.data["reply_text"] }}  {% endif %}
      automation_name: automation.alarm_actionable
mode: restart

And the script for snoozing:

alias: Snooze Notifications
sequence:
  - service: automation.turn_off
    target:
      entity_id: '{{ automation_name }}'
    data:
      stop_actions: false
  - delay:
      minutes: '{{ snooze_time_mins }}'
  - service: automation.turn_on
    target:
      entity_id: '{{ automation_name }}'
mode: single

1 Like

That iPhones don’t automatically expand notifications to show the buttons is so annoying - especially if you miss the notification popup. Has anyone found a workaround for this (despite appearing to be iPhone related and not so much a HA issue).

2 Likes

This is a terrible solution, but an Apple Watch doesn’t have this problem. It presents all the choices with actionable notifications.

1 Like