How do I list all the mobile_apps?

Hello,

I would like to list all existing mobile_apps in order to notify them all.
I don’t want to use a group so that it is dynamic depending on the devices added or deleted in home assistant.

I started by listing all the integration entities
{{ integration_entities('mobile_app') }}

[‘device_tracker.tel_pro_joel’, ‘sensor.tel_pro_joel_battery_level’, ‘sensor.tel_pro_joel_battery_state’, ‘sensor.tel_pro_joel_charger_type’, ‘device_tracker.s21_nina’, ‘sensor.s21_nina_charger_type’, ‘sensor.s21_nina_battery_level’, ‘sensor.s21_nina_battery_state’, ‘device_tracker.s24_de_nina’, ‘sensor.s24_de_nina_battery_level’, ‘sensor.s24_de_nina_battery_state’, ‘sensor.s24_de_nina_charger_type’, ‘device_tracker.s23_de_joel’, ‘sensor.s23_de_joel_battery_level’, ‘sensor.s23_de_joel_battery_state’, ‘sensor.s23_de_joel_charger_type’]

Then I have a single list of devices
{{ integration_entities('mobile_app') | map('device_id') | unique | list }}

[‘248f28a3189954e0b3dddaf514fbbb46’, ‘ca4d19a98b0aa86a89a95de476c76873’, ‘67e840c0e107b5ef66f83316bae002bb’, ‘236491ac1783e9ccf30fc32fa24e295a’]

Next I don’t know how to get the list of devices to notify with the notification service

[‘mobile_app_tel_pro_joel’, ‘mobile_app_s21_de_nina’, ‘mobile_app_s24_de_nina’, ‘mobile_app_s23_de_joel’]

Good evening,

I’d like to raise the subject again

Otherwise, with the list of device_id how can I find the name of the corresponding mobile_app?

There’s no direct access to the service registry via templates, so there’s no way to check that all the resulting notify services exist… but you can try:

{{ integration_entities('mobile_app')
| select('match','device_tracker')
| map('replace', 'device_tracker.', 'notify.mobile_app_')
| list }}
1 Like

Great, that’s almost what I’m looking for. It helps me enormously
The aim is to be able to notify all devices even if one of the users changes the name in their companion application.

After trying to change the name in the companion application, the friendly_name is used, where you also have to convert spaces to underscore, use lower case and convert accents (I haven’t tested the other characters).

I’m continuing my trial and error to get the friendly_name from the device_tracker
I’ll post the result here. If you manage to do it faster than me, don’t hesitate to do the same.

Traduit avec DeepL DeepL The right app or extension for every translation

huh. are you sure about that? i just tried it and when i change the friendly name, the underlying entity name and the corresponding notify.mobile_app_ service names do not change. of course someone could go into the tentities page and change the entity name itself, so this is certainly not foolproof… but i don’t know if you need to worry about the friendly name being changed.

For the friendly name to be updated, this is only sent if the user closes and then opens their application
I’ve just checked this has an immediate impact on the use of notify

I took the opportunity to test with exotic characters. It’s very interesting but unless there’s a ready-made function to clean up a character string, I’m going to have to find out about regexes to convert the friendly_name into an entity code.

Example with
Nom Persoé à ï @/×x&* 》
Which becomes
mobile_app_nom_persoe_a_i_xx

This is fascinating, perhaps it will help those who want to create blueprints?
In the meantime, I’m continuing to read up on the subject, and if you’re more at ease with it, don’t hesitate to share a few lines of research.

Traduit avec DeepL DeepL The right app or extension for every translation

slugify()

Templating - String Filters - slugify

Excellent, thanks for sharing

Here’s what it would look like, I didn’t manage to add notify.mobile_app, I can’t figure out how to do a regex_replace on the list (it works on a string)

{{ integration_entities('mobile_app') 
| select('match','device_tracker')
| expand
| map(attribute='name')
| map('slugify')
| list }}

[‘nom_persoe_a_i_xx’, ‘s23_de_joel’, ‘s24_de_nina’, ‘s21_de_nina’]

Regex exemple is

regex_replace(‘^’,‘notify.mobile_app_’)

Just use map to apply regex_replace across the list. Also, IIRC, it is more efficient to use a similar method to apply the state_attr() function instead of using expand.

{{ integration_entities('mobile_app') 
| select('match','device_tracker')
| map('state_attr','friendly_name')
| map('slugify')
| map('regex_replace', '^','notify.mobile_app_')
| list }}
1 Like

Thanks to your feedback, I’m discovering the uses of map() - it’s powerful!

I really appreciate your feedback, I’ve learnt a lot and the result is superb. This will avoid having to maintain notification groups every time a device is added or removed, and it will automatically take into account any name changes the user chooses.
It’s ideal for automata and scripts to be able to notify without being subject to these vagaries.