-
Notifications
You must be signed in to change notification settings - Fork 17
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
Extending this to work with active iPhones #4
Comments
Great catch! I was wondering how to solve this issue over the weekend, and you beat me to it. I'll merge your changes in. Regarding detecting active/unlocked iPhones: Did you discover Was your thinking that if your phone is unlocked and in a room, then that is a very strong signal that you are in the room (using your phone), as opposed to just left your phone on the table? I have been looking into using Room Assistant's companion app for iPhone detection. How willing are your other household users to adding the companion app to their phone? The companion app displays a UUID to the user. This can be retrieved via BLE with the following method:
This requires connecting to the device once every ~45 min, and jumping through the hoops of getting service and characteristic IDs. TBH I don't know how to do that in a lambda, but we could probably figure that out as ESPHome BLE sensor. |
I did a bit of experimenting, and verified values of 3 when the iPhones were off/locked, and 7 when they were active. I didn't see any other values. The main problems I found were:
I haven't don't a huge amount of investigation beyond that. Perhaps there's something in the other flags that could help. |
I just did a little more digging with the status flags and one iPhone (11 Pro, IOS 14). 0x08 is listed as "Unknown" in the docs here, but in my case it seems to correspond to a recent touch interaction. If I touch the screen, it's set in broadcasts for the next five seconds or so. I'm not seeing any difference in action code or flags in getting a popup notification vs other passive use of the device. I do see the 0x02 flag (also listed as "Unknown") set occasionally, but I haven't been able to correlate it. One other thing: I sometimes see an action code of '5' instead of '7' for an active iPhone SE, but unlike what the docs suggest, there's no audio playing. |
I would be willing to test anything you need. I am not nearly as knowledgeable about this as y'all are, but I can post log miles like a maniac! |
Okay, here's something interesting: When my iPhone stops broadcasting its Nearby Info messages (0x10) because it's in an app with a WKWebView, it instead starts broadcasting handoff messages (0xc) using the same MAC. As far as I can tell, there's no easy way to passively differentiate between handoff messages -- I also see them broadcast from my macbook, but we could do something stateful in the lambda code to keep track of recently observed phones and interpret a handoff broadcast the same way as the active signal. |
Thanks for all the info and discovery work. I've still got to get to the bottom of why my iPhone Xs / iOS 14 is not detected, even with my MacBook close by. Hopefully get to that tomorrow. |
Here's the current version I'm running with some success. I've decided that a local MacOS device broadcasting handoff messages is 'active' too and counts as a valid signal for room presence.
|
Looking at this again, my code for recording the closest RSSI is, of course, total bollocks. :-|
|
thanks for your code, when compiling i've got the following error /config/esphome/bletracker2.yaml: In static member function 'static void std::_Function_handler<void(_ArgTypes ...), _Functor>::_M_invoke(const std::_Any_data&, _ArgTypes&& ...) [with _Functor = setup()::<lambda(const esphome::esp32_ble_tracker::ESPBTDevice&)>; _ArgTypes = {const esphome::esp32_ble_tracker::ESPBTDevice&}]': |
I'm happy to report that with the latest fixes for Series 5, this is doing a great job for detecting presence using our Apple Watches.
I noticed a couple of things. If you have two watches, and one is detected but out-of-range, its RSSI will pollute the reported status.
I was also curious to see if this could be tweaked to detect active/unlocked iPhones in range doing their own Continuity broadcasts, and sure enough, I have this working with an iPhone 11 Pro, an SE 2020, and an XR, if there's a mac OS machine somewhere nearby, presumably sending out its own broadcasts. Maybe we can simulate those?
FWIW, the combined changes from my yaml:
The text was updated successfully, but these errors were encountered: