Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed source priority for Person #21479

Merged
merged 14 commits into from
Feb 28, 2019
Merged

Changed source priority for Person #21479

merged 14 commits into from
Feb 28, 2019

Conversation

gorynychzmey
Copy link
Contributor

@gorynychzmey gorynychzmey commented Feb 27, 2019

Description:

Added GPS accuracy to Person.
Changed source priority for Person. Status of Person determined next way:

  1. If there are sources with status 'home', than latest of this sources will be taken.
  2. If there are sources with source type 'gps', than latest of this sources will be taken.
  3. Other wise will be taken latest source with status 'not_home'.

Docs PR:

home-assistant/home-assistant.io#8773

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

homeassistant/components/person/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/person/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/person/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/person/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/person/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/person/__init__.py Outdated Show resolved Hide resolved
@gorynychzmey gorynychzmey changed the title Added GPS accuracy to Person Changed source priority for Person Feb 27, 2019
Copy link
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test and this will be ok to merge

Changed test for rounding of coordinates.
tests/components/person/test_init.py Outdated Show resolved Hide resolved
tests/components/person/test_init.py Outdated Show resolved Hide resolved
tests/components/person/test_init.py Outdated Show resolved Hide resolved
tests/components/person/test_init.py Outdated Show resolved Hide resolved
@ghost ghost assigned balloob Feb 28, 2019
@balloob balloob merged commit 4a45510 into home-assistant:dev Feb 28, 2019
@ghost ghost removed the in progress label Feb 28, 2019
@balloob
Copy link
Member

balloob commented Feb 28, 2019

Awesome 🎉

Please make a PR to update the docs to describe the new behavior.

for entity_id in self._config.get(CONF_DEVICE_TRACKERS, []):
state = self.hass.states.get(entity_id)

if not state or state.state in IGNORE_STATES:
continue

if latest is None or state.last_updated > latest.last_updated:
latest = state
if state.attributes.get(ATTR_SOURCE_TYPE) == SOURCE_TYPE_GPS:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking source GPS first, before state home, doesn't match the PR description. Is the logic correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MartinHjelmare, yes. If there are other non-GPS devices, which shown 'home', they'll be got prior to GPS in next conditions block.

Copy link
Member

@MartinHjelmare MartinHjelmare Feb 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be clarified in the PR description and in the docs, if it's not done already.

Also, it would help to add examples that explain why this logic is better than the previous logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if state.attributes.get(ATTR_SOURCE_TYPE) == SOURCE_TYPE_GPS:
latest_gps = self._get_latest(latest_gps, state)
elif state.state == STATE_HOME:
latest_home = self._get_latest(latest_home, state)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we call this latest_non_gps_home or something? Since we're excluding GPS from this group.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #21528

@arsaboo
Copy link
Contributor

arsaboo commented Feb 28, 2019

@balloob @MartinHjelmare The PR was merged before I could comment. Maybe I am missing something, but it looks like this is the opposite of what we should be doing. GPS trackers are more accurate and should be prioritized over wifi and BT trackers. However, it seems, we are doing the opposite here. Based on the examples, we are using the less accurate trackers (tracker_ble and tracker_router) to determine state. Given the consider_home property, they will always be slow to update and we should not prioritize them over GPS trackers. I follow this logic in my python_script that works 100% with 5 device_trackers. I did not want to add comments on the docs PR as the comments are related to the underlying logic and not the docs.

So, when we are home, what happens when tracker_router goes not_home due to wifi sleeping?

@MartinHjelmare
Copy link
Member

We should open a new architecture issue to discuss this. I definitely think this needs more discussion. But I don't know myself that the new logic is worse. But I think we should discuss it. There were some comments mentioning a similar logic as is now implemented in the old architecture issue.

@gorynychzmey
Copy link
Contributor Author

gorynychzmey commented Feb 28, 2019

@arsaboo, when tracker_router goes not_home, then priority receives one of the other trackers. If tracker_ble still shows home, then it will be primary source, otherwise tracker_gps. So wifi sleeping is not an issue.
I have frequently the situation, when my Google Maps tracker gives location outside of my home while I'm definitely at home. So I think that stationary trackers are more accurate in question of detecting home (with adjstment to 'consider_home'). On the contrary GPS is more accurate in question of detecting zones outside of home.

@arsaboo
Copy link
Contributor

arsaboo commented Feb 28, 2019

I am happy to test the new logic out in the beta, as I am still using the meta tracker script for all my presence and can compare the two. However, with the logic in this PR, the tracker will behave only in the most optimistic case. In the more realistic scenario or if any of the trackers misbehave, we will certainly have worse outcomes.

For example, based on the docs PR, You're going out. 'tracker_gps' shows status 'not_home', but other two trackers show status 'home' according to their setting 'consider_home'. You are still considered to be at home., is definitely incorrect.

I have not played with Google Maps tracker and may be that is an issue with that specific tracker. I am currently using iOS app, Owntracks, Geofency, Life360, and Unifi trackers. Overall, in my experience and in discussions with other users, GPS trackers are significantly more accurate.

We should not penalize all GPS trackers just because one tracker is misbehaving. In fact, your experience raises another issue. May be we need to let users decide the priority based on how well these trackers work for them. I, for one, would certainly like to prioritize GPS over others.

@gorynychzmey
Copy link
Contributor Author

@arsaboo, in new logic we prioritize not all stationary trackers against GPS, but only in question of detecting home. But you've given me an idea - specific warning needs to be added in documentation, than with multi-tracker configuration, especially when it contains GPS devices, consider_homemust be set as low as possible. In this case prioritized stationary trackers will show homeonly when device indeed at home and connected. When such device will disconnected, GPS will receive priority.

@MartinHjelmare
Copy link
Member

It would be better if we can continue discussion in an architecture issue. Please open one.

@arsaboo
Copy link
Contributor

arsaboo commented Feb 28, 2019

I created one to get our discussion started home-assistant/architecture#163

@balloob balloob mentioned this pull request Mar 6, 2019
@sbienia
Copy link

sbienia commented Oct 16, 2019

Hey
I have beacon in my office, I use OwnTracks as device tracker in person. When owntracks publish (source bluetooth_le) that I’m in office zone, person is not updated, only device tracker. It happens because gps has priority and in else block you have only home and not_home. Can you fix it?

@frenck
Copy link
Member

frenck commented Oct 16, 2019

Hi there, @sbienia, please don't comment on merged/closed PR's.

If you suspect an issue, please create one on our main GitHub repository. That will allow us to track it. Thanks! 👍

@home-assistant home-assistant locked as resolved and limited conversation to collaborators Oct 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants