0.94.1 - Person Component, multiple device trackers and defined Zones

So I think I understand how the Person entity’s state can be unknown when one of its “input” trackers (or its only input tracker) is owntracks. I just did a test and discovered Person changing temporarily to unknown. In this particular test I didn’t see it in the UI because it was only in that state for less than 0.2 sec. I did however see it in the logs.

I made it happen by forcing an update from the Owntracks app. There were actually two updates in HA, where the first had the owntracks device_tracker entity’s source_type attribute set to None, followed almost immediately (less than 0.2 sec later) by another update where source_type was set to gps.

I then looked at the debug messages from homeassistant.components.owntracks.messages and found this:

$ grep -F homeassistant.components.owntracks.messages home-assistant.log
2019-06-12 09:10:40 DEBUG (MainThread) [homeassistant.components.owntracks.messages] Received {'_type': 'location', 'acc': 14, 'alt': 149, 'batt': 97, 'conn': 'w', 'lat': xxx, 'lon': xxx, 'tid': 'pb', 'tst': 1560348597, 'vac': 2, 'vel': 0, 'topic': 'owntracks/xxx/xxx'}
2019-06-12 09:10:40 DEBUG (MainThread) [homeassistant.components.owntracks.messages] Received {'_type': 'location', 'acc': 14, 'alt': 149, 'batt': 97, 'conn': 'w', 'lat': xxx, 'lon': xxx, 't': 'u', 'tid': 'pb', 'tst': 1560348597, 'vac': 2, 'vel': 0, 'topic': 'owntracks/xxx/xxx'}

They look almost identical, but if you look closely you’ll see the second has 't': 'u' whereas the first does not. Turns out, this 't' value is used to determine the source_type. If the value is 'c' or 'u', then it sets source_type to gps, but if it’s missing (like it is in the first message) then source_type is set to None.

It seems that sometimes owntracks is not setting the source_type correctly. (In this case it wasn’t noticeable, but apparently there are plenty of cases where it is noticeable.)

So that probably needs to be looked into on its own. But, this is how it affects the person component…

The logic in the person component, when looking at all its “input” trackers seems to have a flaw. If the source_type is gps, then that takes precedence. But if the source_type is not gps, then its only used if the state is home or not_home – i.e., it’s not in a zone. To be clear, if the source_type is not gps and the state is the name of a zone (i.e., not home or not_home), then the state is ignored!

I would classify this as a bug. I think I’ll open a pull request to fix this…

1 Like