-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add per-proxy distance sensors for configured beacons #99
Comments
That's awesome - you've got more proxies than me, too! :) Take a look in the configure dialog, my guess is you might have the max radius set to 3. I have mine set to 30 (and 20 is the new default in future releases). I suspect that's why it's going Bear in mind that having it high also means that the area sensor won't be a reliable indicator of Perhaps I should add another option for how long to wait before declaring an area device That's interesting re the cessation of updates after restart, I thought I had fixed that :-/ I'll be making changes in that area before I'm ready to release so hopefully it will be addressed there. Did you notice any warnings or errors in your logs at that time? What's really cool is going to the history page and adding an entire device. So... much... data! 😻 Hopefully that will help me come up with much better algorithms for tracking distance and area - it's already shown how obviously bad the decisions are. |
You're right. I had forgot about those settings. Max radius now set to 4 and much better. I have found the new code restores updates on the area and distance sensors when the device returns home, even after a HA restart. However if there is a restart, the device_tracker also goes unavailable but does not recover when the device returns home. A Bermuda reload is required while the device is home. Might I suggest to help prevent devices flipping between proxies while it is stationary, an outlier plus low_pass filter seems to work wonders in the graph. If this was added to the distance logic before the area is decided, it may help. Here are 4 proxy distances on one of the car's bluetooth beacons. And here are the distances cleaned up with Here they are overlaid to show the latency is still low. Notes:
|
That's great! You're definitely showing much-improved data from the filtering you've applied. I agree that if we used the filtered data to make the area decision we'd get far fewer spurious switches between areas. Partly the issue is that currently I look at the recent adverts, and if the current area hasn't seen a packet for a while (currently The lag is pretty good, as you note - I expected it to be worse. Due to the asymmetry of the noise, and the nature of when we want low-latency (typically, we want entering an area to be fast, but leaving it can be slow) perhaps we can influence how the filtering treats decreasing values (ie, follow them fast) versus increasing (follow them slow).
Yes, it could be polarisation, but it could also be the proximity to anything else in/near the enclosure - with a 1/4 wavelength of 3.1cm the amount of variation caused by seemingly small differences can be insane! It does look like it was relatively consistent though - I wonder if that is dependent on the direction of the signal or if it's inherent to the receiver? Ie, if Max were parked a few metres down the street would the gate light still read lower or would the relationship change? I think there might be a lot of variance in receiver sensitivity (which we can calibrate out) but so much of it is also environmental. Like garage doors, as you say!
Oh that's a super-interesting link! I'm temped to dig deeper into the background-packet they identified, although the answerer's blog page indicates that iOS 12 changed to using scan-reponse packets for the same info, which makes it less useful I think. Have you got Private BLE Device set up to resolve the IRK on your iPhone? I'm keen to integrate with it but it'll be a bit of a hassle for me to set up a testing environment here. |
Sorry, been tied up with another project (esphome/firmware#173) and an eye cataract operation which has delayed things a bit. Interesting point on the asymmetry of RSSI. I can try for a filter that prioritises higher signal strengths.
Yep, I've been using Private BLE for many months on 5 phones to verify if anyone is home or not and to lock doors and such when the last person leaves. It's real easy to set up, just needs someone to accept a pairing from my Mac laptop once and then remove it. The IRK remains in the Mac's keyring for searching at leisure. Happy to do some testing when you're ready. |
Oh dang, hope all goes well with the op recovery! That voice work looks really cool, I don't have any hardware yet (just as well, plenty of stuff to play with already!) but I hope to give the voice stuff a crack when I have the time. I'm spinning off a new ticket for the issue you noticed re device trackers after a restart that stay unavailable until a reload. |
@agittins Following a comment you made about a filter to take into account the asymmetry of RSSI signal noise and that it is okay to have some latency when leaving an area but have a very quick response when approaching an area, I have been testing a simple MIN filter which just uses the minimum value over the last x samples for each update. Here are two bluetooth beacons on the cars, Max & Suma: The receiver (proxy) is the same Shelly for both. Physically, Suma is 2m from the Shelly and Max is 0.8m. Max is a Tesla with built in Bluetooth and antenna. Suma is a MicroTik iBeacon puck taped above the passengers sun visor. We can see that the Suma beacon is a lot noisier and has a larger variance (1.2m-4.5m) than Max (0.5m-1.3m). Suma has outliers up to about 8m and Max up to about 29m (I have seen one or the other go up to about 60m sometimes). Here are the signals cleaned up with the MIN filter. Suma is using a sample size of 19 and Max is using 14 (I chose these as the smallest sample_size that would remove 99% of the noise, but lower values may be acceptable). There is a difference in the duration of the 'noise' between the transmitters, hence the different sample sizes needed. The original and filtered overlaid to see latency: When Suma was leaving this morning we can see a 16s lag in the filtered trace (makes sense, 19 samples at about 0.9 / sec) but, although hard to see, the trace drops back to the original with ZERO latency if there is a drop in RSSI. On a side note, a heads up that due to the large number of these distance sensors, each with many attributes, together with the high rate of change, my DB size started going exponential. Fixed in
I didn't exclude the garage sensors as I'm using them for the tests. You may have less proxies, but worth checking DB size just in case if you haven't already. Aim to keep at least 1.5x DB size as free space, otherwise backup restores can fail and brick your HA (happened to me over the new year just gone). EDIT I wanted to note that I am still using a max radius of only 4m otherwise the cars start jumping around all over the house and that's not good for the furniture. |
Awesome, thanks for trying it out - looks promising. You might have to swap your living room windows with your garage door for better RF consistency. I'm sure the household will understand. I think you're right about database size. My 108GB postgres database isn't too worried but people might start sending me invoices for replacing their worn out SD cards :-/ I think having the 1-second updates to the backend data works well because it's cheap (updates only take 0.009 seconds on my production), it makes the math easier for me and allows us to respond quickly for area changes etc, but the sensor updates on the front-end (and db) are too frequent for everyday use. I think what I'll do is throttle the sensor outputs a bit. They will instantly change to lower values, but will hold off updating for higher distances until a percentage threshold or timeout (eg if 5 seconds elapses, or if the value increases by more than 100%, perhaps). That might give the best of both worlds, with the smoothing going on in the background, and sensors snapping to area approaches nicely, but relaxing about retreats (which if they are at the same time as an approach to a different area should still work out well). I'll also round the sensor distance values to reduce the "churn" a bit further. I think I'll apply it to all the distance sensors, but I'll repurpose the config for update-interval for the sensor update timeouts, that way people can tweak the sensor min-update-rate without affecting the backend algo, and can also easily ramp it up to get instant updates while doing testing etc. Keen to get the next update wrapped and out! Just want to make sure it won't blow out anyone's config too much first :-) Then on to iphone support... |
Yeah, I think that's a good idea. I had been wondering how to limit the slope angle (ie, speed) in the filtering part, but the way you put it makes a lot more sense - examine the reading against the last cycles and reject if it implies too high a velocity. Will need an option to select between European and African, though. Could you give me a screenshot of the same graph above, but just the slice of time from 11pm to 11:05pm? I'd like to see some of the detail in that area just to see how it was tracking through those jumps. That bit where Suma popped out to pick up dinner should be fixed now, too - I wasn't expiring old readings, so a device that had gone "out of range" would still show as being that distance away. Not always a problem (esp if one has max_radius set rather low) but it can cause a device to get "stuck" in an area due to an old reading being closer than new readings in a different area. I think we'll always have instances of scratched furniture though - if an area gets a stronger signal it will (correctly, imo) register it as being the closest proxy. It might be resolvable further down the track with proper trilateration, but in this generation it's about all we can do. |
I'm going to open a fresh issue for chatting about filtering and algo ideas now that v0.5.0 is out, and this issue is well-and-truly sorted with that :-) |
(from a discussion I was having with myself while writing a comment)
Create per-proxy distance sensors for each beacon so that I can easily use the history tool to visualise what's happening with the data, including missing packets. The current distance and area sensors are good, but their data makes it clear that:
Currently the distance sensor is showing the distance from the currently "winning" proxy, which makes analysis difficult. By adding a sensor per-proxy I'll be able to see the fuller picture (with the aid of HA's wonderful history graphing) and get visual feedback on improvements with distance filtering. While the raw data is available from the service it's more difficult to visualise.
The text was updated successfully, but these errors were encountered: