-
-
Notifications
You must be signed in to change notification settings - Fork 99
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
Logic for combining device_trackers for PERSON component #163
Comments
I'd like us to avoid config options if at all possible. Besides that, I think the above sounds good. But let's hear what others think. |
I agree...we can leave the config options out as I don't think we should ever prioritize wifi/BT over updated GPS. |
As I can understand, |
We don't have to prioritize a particular tracker, we are prioritizing based on what provides the most recent information. Presence is the fundamental aspect of home automation and I am opposed to the idea of prioritizing any particular tracker as it can mess things up if it misbehaves. That is the reason I have 5 trackers :) In your example, for |
In my experience with the Unifi presence tracker, it's very accurate for determining when a device arrives at home. However, the device timeout on the Unifi controller (external to HA) is long and not obviously configurable, leaving devices marked as |
Situation with Unifi is almost alike to situation with |
I can see two things people may want here: presets and advanced configuration. Presets are nice, but there will be people with very specific needs not covered by them. With the advanced configuration scenario, I can see a per person, per device tracker setting. This would require an alternate schema for the device_tracker list though. Advanced config and presets can even be mutually exclusive to help keep things simple. When more likely configurations are figured out, then I think would be time to pre-configure things with presets. ie (added some random keys for demonstration purposes): person:
- id: me
name: Me
device_trackers:
- entity_id: device_tracker.track_me_1
consider_not_home: 5
consider_home: 30
priority: 2
force_if_not_home: true
- entity_id: device_tracker.track_me_2 |
@Chris-V While it will be great to have such fine-grained control, we should weigh it against the complexities and move gradually towards such options. As a first step, we should try things out without any config options as @MartinHjelmare suggested. |
Something to consider, though, is that we are talking about moving or remaking the I still think we should be careful before adding config options, but it's good to consider the big picture and changes we are planning. |
If we move all the "intelligence" to the |
I'm not sure that makes sense in all situations. It makes sense when all you are trying to keep track are people but what about object detection or animal detection? For example, I could have multiple device trackers in my car that I may or may not want to combine. In that scenario I'd certainly want the ability to adjust consider_home and consider_not_home depending on the tracker but I wouldn't want to create a person entity for that. The same with a dog for example, if I had a smart dog door and tracking collar, I'd want to customize consider_home and consider_not_home but it would feel odd to set up a person entity, especially since a dog would never login to Home Assistant. |
Currently |
I'm glad we are getting this discussion going. The config example by @Chris-V is great, but out of scope for now, and we should not further discuss that in the current issue. Our config format is capable of expanding to it in the future, if necessary. @rohankapoorcom I think that we should focus on tracking humans for now, and so we should not consider supporting alternative tracking approaches for cars/dogs. I think that we can consider expanding scope or add a new component to track objects/animals/etc in the future. Also note, you can create persons that are not connected to a user, so you could still track your dog without giving them login credentials. Things like May I propose that when people suggest algorithms, let's describe how the algorithm should work in pseudo-code, and not sentences. That will make it easer to compare results. Proposal based on what I have seen so far:Person to adopt latest updated state for which any of these checks is true:
Person to adopt battery level attribute of latest updated state that contains battery_level. When a tracked device tracker state of the type |
That is an excellent summary. I am assuming 5 minutes should be sufficient time for wifi/bt devices to wakeup. |
Hi team, So from my own personal use case point of view, the "Person" component is rather binary for my liking. I had the same issues with Underneath the hood, I think that the current implementation of using device trackers for a person is fine. However, I would also like the ability to have this expanded, to perhaps binary sensors. After all, most of the status is just on/home, not home/off. For this reason, it would be good to allow a Bayesian sensor (or any other The reason I mention the bayesian sensor, is my current feeling towards the person entity. Right now, if my phone is connected to wifi and bluetooth, if I turn off my bluetooth, but my phone stays connected to the Wifi, I am marked as away, as that was the last entity to be updated. (I may be wrong here, if I am please accept my most humble apologies). For me, I would like the ability to "fine tune" the way in which the person component knows if I am home or away. Not based on a device tracker updating, which could change frequently if I move in and out of Bluetooth range. Now what I would love to see in the person component, is an implementation of my Not so binary presence. I would love the person to have two kinds of states, person:
name: Phil
states:
Just Arrived:
state: home
for:
seconds: 0
Home:
state: home
for:
minutes: 15
Just Left:
state: not_home
for:
seconds: 0
Away
state: not_home
for:
minutes: 10
extended_away:
state: not_home
for:
hours: 24 As mentioned I use this logic currently based on templates and dropdowns, which allows me to do some automations which trigger as a person gets home for the first time, and then move into another mode etc. Just my 2c |
Although 5 min seems like a sane timeout, some trackers update when leaving a zone much faster than that. Requiring a wifi/bt tracker to timeout first to Zone exits seem inherently unreliable for wifi/bt/ibeacon tracking methods. Perhaps they can be given top priority for arriving but relied on far less for remaining in or exiting the zone? |
My logic is quite simple. If any non gps tracker is home, the person is home else set same state as gps tracker unless gps tracker did not report new data in an hour so we dont get stuck Home if we are away a long time. This works most reliable of any logic I tried. I imolemented a appdaemon app to use it. In the Swedish community quite a few people use it and are happy with it. Non gps trackers are normally reliable on home state but can be false positive in not_home state due to battery savings in mobiles. With this logic and use 3 trackers , gps, BT and WiFi(router) it is very acccurate. Not so binary logic I also implement with just arrived and just left logic. I tend to do automations on when just arrived. I suggest we wait to implement the "not so binary" logic. Better to manage the device prio first. Let’s Make it stable before next step. |
Currently state of One more thought to tracker state combining: not only routers have time, when they doesn't update state after device is disconnected. GPS is also not immediate and makes update not every second. So we always have periods of time, when state of our sensors not reflect real things. I think that we should assume that we always have some delay between reality and it's representation in Home Assistant, but our task is simply to make this delay as low as possible. I believe that it can be done by manipulating with device_tracker:
- platform: traccar
- platform: fritz
consider_home: 60
person:
- id: me
name: Me
device_trackers:
- entity: device_tracker.track_me_traccar
consider_home: 30
- device_tracker.track_me_fritz |
Except... I find the opposite. My GPS tracker will take 10 to 15 minutes (or so) to mark me as home or away. That's why I'm using much the same approach as @helto4real (and also make use of much of @philhawthorne's awesome non-binary logic - except for my extended away logic being based on distance from home). As long as one of BT or WiFi shows me at home, they win over GPS. Indeed, GPS showing somebody at home, but WiFi and BT not probably means that they're at the neighbours. |
As a non-coder, mere user, my feedback is simple: Please give us the ability to make our own decisions. We're using open-source software for a reason: flexibility. Let us establish our own rules, our own priorities, and then you guys guide us on the pros/cons of each option if we're getting it wrong. That's what the docs are supposed to be for. What is the most intuitive way of doing that? IMHO, priority should be given in the order that the trackers or sensors are listed in the config. Don't second guess us. Doing so is most peoples' complaints about Google: your logic and AI don't always mesh with our expectations as users, and the decision that you (Devs) make in this thread have to be consistent for the rest of HA's life or until you have this debate again. A new device tracker is released that is killer accurate in 5 years from now, integrated immediately into HA, but it's not GPS-based so it falls to the end of the logic - now you guys have to update the logic and have this debate again. I set up my system to use Wifi with appropriate timeouts, notwithstanding that Google Maps integration is available? Let me override the GPS-heavy logic - I've built in the necessary delays in my automations already. You guys are knocking it out of the park with this project. Don't over think it. Users can learn from tools that are too flexible. Users stop using tools that become inflexible. |
@databoy2k, seems to be that your idea comes to simply iterating through device trackers in order, in which they're appearing in config, and searching for first tracker, which returns something different than 'not_home', right? |
One more potential problem with prioritizing BT/router/etc tracker sources is when using non-home zones. Perhaps I have a GPS tracker that marks me at my |
@jjlawren, restart of HA is always the special case. After restart reliable status will be only atfer all (or almost all) device trackers got updates. GPS trackers usually make updates with bigger intervals to lower battery consumption and probably will be last. |
I think so, yes. Or prefer marked Zones to deal with @jjlawren's comment. I'm mostly responding to the suggestion that there needs to be an overarching logic that can't be configured; on the flip side, rather than creating some arcane set of rules that we might start cussing in 5 years time, I'm advocating for allocating complete manual control of priority to the users via config. |
@databoy2k, I think that it quite good idea to make priority by config order. I want only to expand and evolve it. person:
platform_priorities:
- unifi_direct
- buetooth_le_tracker
- google_maps
- traccar But this will require, that every device tracker entity should have attribute device_tracker:
- platform: unifi_direct
priority_tag: wifi
- platform: buetooth_le_tracker
priority_tag: ble
- platform: google_maps
priority_tag: gps
- platform: traccar
priority_tag: gps
person:
priority:
- ble
- wifi
- gps |
FWIW (and again, coming from strictly a user standpoint, and just one of the many at that) I don't think per-user is a bad idea or undesirable. I can think of lots of use cases where defining priorities based on the person, rather than globally, is a better alternative. Besides: you have to define trackers by person anyway, so the only use case for setting priorities by platforms is where you have multiple persons (perhaps significant numbers) and you're experimenting with the different orders. The cost of that is the loss of individuality; maybe GPS is the correct priority for my wife and my phones, but if I want the alarm system to shut off when the inlaws come in then Wifi is the best priority for them. Again, I'm probably not the best guy to be engaging in this discussion too deeply as a non-dev, but when the decision gets made, I seriously hope that flexibility remains the guiding principle, even if it is at the expense of a few extra keystrokes. Better to have a truly flexible system that allows full user control, even if it means that the users have to think about the best priority order that works for their respective systems. |
I just got triggered by a sentence in one of the above comments:
Our flexibility offering is that you can just copy our component into the custom component folder and make any changes that you want. By doing so, your flexibility does not come at the expense of offering a sane and usable defaults that will be enough for 90% of the users or at the expense of our developers time. So right now, we should be discussing default behavior for person component. Going all in on per-person configuration is out of scope, as I mentioned in my initial response #163 (comment) . If we don't have sane defaults, we can't even start to offer config options. As I haven't seen any other algorithm suggestions since mine at #163 (comment) , I suggest that we just implement that and consider this issue closed. Small edit: this doesn't mean it's the final feature set, it just means that we have some default that works pretty ok out of the box. |
Flexibility doesn't just always come at the expense of "a few keystrokes". It can also cause a much more complex logic to make sure you keep undesired effects out and the worst side effect can be a less robust component with a lot of things that can go wrong. It can also make bug reporting and finding bugs a lot harder. For me open source is not necessarily the same as a super flexible solution, and not even that everyone gets the thing they think is best, there are still developers that has to make the decisions of what's best for the project in terms of maintainability and robustness. |
@balloob I would suggest one addition to your logic above, that if you have multiple trackers of wifi or bt, that maybe at least two has to be not home for 5 min. Otherwise, and also without this suggestion, I think it sounds great and will be really useful. |
I can only suggest to make check of |
Yes, I agree that not_home probably should only be set by wifi or bt if the current state is home. |
@balloob I aggree with @isabellaalstrom, if we introduce a timeout it needs to be both or there will be some cases that could trigger false positives. I also like the @gorynychzmey with the zone logic. The Zone feature that @gorynychzmey suggested could be a different PR if we feel it needs to be implemented. |
I was a bit surprised by this statement. If we want to keep person a pure person thing, then why add a "random" battery level? A person does not have a battery level. What is the use-case for battery level on person? |
As above, can we allow binary sensors as data sources? It would allow the Bayesian sensor (and all that entails), as well as other sensors types (ultrasonic car sensors, in my case) to influence home/not_home. That might be a solution for those requiring more control, and avoid adding config options to this. |
I thought the same thing as @Brianckramer. Why add all this logic to the person component? If we just had something like a "generic" or "template" device_tracker, we could implement whatever logic and combine whatever other sensors we want. Then there's really only need for having a single device_tracker attached to any person. Even with the current behavior, a "group" device_tracker could be the equivalent of what the person component does for presence. Essentially, leave all the presence detection logic in the device_trackers and just tie one of them to a person for indicating presence of that person. |
This can already be done today by using the Instead of a binary sensor, we should add a device_tracker.template ? That still should not stop us from adding sensible defaults to the person component that works for most people. |
I am using the composite tracker custom component (by @pnbruckner) to achieve exactly this. My setup is not perfect yet, but I will just have 1 device tracker in person and manage all the other "fine tuning" elsewhere. Basic defaults could work for some, and if the user needs more control a component like Composite might be for the more advanced user. Maybe we can get Composite into the HA code? |
I'm not arguing against sensible defaults. I was just suggesting putting them in device_tracker instead of person, i.e. |
Of course, that only works if the logic for Either way, that was really just a suggestion. I would prefer to see something like the |
As noted in home-assistant/core#22017, there's a current assumption here that 'stationary' trackers are always in the The PR above is not meant to open the door for tracking mobile beacons. Perhaps documentation should explicitly reflect this. |
To be more explicit about the last post and linked PR, the proposal should be updated to change:
to
This should prioritize 'stationary' trackers if they're in any zone, not just |
@jjlawren, in this case we must also add to stationary trackers an option to show specific zone as a place of presence instead of |
My example is for the HA iOS app and OwnTracks iBeacon detection methods with stationary beacons. Perhaps this concept only really applies to the |
One of the problems of the device_trackers as they are is that to make accurate tracking estimations they require to make assumptions. Example: "The device is not detected by nmap, therefore it is not at home" Example: "The device is not detected by nmap because it is sleeping, so we add the consider_home option". These assumptions are detrimental as they are because they add complexity to the tracker and more importantly because they make it more difficult to debug tracker issues (e.g. Is this tracker error caused by a physical malfunction or by a bug/missconfiguration in the assumption code?). Moving Having a distinction between "physical" and "logical" trackers would make things easier. Physical trackers would not be allowed to make assumptions, and logical trackers would be built on top of other trackers to refine them.
Removing assumptions from physical trackers would render them less useful by themselves (e.g. the nmap tracker, operating on my home wifi, would never be able to tell that a device is Having the assumptions separated from the physical tracker makes the output of the physical tracker more reliable, and gives more confidence to the user to rely on it when building his/her custom logic. |
Presence detection is tricky business! Lots of good info above. A few things to add:
Lots to consider to really get this right. |
There is one small issue in the data model that I would like highlight - which is probably encountered by any device tracker using the Current situation:
If i frame this as raw events and synthesized events (from tracker/physical tracker as coined above), I see these things:
A general device tracker can than track the state of the devices to create synthesized events that indicate the presence of an object. I do not like that this is more complex, but this is the easiest way I see to fuse observations for a device from multiple observers (use cases: multiple access points, |
This architecture issue is old, stale, and possibly obsolete. Things changed a lot over the years. Additionally, we have been moving to discussions for these architectural discussions. For that reason, I'm going to close this issue. ../Frenck |
Since the
person
component is now ready, it is now a good time to think about how should multiple device_trackers entities be combined. Based on the multiple threads on the forums and my own experience playing with 5 different device_trackers, here is the approach that I use that gives me 100% reliable presence detection. The logic relies on two assumptions:So, here's one approach to combine different trackers:
not_home
. They are far more reliable for markinghome
.home
tonot_home
, GPS trackers will typically update first and they should be used to updateperson
. Wifi/BT trackers should be acted upon with some delay to avoid false alarms, i.e., they should benot_home
for some time before we markperson
asnot_home
. This can be taken care using a slightly larger value forconsider_home
(about 10 minutes seems to work fine). Thus, in most cases,not_home
will be marked based on GPS based trackers. Worst case scenario, if none of the GPS trackers are working,person
will be markednot_home
after theconsider_home
interval.not_home
tohome
, we can use any tracker that updates first to set the state. Since wifi/BT trackers are quite reliable in this case, we don't need to delay them.We can probably provide a config option to reverse the logic if someone wants to prioritize Wifi/BT trackers over GPS trackers (not preferred IMHO).
The text was updated successfully, but these errors were encountered: