Custom data in Actionable Notification on iOS

I want to have custom data (the id in the example below) in a notification action so when the action is clicked and the automation gets called, I can process it based on that information.
For this purpose on android I can use the TAG field in the notification as it will be received in the automation as well, but on iOS it is not forwarded.

The documentation mentions some action_data but I can’t find any example for it.

"event_type": "mobile_app_notification_action",
"data": {
	"action": "OPEN_<context_id_here>",
	// will be present on:
	// - Android and iOS, when `REPLY` is used as the action identifier
	// - iOS when `behavior` is set to `textInput`
	"reply_text": "Reply from user",
	// iOS-only, will be included if sent in the notification
	"action_data": {
	  "entity_id": "light.test",
	  "my_custom_data": "foo_bar"
	},
	// Android users can also expect to see all data fields sent with the notification in this response such as the "tag"
	"tag": "TEST"
},

Sending the notification:

repeat:
  for_each: '{{ my_items }}'
  sequence:
    - service: notify.ios_device
      data:
      title: '{{ repeat.item.name }}'
      message: '{{ repeat.item.description }}'
      data:
      tag: {{ repeat.item.id }}
      alert_once: true
      actions:
        - action: MARKSKIPPED
          title: Skip
          destructive: true
          action_data:
            custom_data: {{ repeat.item.id }}
        - action: MARKDONE
          title: Done
          action_data:
            custom_data: {{ repeat.item.id }}

But in the automation this is the only information I’m getting.

trigger:
  id: '0'
  idx: '0'
  platform: event
  event:
    event_type: mobile_app_notification_action
    data:
      action: MARKDONE
    origin: REMOTE
    time_fired: '2022-06-10T10:48:50.864458+00:00'
    context:
      id: <some id>
      parent_id: null
      user_id: <some user id>
  description: event 'mobile_app_notification_action'

Is there a way to forward custom data to the automation from the notification action?

For now the only way I found is to add the id to the action

repeat:
  for_each: '{{ my_items }}'
  sequence:
    - service: notify.ios_device
      data:
      title: '{{ repeat.item.name }}'
      message: '{{ repeat.item.description }}'
      data:
      tag: {{ repeat.item.id }}
      alert_once: true
      actions:
        - action: MARKSKIPPED_{{ repeat.item.id }}
          title: Skip
          destructive: true
        - action: MARKDONE_{{ repeat.item.id }}
          title: Done

get it with regex in the automation and act based on it.

service: script.do_something
data:
  id: >-
    {% set value = trigger.event.data.action %}
    {% set pattern = "\d+" %} 
    {{ (value | regex_findall_index(pattern)) if value is search(pattern) else -1 }}

Had exactly the same problem and spent 2 hours trying to see why it does not work but finally managed to figure it out. actions_data param is not per action item (unfortunately), but rather per notification, so doing this will work for you:

repeat:
  for_each: '{{ my_items }}'
  sequence:
    - service: notify.ios_device
      data:
        title: '{{ repeat.item.name }}'
        message: '{{ repeat.item.description }}'
        data:
          tag: {{ repeat.item.id }}
          alert_once: true
          action_data:
            custom_data: {{ repeat.item.id }}
          actions:
            - action: MARKSKIPPED
              title: Skip
              destructive: true
            - action: MARKDONE
              title: Done
4 Likes