Actionable notification calling script

Hi,

I am going crazy as I can’t figure out what I am doing wrong. I would like to set-up an actionable notifcation where you can choose between yes and a script gets called and no and nothing happens.

I simply can’t get the script being called when clicked on yes.

alias: Neue Automatisierung
description: ""
trigger:
  - platform: state
    entity_id:
      - person.XXX
    to: home
condition:
  - condition: time
    weekday:
      - fri
action:
  - service: notify.mobile_app_xxx_iphone
    data:
      message: Message
      title: Title
      data:
        actions:
          - action: script.test
            title: Ja
mode: single

I feel it is something stupid, as the docs do not help me too.

The configuration key action shown above is just a name/identifier that you are setting up to send from your phone back to Home Assistant.

image

It is not the same as a service call or other action in script syntax.

As shown in the Actionable Notification docs you need to set a Wait for Trigger action to listen for the response event from when you press the button.

The basic version would be:

alias: Neue Automatisierung
description: ""
trigger:
  - platform: state
    entity_id:
      - person.XXX
    to: home
condition:
  - condition: time
    weekday:
      - fri
action:
  - service: notify.mobile_app_xxx_iphone
    data:
      message: Message
      title: Title
      data:
        actions:
          - action: Yes_Run_Test_Script
            title: Ja
  - alias: "Wait for a response"
    wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: Yes_Run_Test_Script
  - alias: "Perform the action"
    service: script.test
    data: {}
mode: single
1 Like

Hello, I would like to do a shameless plug for my script here:

For “nothing happens” just leave timeout disabled and actions empty.

Hope it is of use to you, have a good day!

1 Like

Hi @Didgeridrew,

thanks for the reply, that does indeed the trick. So basically the “- action:” is something I can freely choose which, when being passed back to HA tells HA to proceed with the action that I would like to happen, when this button is pushed.

Did I understand this correct?

Yes.

Keep in mind that action identifiers should be as unique as possible so the Wait for Trigger has something specific to listen for. That is why the example in the docs and @samuelthng’s blueprint above include context.id with each action. It makes the action identifier specific not only to which button was pressed, but also specific to that run of the automation. It is both more accurate and easier in the long run than manually created actions.

Got it, thanks.

I will also have a look at the blueprint from @samuelthng.

THANK YOU. This helped me so much.

1 Like