Using multiple trackers in groups to detect presence

Nice guide. I was speaking to you on Reddit about this!

1 Like

While this is a great workaround, I somewhat feel there should be a global setting to set / flip the default tracker logic to the users preference…

Any away or any home.

Which beacons do you use ?

Lars

I opted for a few of the RadBeacon USBs:

Thanks!

One question though - I use a group for ‘all occupants’. If each occupant is a group, can I nest each ‘occupant group’ into the ‘all occupants’ group?

I will test this soon when I get a chance, and edit an answer (if not already answered)

In the config I describe, you’ll wind up with a card in the HA UI for each user, and each user will have the devices “belonging” to them under their names. Those cards technically aren’t a “group,” though I suppose it makes sense to think of them that way since the user’s devices are… um… grouped. :wink:

That’s thanks to these entries in groups.yaml:

user1: device_tracker.user1_owntracks, device_tracker.user1_nmap
user2: device_tracker.user2_owntracks, device_tracker.user2_nmap
user3: device_tracker.user3_owntracks, device_tracker.user3_nmap

The presence of all users together – so all users, and all of their devices – is then handled by entity_id: group.all_devices. That’s not anything that you have to code; it’s an entity provided by HA. Here’s what’s in my automations.yaml that acts on the state of entity_id: group.all_devices:

  - alias: Group is away
    hide_entity: True
    initial_state: 'on'
    trigger:
      platform: state
      entity_id: group.all_devices
      to: 'not_home'
    action:
      - service: homeassistant.turn_off
        entity_id: light.garage_group_presence

(Not to confuse the issue but in the above, that’s not really a “light” in my system. It’s virtual – a kludged on/off to keep track of who’s home and who’s not.)

Does that answer your question?

2 Likes

Yes, thanks. I have implemented this and it works great.

Regarding the approach I was thinking about - I am using a custom UI, the ‘Tiles’ interface - Custom UI: Tiles - which relies on Groups for the display. So I tried to nest the “device groups” (Kelly and Matt) into a group used for “anyone home” (the ‘Us’ group) - and as you can see here, it worked. So it does appear you can nest groups to achieve your approach.

image

Hey there, thanks for sharing your setup. It definitely seems to work out fine. I’m curious though if you have found a way to add the icon on top of the default view showing the device tracking, but then as group. Because groups (like the group of device trackers) of course are shown as tile and not on top…

My setup makes pretty extensive use of groups and views, and I have a group named Presence and Sensors. At the top of that tab is where my three user cards appear. Maybe that would work for you? In config.yaml:

group: !include groups.yaml

And then in groups.yaml:

default_view:
  view: yes
  name: Name_Of_View
  entities:
    - group.User 1
    - group.User 2
    - group.User 3

Each user will have his own tile, but they’ll all appear at the top if you list any other entities/groups after that. For example:

default_view:
  view: yes
  name: Presence and Sensors
  entities:
    - group.User 1
    - group.User 2
    - group.User 3
    - group.motion_events
    - group.weather

… etc. …

Thanks for further sharing your setup. Interesting things to configure and try out.

I conclude that showing an icon with home/away indicator from a group isn’t a possiblity. Maybe something for a future release!

Someone’s probably figured that out. I haven’t tackled that one, but I’m sure it’s doable. What I did do (of necessity) is to have users’ presence turn on/off virtual switches: one for each user, and then another one representing the group. My instance of Home Assistant is part of a larger system, and I use the virtual switch on the HA side to communicate presence conditions to that larger system. So in addition to the cards, there’s also a visual indicator of presence from the switch position.

Those virtual switches are what I was referring to in that earlier post in this thread.

Reviving this to say thanks and share a quick template sensor i threw together.

- platform: template
  sensors:
    josh_home_away:
      friendly_name: Josh
      value_template: >-
        {% if is_state('group.josh', 'home') %}
          Home
        {% elif states.device_tracker.josh_phone.state != 'not_home' %}
          {{ states.device_tracker.josh_phone.state }}
        {% else %}
          Away
        {% endif %}
      icon_template: >-
        {% if is_state('group.josh', 'home') %}
          mdi:account
        {% else %}
          mdi:account-outline
        {% endif %}

I haven’t done a ton of testing on it yet but basically it checks the group status for home first. If not home it will check for the status of the Owntracks device. In my case this is ‘josh_phone’. If a zone is found then that will be displayed. And finally it gives up and displays Away.

The icon template will flip from a blue user icon if home to an outlined icon if not home.

With a little work I may be able to build this sensor into a package that loops across a specific groups such as ‘users’ to auto build these sensors when HA starts. Not sure on that tho as I’m still very new to package building.

EDIT: I built this so i could hide the card with multiple devices in it and display a single presence icon/status in my Presence view.

2 Likes

Nice work!

How it works? I mean, when given group is considered as home or out of home? Does all the tracker’s need to have the same value? If not, which one has the priority?

Say you have four family members who are tracked:

Fred
Sally
Big Sis
Kiddo

If one of the individuals is home, then the Group is considered to be Home. That’s handled by Home Assistant automatically, and otherwise there is no priority or dependency among the individual trackers. But you could pretty easily create automations based on, say, when Fred and Sally are Away but Big Sis and Kiddo are At Home.

When using groups have you figured out a way to show if your in a zone?
Mine show only home or away, even if owntracks is in a zone.
i have a workaround for now usind nodered and mqtt but if you have a better soulution im interested

Yes, it’s not hard. You use Region Monitoring

https://owntracks.org/booklet/features/location/

in OwnTracks in conjunction with Zones in Home Assistant

Once you’ve got a good system going with your own mobile device then you can Export Waypoints from OwnTracks to easily share the list with other users. Your recipient just imports them.

Did you figure this out? Would you mind share your solution?
Thanks

Here’s what my setup looks like. Is this what you’re after?

The 4 boxes to the left are for each of the four family members. The zone’s name will show for each person if the name of the zone is known; otherwise it shows “Away.”

My entire system is really three systems that work in tandem. So the right box is for presence switches that talk to those other systems.

1 Like

I’m wondering how the group approach compares to using a bayesian sensor approach. Certainly easier to do this way, no need to figure out percentages, but do you get “better” results by using a bayesian approach, which, if I understand correctly, can still get a good result even if one of the trackers is misreading?