Notifications with simple Action (Start Script)

Hi guys, Iam reading the tutorials over and over again. Am I missing something?

I have an automation checking in the evening if I closed my Garage. If its unlocked I receive an Notification in HA app. I wanted to add an action within the notification that offers me to directly close the Garage. How can I trigger directly a Script within the Action? The documentation mentions this concept but as always doesnt provide proper example :confused:
Defining the Action as Script.xyz doesnt work.

Any ideas? :confused:

action:
  - service: notify.mobile_app_pixel_6
    data:
      title: Die Garage ist noch offen!
      message: ""
      data:
        color: "#ff0000"
        notification_icon: mdi:garage-alert-variant
        visibility: public
        actions:
          - action: test
            title: Garage schließen
1 Like

I would say this is a proper example.

This is mentioned but I dont find any example. The mentioning alarm events and making plenty of examples around that topic. I just want to see how I can execute any script or even just go for an entity that is switched on :confused:

I posted a link. Perhaps that is a clue

Also looking for the solution. In my case I want to run a vacuum from notification when leave home.
I need an action to run a script or automation.

Ok, seems like iam dumb or the documentation could be optimized :wink:

The “action” in my script called “test” is the actual event that is send to Home Assistant.
You need then to create a new automation that gets triggered by the event “test”.

2 Likes

Could you please elaborate? I’m trying to achieve the same but don’t know how to get the automation launched

You do the automation like mentioned in my start post.
The line “-action: test” is basically an event name.

So when I want to close the garage door I hit the word “Garage schließen” in my notification bar.
What then happens is that the word “test” is fired as an event.
I then created a new automation that “listens” to that trigger word and as action basically closes the garage.

This automation looks like this:

alias: Garage - Push Notification mit Action
description: ""
trigger:
  - platform: event
    event_type: mobile_app_notification_action
    event_data:
      action: test

And as soon as the event “test” comes in, the automation is fired to do anything.

1 Like

Hi, I’ve been banging my head on how to get the notification to trigger an automation. Below is my notification yaml, which I believe is wrong at the end because I need to call an automation. I don’t know what code does that.

Notification YAML:

alias: Door lock status notif
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.lock_switch_2
    from: "off"
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition: []
action:
  - service: notify.mobile_app_first_iphone
    data:
      message: Check the door if it should be locked
      title: Door lock is open
      data:
        actions:
          - action: lock
            title: Lock?
            service: input_boolean.turn_off
            data: {}
            target:
              entity_id: input_boolean.lock_switch_2
mode: single

I created the automation but don’t know what code to use for the trigger here:

description: ""
mode: single
trigger: []
condition:
  - condition: or
    conditions:
      - condition: device
        device_id: 6c2c9df53227ce58asdasd80a74ba4bdc
        domain: device_tracker
        entity_id: device_tracker.first_iphone
        type: is_home
      - condition: device
        device_id: d889b7b35c98a8asdaseqw5b36f12518ec903
        domain: device_tracker
        entity_id: device_tracker.second_iphone
        type: is_home
action:
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.lock_switch_2

1 Like

Finally figure out what it is:
The flow is that

  1. Set up an actionable notification. The action can be of any name like STOP_THE_SIREN.
  2. When you press the button on the notification of the app, a trigger mobile_app_notification_action with event data STOP_THE_SIREN is fired.
  3. You use the trigger in #2 to trigger ANOTHER automation.
  4. In this automation, do everything you want.

Here’s my result:

Automation 1: Send the notification until turned off

alias: Repeat Notification when Siren Switch Turned On
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.siren_switch
    from: null
    to: "on"
condition: []
action:
  - repeat:
      sequence:
        - service: notify.notify
          data:
            message: Button pressed
            title: Warning
            data:
              sound:
                name: default
              actions:
                - action: TURN_OFF_SIREN
                  title: Turn off
        - delay:
            hours: 0
            minutes: 0
            seconds: 3
            milliseconds: 0
      until:
        - condition: state
          entity_id: input_boolean.siren_switch
          state: "off"
mode: single

Automation 2: Listen to the app action and then turn off the siren switch

alias: Turn off siren switch using mobile app
description: ""
trigger:
  - platform: event
    event_type: mobile_app_notification_action
    event_data:
      action: TURN_OFF_SIREN
condition: []
action:
  - service: input_boolean.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: input_boolean.siren_switch
mode: single

I think the official document is written in a way that not everyone can understand. Thanks for the YouTube video https://www.youtube.com/watch?v=QZsY5a7R10c . Hope this helps.

Cheers