Detecting if a person in group is in group of zones

I want to notify the persons at home if any of us is in any of the registered grocery stores.
Basically:

group:
  family:
    entities:
      - person.bob
      - person.alice

  grocery_stores:
    entities:
      - zone.kwik_e_mart
      - zone.slurm_r_us

How can I create a trigger if alice or bob enters kwik_e_mart or slurm_r_us?

So for entity_id I set group.family and zone set group.grocery_stores?

You will have to set two triggers - one for “bob” & one for “alice”. and two zone events per device tracker.

automation:
  trigger:
    - platform: zone
      entity_id: device_tracker.bob
      zone: zone.kwik_e_mart
      # Event is either enter or leave
      event: enter # or "leave"
    - platform: zone
      entity_id: device_tracker.bob
      zone: zone.slurm_r_us
      # Event is either enter or leave
      event: enter # or "leave"
    - platform: zone
      entity_id: device_tracker.alice
      zone: zone.kwik_e_mart
      # Event is either enter or leave
      event: enter # or "leave"
    - platform: zone
      entity_id: device_tracker.alice
      zone: zone.slurm_r_us
      # Event is either enter or leave
      event: enter # or "leave"

There might be a more compact way but I don’t ever use device tracker groups so this is the way I would do it and it should work even if it is a bit long.

I know I can create triggers when a specific device tracker enters a specific zone. Would be nice to trigger any person in group enters any zone in group and notify the rest Hay, Alice is at Kwik-E-Mart, need anything?

Sorry, I don’t know of a way to do that with groups since the device tracker group only shows home & away based on the status of both people in the group. if one person is not home the group is away if both are home the group is home.

I don’t know what the status of the group is if both are in the same zone (other than home) but that would defeat the purpose of your use case even if they did.

The zone trigger can accept a list of entity_id's, so one zone trigger can make the automation fire when any of the entities enters a zone. So you’d need one trigger per zone.

The state trigger can also accept of list of entity_id's, but it can also accept a list of to values as well. And when person entities enter a zone (as far as I know, because I don’t use them) their state changes to the friendly name of that zone. So one state trigger could do it all. Unfortunately, I don’t believe you could use the groups; you’d have to directly specify the entities and zone friendly names. So something like this:

trigger:
  platform: state
  entity_id:
  - person.bob
  - person.alice
  to:
  - Kwik e Mart
  - Slurm R Us

Of course I just guessed what the zone friendly names are. Change them to what you have them configured as.

The nice thing about this is that in the action you can use trigger.to_state.name and trigger.to_state.state for the name of the person that triggered the automation and the name of the zone they entered, respectively.

I haven’t exactly tried this, so let me know how it works for you and if you need any help (if you decide to try it.)

1 Like

Works like a charm. Here is my complete automation snippet

- alias: Notify when someone is at grocery store
  description: ''
  trigger:
  - entity_id:
    - person.fredrik_rambris
    - person.kerstin_rambris
    - person.frank_rambris
    platform: state
    to:
    - ICA Maxi Trelleborg
    - ICA Kvantim Karlssons Svedala
    - Matöppet Beddingestrand
  condition: []
  action:
  - data_template:
      message: '{{ trigger.to_state.name }} är i {{ trigger.to_state.state }}. Ska
        vi ha nĂĄgot?'
      title: Affär
    service: notify.mobile_app_pixel_3_xl

Notification service to be changed to something better.

1 Like

This looks like a great solution, but I’d love to have a zone reference in the trigger to: field, in the automation snippet above, if the name of the zone ICA Maxi Trelleborg changes to something else, the automation stops working. Is there a nice way to fix that?