I researched doing something similar a while back but never found any way to add multiple entries with a single entity. What you have now looks pretty efficient. Are you just trying to save space in the UI?
That’s what I was thinking (but as automations): Using the same service_template you have now but with automation.notify_everyone, automation.notify_person1, etc.
not really sure what you want, and what the full automation looks like, but depending on your triggering entities, you might be able to use the {{trigger.to_state}} in the service_template?
need to find the correct filter to only use the final part of the name of course but you get the idea?
something else you might be able to use: I have input_booleans to activate my media_players and to allow these active players be used in the media_player services via the sensor.media_players_active.
media_players_active:
friendly_name_template: >
{% set count = states.input_boolean
|selectattr('entity_id','in',state_attr('group.activate_media_players','entity_id'))
|selectattr('state','eq','on')|list|length %}
{% set player = 'player' if count in [0,1] else 'players' %}
{% set number = 'No' if count == 0 else count %}
{{number}} Media {{player}} active
entity_id:
- input_boolean.googlehome_1
- input_boolean.googlehome_2
- input_boolean.googlehome_3
- input_boolean.googlehome_4
- input_boolean.googlehome_5
- input_boolean.googlehome_6
value_template: >
{% set rooms = states.input_boolean
|selectattr('entity_id','in',state_attr('group.activate_media_players','entity_id'))
|selectattr('state','eq','on') |map(attribute='object_id')|list %}
{% set ns = namespace(speakers = '') %}
{% for i in range(rooms | length) %}
{% if states('input_boolean.' ~ rooms[i]) == 'on' %}
{% set d = ', ' if ns.speakers | length > 0 else '' %}
{% set ns.speakers = ns.speakers ~ d ~ 'media_player.' ~ rooms[i] %}
{% endif %}
{% endfor %}
{% if ns.speakers|length|int == 0 %} None
{% else %}
{{ ns.speakers }}
{% endif %}
To revive a very old topic, I created a script which is called from various automations, setting the icon, group etc via variables (if set), and it sends it out to everyone who is home.
notify:
alias: Notification
icon: mdi:cellphone-information
sequence:
- repeat:
for_each: >
{{ states.person | selectattr('state','eq','home') | map(attribute='object_id') | list }}
sequence:
- service: notify.mobile_app_{{ repeat.item }}
data:
message: "{{ message }}"
data:
notification_icon: "{%- if notification_icon is defined -%}{{ notification_icon }}{%- else -%}mdi:home-assistant{%- endif -%}"
group: "{%- if notification_icon is defined -%}{{ notification_icon }}{%- endif -%}"
tag: "{%- if tag is defined -%}{{ tag }}{%- endif -%}"
ttl: 0
priority: high