There’s a script Blueprint to help you create a script that you can call from automations to do what you are trying to do, but it suffers from the same possible point of failure Petro mentioned above.
Regarding Petro’s comment, you may want to consider setting up a Notify group for each person so that the object ID of the person entity matches that of the notify action… it makes this kind of thing easier.
You need to use the map function to iterate slugify over all the list items. I would also just set the names list to a variable, so you don’t have to run essentially the same query multiple times:
alias: Dynamische Benachrichtigung nur an Anwesende
description: Sendet eine Nachricht nur an Personen, die zuhause sind
triggers:
- entity_id: binary_sensor.bewegung_flur
to: "on"
trigger: state
variables:
names: |
{{ states.person | selectattr('state', 'eq' ,'home')
| map(attribute = 'name' ) | map('slugify') | list }}
conditions:
- condition: template
value_template: "{{ names | count > 0 }}"
actions:
- repeat:
for_each: "{{ names }}"
sequence:
- data:
message: Bewegung erkannt.
action: notify.{{ repeat.item }}
mode: single
OK, I did exactly as you suggested, but the action notify.mobile_app_sascha is being called, which does not seem to exist.
Logger: homeassistant.components.automation.dynamische_benachrichtigung_nur_an_anwesende
Quelle: helpers/script.py:2098
Integration: Automation (Dokumentation, Probleme)
Erstmals aufgetreten: 09:16:49 (4 Vorkommnisse)
Zuletzt protokolliert: 09:27:03
Dynamische Benachrichtigung nur an Anwesende: Repeat at step 1: Error executing script. Service not found for call_service at pos 1: Action notify.mobile_app_sascha not found
Dynamische Benachrichtigung nur an Anwesende: Error executing script. Service not found for repeat at pos 1: Action notify.mobile_app_sascha not found
Also the value_template: "{{ names | count > 0 }} shows "False" even though we are both at home: