Group of persons? possible?

Have question regarding person and group,
by using person i get better presence accurancy as
i can father couple of device_tracking for each person ,
Then I want to collect persons under group
so in my automation i be able to check if group is home for example .

person.yaml

#person:
  - name: karin
    id: 321
    device_trackers:
      - device_tracker.life360_karin
      - device_tracker.karin
      - device_tracker.mi_9t_pro
  - name: avi
    id: 123
    device_trackers:
      - device_tracker.life360_avi
      - device_tracker.avi
      - device_tracker.vtr_l29_2

```
group.yaml
```
family:
  name: family
  entities:
    - person.avi
    - person.karin
```

Then , in automation i want to check if group is home/not home,
and avoid AND condition which i have .
i.e:
```
   condition:
      condition: and
      conditions:
        - condition: state
          entity_id: device_tracker.avi
          state: 'not_home'
          for:
            minutes: 4
        - condition: state
          entity_id: device_tracker.karin 
          state: 'not_home'
          for:
            minutes: 4

This is what I do.

In fact I go a bit further and use those groups to define who’s at home (adults/kids/known guests) and an occupancy state for the house.

I might be wrong but this could be set only if using some sensor ,
as group would be change to home only if all the entities belong to the group are in home ,right?
if not , would be great if u or some1 can share something similar.

I found something strange ,
In persons.yaml - as mention in first post i create 2 persons
but HA see them in other name meaning person.avi and person.avi_2
why is that?

Yeah, so I create a sensor based on the values, so…

You can see from the screenshots that the last adult to leave home today left at 8.50, but the house isn’t marked unoccupied until 10.06 because one of the kids was still at home until then. After which they mirror each other as adults come in and go out again. The last update to both is because I remotely updated homeassistant and it restarted so the states updated.

As for avi_2, no idea. Have you set one up in the gui and a second one in yaml?

Thanks,
Both coming from persons.yaml
No person created via GUI - actually i prefer everything define in the configuration files.

I found solution- dont like though …
i fix it in .storage/core.entity_registry file
the problem , in next upgrade i need to remember to do it othetwise all related automation will not work.
Maybe there’s other elegant way to customize the person name?
I wonder if this a bug in HA that name for person not coming from the yaml ,

So I just googled this thinking the same as the OP.
I want to maybe create an automation to turn all lights off when nobody is home and I am using the new Persons element (really like it actually).

Then as I was reading this, I think we are all trying to reinvent the wheel while rolling down the road.

The logic for a person is already sound, multiple trackers tied to one person to determine if they are home or not.

Then we want to group all the persons together so that we can combine that logic into a larger group.

So…

Rather than group your individual persons together, why not just create a new person and assign them all the same trackers that are assigned to your individual users? I just did this so I do not have data yet but I think it should work perfectly.

1 Like

Actually, it seems really easy to do based on the docs (look at the end of https://www.home-assistant.io/integrations/group/).

I will try it soon.

I also use a group for this (for years now) and it works absolutely fine. Example below:

group:
  persons:
  entities:
    - person.jimmy
    - person.stephanie

  persons_and_dog:
  entities:
    - person.jimmy
    - person.stephanie
    - person.tala

You could then use these groups in automations like this

- alias: all lights off when nobody is home
  initial_state: 'true'
  trigger:
    - platform: state
      entity_id: group.persons_and_dog
      to: 'not_home'
      for:
        seconds: 60
  action:
  - service: light.turn_off
    entity_id: all

But you could also simply do it without any group by creating an automation with a template. Example below:

- alias: send notification to phone
  initial_state: 'true'
  trigger:
    - platform: state
      entity_id: binary_sensor.motion_hallway
      to: 'on'
  action:
    - service_template: >
        {% if (is_state('person.jimmy', 'not_home')) and (is_state('person.stephanie', 'not_home'))  %}
          notify.all_devices
        {% elif (is_state('person.jimmy', 'home')) and (is_state('person.stephanie', 'not_home')) %}
          notify.me
        {% else %}
          notify.wife
        {% endif %}
      data:
        title: "Motion"
        message: Motion detected in the hallway!

The last examples templates can also be used elsewhere (e.g. conditions).

Hope this helps. Good luck!

2 Likes

Or just add a template sensor which is on or off when someone is home :slight_smile:

      tpl_occupancy:
        friendly_name: Someone home?
        icon_template: >-
          {% if is_state('binary_sensor.tpl.occypancy','on') %}
            mdi:home-account
          {% else %}
            mdi:home-outline
          {% endif %}
        value_template: "{{ is_state('person.1','home') or is_state('person.2','home') or is_state('input_boolean.guestmode','on')}}"
3 Likes

Hi ,
I have one question for the group.yaml thing.
If the group state is not_home , so all person state inside this group change to away ?
Because I don’t have this behaviour

My group of persons seems to behave like a person with multiple trackers. Eg, I leave home but my gf is at home, it will change the group to be not_home as that was the most recent update

this does not seem to be possible using the UI right?
On:
Home Assistant Core 2022.6.7
Home Assistant Supervisor 2022.05.3
Home Assistant OS 8.2

At least I did not find a group where is could add persons.

I honestly wouldn’t know, I did it in YAML a long time ago and it is still working so never saw the need to do it through the UI.

I know what you are taling about :slight_smile:
I preferred to use file based configurations on my previous system (openhab) for years as well.
But as a rookie on HA it’s safer to use the GUI - not as flexible though.

Anyway - I will try your approach and will see…
Thank you for your help!

EDIT:
This is not accepted:
image

and in accordance the the actual documentation this does not work either:

# For family member presence
person:
  - platform: group
    entities:
      - person.donald
      - person.trump

Error:

Invalid config for [person]: [platform] is an invalid option for [person]. Check: person->person->0->platform. (See /config/configuration.yaml, line 42).

No, you should make a group like in my example above.

Edit: I see the example has indentation issues, below should be correct

So

group:
  persons:
    name: All Persons
    entities:
      - person.jimmy
      - person.stephanie

Thank you!
Works like a charm! :smile: -)

I’ve managed to create this person group but using it in automations is not possible. as there is no “home/away” state.

how do you use this with your automations? thank you

What state does the group have?

it’s just unknown