Actionable notifications script blueprint with variable number of actions

I’m trying to create a blueprint for actionable notifications, which would be extendable to allow me to have X amount of actions. The number of actions would be determined by how many actions were filled out in the UI. Basically I’m looking for something that the JS equivalent would be like:

if (action_fourth !== null) {
// add action to notification
}
if (action_fifth !== null) {
// add action to notification
}

Currently I have it set up so there are 5 actions hardcoded, but if I do not put anything in the 3rd / 4th / 5th action, they still show up in my notification just as default “Fifth” button, which then does nothing, when I want the options that haven’t been filled out to just not show up:

I copied the “confirmable notification” default blueprint and adjusted it a bit here, this is what i have:

blueprint:
  name: Actionable Notification
  description: >-
    A script that sends a notification with multiple actions to choose from.
  domain: script
  source_url: https://github.com/home-assistant/core/blob/b297b78086ed7f7de0fe0a629a1c85170cb5e967/homeassistant/components/script/blueprints/confirmable_notification.yaml
  input:
    notify_device:
      name: Device(s) to notify
      description: Device needs to run the official Home Assistant app to receive notifications.
      selector:
        device:
          integration: mobile_app
          multiple: true
    title:
      name: "Title"
      description: "The title of the button shown in the notification."
      default: ""
      selector:
        text:
    message:
      name: "Message"
      description: "The message body"
      selector:
        text:
    first_text:
      name: "First Text"
      description: "Text to show on the first button"
      default: "First"
      selector:
        text:
    first_action:
      name: "First Action"
      description: "Action to run when first button is chosen."
      default: []
      selector:
        action:
    second_text:
      name: "Second Text"
      description: "Text to show on the second button"
      default: "Second"
      selector:
        text:
    second_action:
      name: "Second Action"
      description: "Action to run when second button is chosen."
      default: []
      selector:
        action:
    third_text:
      name: "Third Text"
      description: "Text to show on the third button"
      default: "Third"
      selector:
        text:
    third_action:
      name: "Third Action"
      description: "Action to run when third button is chosen."
      default: []
      selector:
        action:
    fourth_text:
      name: "Fourth Text"
      description: "Text to show on the fourth button"
      default: "Fourth"
      selector:
        text:
    fourth_action:
      name: "Fourth Action"
      description: "Action to run when fourth button is chosen."
      default: []
      selector:
        action:
    fifth_text:
      name: "Fifth Text"
      description: "Text to show on the fifth button"
      default: "Fifth"
      selector:
        text:
    fifth_action:
      name: "fifth Action"
      description: "Action to run when fifth button is chosen."
      default: []
      selector:
        action:

mode: restart

sequence:
  - alias: "Set up variables"
    variables:
      action_first: "{{ 'FIRST_' ~ context.id }}"
      action_second: "{{ 'SECOND_' ~ context.id }}"
      action_third: "{{ 'THIRD_' ~ context.id }}"
      action_fourth: "{{ 'FOURTH_' ~ context.id }}"
      action_fifth: "{{ 'FIFTH_' ~ context.id }}"
  - alias: "Send notification"
    domain: mobile_app
    type: notify
    device_id: !input notify_device
    title: !input title
    message: !input message
    data:
      actions:
        - action: "{{ action_first }}"
          title: !input first_text
        - action: "{{ action_second }}"
          title: !input second_text
        - action: "{{ action_third }}"
          title: !input third_text
        - action: "{{ action_fourth }}"
          title: !input fourth_text
        - action: "{{ action_fifth }}"
          title: !input fifth_text
  - alias: "Awaiting response"
    wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ action_first }}"
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ action_second }}"
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ action_third }}"
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ action_fourth }}"
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ action_fifth }}"
  - choose:
      - conditions: "{{ wait.trigger.event.data.action == action_first }}"
        sequence: !input first_action
      - conditions: "{{ wait.trigger.event.data.action == action_second }}"
        sequence: !input second_action
      - conditions: "{{ wait.trigger.event.data.action == action_third }}"
        sequence: !input third_action
      - conditions: "{{ wait.trigger.event.data.action == action_fourth }}"
        sequence: !input fourth_action
      - conditions: "{{ wait.trigger.event.data.action == action_fifth }}"
        sequence: !input fifth_action

Ideally there is a way to not have to hardcode first, second, third, fourth, fifth as well, and just loop over it to show X amount, depending on how many you added in the UI, but I’m only a beginner here so that’ll probably be my next itteration.

Hi @dnvr ,

I was just wondering if this was possible. Did you manage to work out a way to do this?

Cheers,

T

Nice, thanks! This seems like a good direction. Still coming across a couple errors here, namely “no input for actions_text”, but I am trying to work through those.

There’s something weird going on with this post, as I received an email with a proposed solution that is completely missing here as I post this! I wonder if there’s some sort of moderation going on here?!