Run automation when service is triggered

Hello,

I want to create an automation when a service is triggered.
and specifically notify.sms
at the moment I only use this sms service for MFA.

  auth_mfa_modules:
    - type: totp
      name: "Authenticator app"
    - type: notify
      include:
        - sms
      name: "sms"
      message: "De MFA code voor Home Assistant is: {}"

and what I would like to know is when the last sms was send.

the reason is that my sim is on a pre-paid subscription and will expire when inactive for over 6 months.
so when this is about to happen I want to trigger notify.sms using an automation.

You can probably use an Event trigger to listen for the call service event:

- trigger:
    - platform: event
      event_type: call_service
      event_data:
        domain: notify
        service: sms

You can use the Developer Tools > Event listener tool to make sure that your MFA messages show up on the event bus under the call_service event type.

2 Likes

this indeed seems to work
on the even listener I get this

event_type: call_service
data:
  domain: notify
  service: sms
  service_data:
    message: "De MFA code voor Home Assistant is: <code>"
    target:
      - "<my number>"
origin: LOCAL
time_fired: "2023-05-23T14:13:21.210084+00:00"
context:
  id: <some ID>
  parent_id: null
  user_id: null

I will check create the automation later