Automation based on notification Event

Looking to call a service when a group is notified and get the title/message of the notification.

There’s no notification integration to use a service, so I thought about using REST (however the rest notification doesn’t seem to be able to POST data in a way the REST API could utilize. So that attempt seems like a dead end.

So I was thinking it might be possible to use an automation based on an event trigger, but haven’t been able to find much documentation as to if this is possible. Curious if anyone has tried something similar.

You can listen to events in Developer Tools > EVENTS

Example:

20230513_002801

Click START LISTENING, go to SERVICES and call a notification service

service: notify.mobile_app_yourphone
data:
  title: My_Title
  message: My_Message

In EVENTS, click STOP LISTENING and search for something like…

event_type: call_service
data:
  domain: notify
  service: mobile_app_yourphone
  service_data:
    title: My_Title
    message: My_Message
origin: LOCAL
time_fired: "2023-05-12T22:17:26.321466+00:00"
context:
  id: 04H090MMvGTWPHG67dFWXXC2F1
  parent_id: null
  user_id: 96c43fx658c141e

Now you can use the event-trigger for your automation.

You can also listen to all ‘*’ (without quotes) events, but that will be a lot.

Thanks! That’s a big help.

Playing with this I did get the automation to trigger, the one part that’s still got me stumped is getting the actual message.

I do see the service being called:

data:
  domain: notify
  service: notifier
  service_data:
    title: Title
    message: Message
origin: LOCAL
time_fired: "2023-05-14T22:53:49.513488+00:00"
context:
  id: 01H0E7GPJ9J3AQARFW477J9CC2
  parent_id: null
  user_id: b15a35ded99f4d59b6b55803a67bd0d1

And my automation triggers:

automation:
  - alias: "Display alerts on Clock"
    initial_state: true
    trigger:
    - platform: event
      event_type: call_service
      event_data:
        domain: notify
        service: notifier
    action:
      service: esphome.ulanzi_add_screen
      data_template:
        alarm: false
        icon_name: 1
        text: '{{trigger.event.data.message}}'
        lifetime: 1
        screen_time: 1

However the text is empty.

        text: '{{ trigger.event.data.service_data.message }}'

:man_facepalming:

That’s it.