Dynamic actions based on a single trigger

I’d like to write a simple but tight automation that does the following:

If

any of these people enter any of these zones

Then

Send a mobile push notification to whoever entered the zone (could be multiple people)

Is there a way to do this with one trigger and one action?

I don’t need the action to be specific to the zone at this point (it’s a simple shopping list notification, and I only have one shopping list).

Tx!

Assuming there are no people registered in your Home assistant that would enter the shopping area, the trigger could simply be a state condition for the zone state to change not_to 0. If you have multiple,zones you want to test, then you can create triggers for each, and fill the trigger id with the name of the zone you are looking for.

I’m not that good in looping over persons with a state equal to that specific zone, so maybe someone else can answer that. If there are persons in HA who are not doing the shopping, you could probably filter them out here too. However, there’s also the problem of selecting the right notifier for each person.

So maybe one automation per person to check then entering the zones you need would not be such a bad idea. Also because that automation can easily be disabled if the person does not want to het the notifications for a while.

I can use trigger IDs to avoid having multiple automations, but I’m trying to avoid having separate actions for each person that needs to be notified, when the action is the same except for the notify service name.

You can template the service call’s name.

Post an example or two of how your person entities and notify services are named. For example:

person.john
notify.john_mobile
person.mark
notify.mobile_app_mark_s21

Does every person have an s21 phone? I suspect they don’t so it won’t be as simple as adding the person’s name into the string mobile_app_name_s21. Let me know if that’s true and I can show you another way to do it.

Depending on how many people there are in your household, it may make this automation easier to set up if you create a notify group for each person. Doing so makes it simple to template and it gives you an easy-to-remember single service call to use in future automations which can broadcast to multiple notify integrations or devices.

Correct. 2 adults have S21s, but the teenagers don’t. A notify group per person sounds like a good idea to make the names consistent. I already have one for parents, but in this case I want everyone notified individually.

Let me know the naming format you will use for the notify groups.

Ok, the services will just be

notify.mark
notify.otherfirstnames

In that case you can easily template the service call using trigger.to_state.object_id

alias: example
trigger:
  - platform: zone
    entity_id:
      - person.mark
      - person.jane
      - person.alex
    zone: zone.home
    event: enter
action:
  - service: 'notify.{{ trigger.to_state.object_id }}'
    data:
      message: 'your message goes here'

EDIT

The Zone Trigger supports multiple persons but not multiple zones. So if your goal is to use just one trigger supporting multiple persons and zones, then you will need to use a State Trigger and a bit more templating (or relax the requirements and allow for multiple Zone Triggers).

Thanks so much! Duplicating triggers and changing the zone is a reasonable compromise. The heavy lifting is associated with the actions anyhow.

You’re welcome! Glad to hear it met your requirements.

Please consider marking my post above with the Solution tag. Only you, the topic’s author, can select and mark one post to represent the Solution. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information, refer to guideline 21 in the FAQ.