custom-components / places

Component to integrate with OpenStreetMap Reverse Geocode (places)
GNU General Public License v3.0
110 stars 22 forks source link

Update Places sensor with person sensor? #256

Closed shanelord01 closed 7 months ago

shanelord01 commented 7 months ago

I have a number of device trackers under each person.

The least reliable for "At Home" detection is the iCloud v3 HACS (using since Life360 decided for profits over people).

Best "At Home" detection is the Unifi Network plugin (ie when the users device connects to WiFi I KNOW it is at home).

At the moment, the "sensor.person_name" I have setup in Places which is set to track "person.person_name" doesn't override the iCloud v3 HACS location, even though the Unifi one knows the persons device is at home.

The result is my "person.person_name" shows on the HA map as at home (recent update unifi device tracker), but the "sensor.person_name" shows them at the last place the iCloud tracker detected them, which sometimes updates to home and sometimes doesn't.

Is there a way to prioritise which device tracker to trust?

Snuffy2 commented 7 months ago

Home Assistant controls the prioritization of what sensor to use when for a Person sensor (see the logic here). However, the issue you are likely seeing is that when the Person sensor changes to the Unifi Network plugin, there are no longer any GPS coordinates in the Attributes as it has a Source Type of router rather than gps. Thus, places is not able to evaluated the Person Sensor's location as it relies on the presence of lat/long coordinates.

shanelord01 commented 7 months ago

Interesting.

So if there was some way for the Unifi plugin to share a fixed GPS coordinate for my location (home) when a device is detected, that would likely resolve it?

If I can’t get them to change that, would there be any way to have places have an option to detect it as higher priority home location - or have the option in places to set home lat/long to a router type like this?

Snuffy2 commented 7 months ago

Not sure if that is actually possible as lat/long is not part of the spec for router-type device trackers.

I suspect if you look on the HA logs around the time your person sensor changes from using the GPS device tracker to the router device tracker you will see a warning saying that no lat/long can be found for your person.

One thing I could consider doing is for person sensors, when the device tracker in use is a router-type without a lat/long, show the state of the person sensor in the places sensor.

Snuffy2 commented 7 months ago

The more I've been thinking about it and trying out some build, I'm not sure that doing what I said above will work. Since the state of the person sensor would essentially just be a zone, the rest of the attributes would all be blank. That would make many of the display options end up with a blank state. I'll keep brainstorming, but I'm not sure there is a great solution as places is built around a lat/long.