How to loop over all mobile device to send a notification to each

Hello,

I have an automatisation, which detect if one of my solar panel produce not enough.
I want to trigger a notification of all devices linked my Home Assistant.
I would like to loop over mobil apps automatically, to be robust in case I buy a new phone. I would like to make a notificaiton which will trigger on the new phone with no further Home Assistant config.

Here is the ACTION part in the YAML of my automatisation (sorry for french wording in notif):

actions:
  - sequence:
      - action: notify.mobile_app_ot5
        data:
          title: Alerte Panneaux Solaires Déféctueux
          message: >-
            Un des panneaux solaires a produit plus de 20% de moins que la
            moyenne des autres panneaux. VĂ©rifier les panneaux solaires.
      - action: notify.mobile_app_sm_a536b
        data:
          title: Alerte Panneaux Solaires Déféctueux
          message: >-
            Un des panneaux solaires a produit plus de 20% de moins que la
            moyenne des autres panneaux. VĂ©rifier les panneaux solaires.
      - action: notify.mobile_app_sm_a336b
        data:
          title: Alerte Panneaux Solaires Déféctueux
          message: >-
            Un des panneaux solaires a produit plus de 20% de moins que la
            moyenne des autres panneaux. VĂ©rifier les panneaux solaires.

It’s working but mobile apps are listed “manually”.

I tried several things. My last try is this one. I don’t understand how to make it working…

actions:
  - sequence: "{% for item in integration_entities('mobile_app') | select('match','device_tracker') | expand | map(attribute='name') | map('slugify') | list %}
      - action: notify.mobile_app_sm_a336b
        data:
          title: Alerte Panneaux Solaires Déféctueux
          message: >-
            Un des panneaux solaires a produit plus de 20% de moins que la
            moyenne des autres panneaux. VĂ©rifier les panneaux solaires.{% endfor %}"

I’m on Home Assistant since 3 days so totally New.

If someone could help me, to find out a working code, it would be great !

You need to use a Repeat For Each action:

triggers:
  #.... Your triggers
conditions: []
actions:
  - repeat:
      for_each: |
        {{ integration_entities('mobile_app') | select('match','device_tracker') 
        | expand | map(attribute='name') | map('slugify') | list }}
      sequence:
        - action: notify.mobile_app_{{ repeat.item }}{# if your tracker names already have "mobile app" in them, make sure to delete the "mobile_app_" #}
          data:
            title: Alerte Panneaux Solaires Déféctueux
            message: >-
              Un des panneaux solaires a produit plus de 20% de moins que la
              moyenne des autres panneaux. VĂ©rifier les panneaux solaires.
3 Likes

do notification groups not work here? :thinking:

I took OP’s goal to primarily be avoiding the need to add new devices manually… there is no functionality in notification Groups to do that.

1 Like

Hello,

Tested, it works as I wanted,

Thank you so much !