From notification platform to entity platform?

Hello,

Until now, I was using notification groups:

notify:
  - name: notification_alarm
    unique_id: notification_alarm
    friendly_name: Alarm
    platform: group
    services:
      - action: mobile_app_redmi14
      - action: freemobile_guillaume
      - action: freemobile_emma
      - action: ntfy_alarm

And notifications defined like this:

- name: ntfy notification
  unique_id: ntfy_notification
  platform: apprise
  url: "ntfy://[email protected]/homeassistant?priority=min&tags=scroll&avatar_url=https://yyy.domain.ltd/local/icons/omeassistant.png"

Recently, the ntfy integration has evolved a lot and now supports the parameters that were missing, so I could switch from Apprise to ntfy. The problem is that apparently my syntax is deprecated.

My question is how to call an action (ntfy.publish) from a group of notification if this action is not a notification ?

One option might be to use an automation with an Event trigger to proxy notifications from your group to the notify.send_message or ntfy.publish actions.

First, you would create a new “old style” notification group…

notify:
  - name: new_ntfy_alarm
    platform: group
    services: []

… that will stand in for your new notify entity where you used ntfy_alarm in the “notification_alarm” group.

notify:
  - name: notification_alarm
    unique_id: notification_alarm
    friendly_name: Alarm
    platform: group
    services:
      - action: mobile_app_redmi14
      - action: freemobile_guillaume
      - action: freemobile_emma
      - action: new_ntfy_alarm

Then the base automation would be something along the lines of:

triggers:
  - trigger: event
    event_type: call_service
    event_data:
      domain: notify
      service: new_ntfy_alarm
conditions:
actions:
  - action: notify.send_message
    data:
      message: '{{trigger.event.data.service_data.message}}'
    target:
      entity_id: notify.ntfy_example

You’ll have to use the Event listener tool to see what other event data is available for the other parameters that can be used with ntfy.publish.

Thx for your help !

OK, if that’s the old style, what is the new one?

I’m having a bit of trouble with the new syntax versus the old one… especially when the new syntax is more complex than the old one. Should I understand that group notifications are deprecated, maybe even notifications themselves, and that it’s better to use scripts with multiple actions instead?

The “new one” is Notify entity group Helpers, which are only useful for the new notify entities. AFAIK, there isn’t currently a way to create your own notify entity.

No, group notifications are not deprecated. But notifications, in general, are in transition.

Originally the plan seemed to be that all notifier integrations would be migrated from providing individual service/action end points to have all notifications provide entities as end point for a generic action, notify.send_message. That would have made it easier to send the same message through multiple notifiers with a single action. I may misunderstand the situation, but I think the transition has taken quite a bit longer than expected. I lost track of the discussions as progress seemed to have stalled about 6-8 months ago on how to deal with notifiers that have more complex service data. It seems some of the transitional concerns (like how to handle groups containing a mix of “old” and “new”) were neglected based on the idea that they would only be short-term inconveniences.

Based on what has recently been allowed for ntfy and Telegram, it looks like the decision has been made to abandon “one action to rule them all”… In both these cases the notifier integrations will provide a notify entity that can be targeted by notify.send_message for basic messages and, additionally, the integrations can provide actions under their own domain for notifications that require complex data.

Thx !

So I’m having trouble figuring out the right approach today to create notification groups that rely on the ntfy action.
Automation seems like a possible solution, but is it a long-term one?

Depending on the specifics of what you’re doing, I don’t know that there are any other options. Even if all the notifiers you are using have moved to the new methods (currently unlikely) it looks like the new groups will only be useful for basic notifications, since the custom domain-based actions will only work for their own entities. I can envision using a script with Repeat For Each to handle complex data notifications across a group of notifiers, but it would need to be customized for the specific mix of notifiers being used.

OK, it’s works !

# Notifications ntfy
notify:
  - name: ntfy alarm
    unique_id: ntfy_alarm
    platform: group
    services: []
  - name: ntfy alert
    unique_id: ntfy_alert
    platform: group
    services: []
  - name: ntfy_info
    unique_id: ntfy_info
    platform: group
    services: []
  - name: ntfy_notification
    unique_id: ntfy_notification
    platform: group
    services: []

automation:
  - id: "ntfy_send"
    alias: Envoie de notification avec "ntfy.publish"
    description: Utilise le service "ntfy.publish" pour envoyer des notifications.
    triggers:
      - trigger: event
        event_type: call_service
        event_data:
          domain: notify
          service: ntfy_alarm
        alias: ntfy alarm
        id: ntfy_alarm
      - trigger: event
        event_type: call_service
        event_data:
          domain: notify
          service: ntfy_alert
        alias: ntfy alert
        id: ntfy_alert
      - trigger: event
        event_type: call_service
        event_data:
          domain: notify
          service: ntfy_info
        alias: ntfy info
        id: ntfy_info
      - trigger: event
        event_type: call_service
        event_data:
          domain: notify
          service: ntfy_notification
        alias: ntfy notification
        id: ntfy_notification
    conditions: []
    actions:
      - choose:
          - conditions:
              - condition: trigger
                id:
                  - ntfy_alarm
            sequence:
              - action: ntfy.publish
                target:
                  entity_id: notify.home_assistant
                data:
                  title: "{{ trigger.event.data.service_data.title | default('Home Assistant') }}"
                  message: "{{ trigger.event.data.service_data.message }}"
                  priority: 5
                  tags: rotating_light
                  icon: "https://domain.co/local/icons/homeassistant.png"
          - conditions:
              - condition: trigger
                id:
                  - ntfy_alert
            sequence:
              - action: ntfy.publish
                target:
                  entity_id: notify.home_assistant
                data:
                  title: "{{ trigger.event.data.service_data.title | default('Home Assistant') }}"
                  message: "{{ trigger.event.data.service_data.message }}"
                  priority: 5
                  tags: warning
                  icon: "https://domain.co/local/icons/homeassistant.png"
          - conditions:
              - condition: trigger
                id:
                  - ntfy_info
            sequence:
              - action: ntfy.publish
                target:
                  entity_id: notify.home_assistant
                data:
                  title: "{{ trigger.event.data.service_data.title | default('Home Assistant') }}"
                  message: "{{ trigger.event.data.service_data.message }}"
                  priority: 3
                  tags: newspaper
                  icon: "https://domain.co/local/icons/homeassistant.png"
          - conditions:
              - condition: trigger
                id:
                  - ntfy_notification
            sequence:
              - action: ntfy.publish
                target:
                  entity_id: notify.home_assistant
                data:
                  title: "{{ trigger.event.data.service_data.title | default('Home Assistant') }}"
                  message: " {{trigger.event.data.service_data.message}} "
                  priority: 1
                  tags: scroll
                  icon: "https://domain.co/local/icons/homeassistant.png"
    mode: parallel
    max: 10

Basically, I declare empty groups and I listen to those groups… and then I have the real groups.

# Groupes de notifications
notify:
  - name: notification_alarm
    friendly_name: Alarme
    platform: group
    services:
      - action: mobile_app_redmi14
      - action: freemobile_guillaume
      - action: freemobile_emma
      - action: ntfy_alarm

  - name: notification_alert
    friendly_name: Alerte
    platform: group
    services:
      - action: mobile_app_redmi14
      - action: ntfy_alert

  - name: "notification_alert_tts"
    friendly_name: "Alerte + TTS"
    platform: group
    services:
      - action: mobile_app_redmi14
      - action: ntfy_alert
      - action: tts_google_home_salon

  - name: notification_info
    friendly_name: "Info"
    platform: group
    services:
      #- action: mobile_app_redmi14
      - action: ntfy_info

  - name: notification_notification
    friendly_name: "Notification"
    platform: group
    services:
      - action: ntfy_notification

  - name: "notification_notification_tts"
    friendly_name: "Notification + TTS"
    platform: group
    services:
      - action: ntfy_notification
      - action: tts_google_home_salon

  - name: "notification_tts_only"
    friendly_name: "Notification seulement TTS"
    platform: group
    services:
      - action: tts_google_home_salon

Thx for the solution @Didgeridrew !

1 Like