Area/Room Presence Detection for Mobile Devices using ESP32-based BLE Beacons

I would also be happy to test for you, this could be really useful for me.

im still interested!

Given that the approach requires an app, I wonder why didn’t you go with the other direction: app BLE broadcasting and esp32 listening ? MAC address for broadcast is not an issue since you can broadcast stable a string that is then interpreted by ESP32.
I use this approach and it works just fine.

2 Likes

That’s an interesting point. Certainly, at the time I started reading up on it, I found it simply wasn’t possible to advertise as an iBeacon on iOS in the background. As I moved along, the idea with a unique, constant string per device (I assume this is what you mean by stable?) also popped into my mind. At the time I was thinking around whether to completely rework the approach or stay with a device-centric solution.
For me, the main drawback of the unique-string approach was, that it would effectively make the device trackable for others, as anyone can simply follow the BLE messages with the unique string. Of course, it would be possible to mitigate this by anonymization of the unique string. Similar to a car remote rolling key, where a new sequence is used after each time the button is pressed. So complexity would increase, as for each new device I would require a unique key generator, which would have to be synced with the ESP32, increasing complexity of the system.
Plus I like how the device-centric approach is fully privacy-preserving. The user has control over his location at all times and decides how to share it.
Here are some other arguments I thought about:

  • Simplified processing, no additional server required: All processing happens on the device, no need to fuse data from multiple sensors at a server.
  • Lower latency: After processing the beacons measurements and making the prediction, the only step left is to publish an MQTT message to the broker.
  • Apple review acceptance: Given that Apple always states how they are very protective about customer privacy, I was unsure whether they would allow an app that potentially makes the device trackable.

In addition, I was also not sure, which solution is truly better energy-wise and how efficiently iOS can perform the ranging. If you have any materials on the matter, I’d love to check them out.
I’d also like to emphasize, that the above list is not complete in any sense. A better one can be found at [1]. The above is simply a collection of the arguments that mattered the most to me.

[1] -Crownstone | Indoor Localization

Thanks for sharing thought process !
I use Android and it is not clear to me how things are on iOS. W.r.t. energy I guess it will be similar.
I’ve experimented with ble scanning on phone first and it was definatelly noticable from the battery perspective. I don’t have any concrete material on this. Technology-wise I don’t think constant BLE scan is actually energy consuming since I would guess that phones are in constant BLE listen mode (e.g. consider how BLE headphones get paired automatically), but I would guess actually actioning on the scan (i.e. responding to BLE advertisement from ESP32) might be actually an issue since it will not let the phone to sleep properly. Again, no hard evidence just guesses.
Also, at least on Android, doing BLE scan was causing intermittent connection issues with other BT devices connected to phone.

The privacy argument is definatelly true, hence it is more of a personal choice. This is not that a big deal for more. W.r.t. detecting whether someone is at home I already have bunch for Mi Flora devices and Mi Scale that perform broadcast over BLE. If a thief was really into technology they would be able to detect my presence using other means. In particular, physical surveillance would be likely much easier :slight_smile:

I don’t think latency is really an issue here. Phone->ESP32->HA should be order of tens of milliseconds if everything working in push fashion. With end user device doing broadcast you also have control over the frequency of broadcasts, hence potentially even further decreasing latency.
The additional benefit is that you can do ML on the server and improve the algorithm over time without need to push something to the end user device.

The final argument that was the most important to me is that this approach works not only with devices that have the app, but with any BLE devices that performs broadcast. I personally have Android phone with free Beacon Toy app where I can configure BLE broadcast (stable string, while MAC is changing). My wife uses iNode BLE beacon. There is plenty of BLE trackers on the marker that would likely work. I’ve recently bought Oura Ring which seems to do constant BLE broadcast which would be ultimate wearable for BLE broadcast if it turns out to work.

1 Like

Thanks so much for the feedback. I agree with you, regarding privacy it’s much more a personal preference :wink:. Other decisions are based on what’s possible under iOS and acceptable for the Apple app review process. Again, I feel that the approach I am presenting is much more of an addon and not a replacement. The biggest benefit, is without doubt, for iOS users, as solutions as esp32-mqtt-rooms are simply not available there.
The latency argument is probably also true for most cases, though with an increasing number of ESP32s it will get noticeable (e.g. due to the shared BT/Wifi hardware on the ESP32, CSMA/CA medium access). But yes, probably not an issue.

Yes, also a good point. I like to train my models using sklearn and/or Keras. The current implementation allows importing a new model with a single button from a URL :smile:.

Definitely a good point, and one of the biggest drawbacks of the device-centric approach.
From what I understand, all approaches do some sort of AI-based classification using RSSI values. I do not expect significant improvements/drawbacks among them. RSSI is not a real high-value wireless channel feature, just the best we can get with cheap hardware and reasonable effort at the moment.
A real game-changer would be to use significantly more expensive SDR hardware and extract more advanced wireless channel features for the learning, i.e. multipath-parameters, or time-difference of arrival.
I hope this is not taking it to far off-topic, but I really appreciate the input and wanted to explain my thought-process as thoroughly as possible.

How cool would it be if the BT Beacon stuff could be in the existing HA App, so it doesn’t require an additional app to be installed!

Have you looked at the method used here https://github.com/andrewjfreyer/monitor instead of requiring the beacon?

Ill take a look at this once im finished my current project :slight_smile:

I’d just like to say that I love this project - @st0nedB I fully agree with you that the cost/complexity of deploying raspberry pi zeros for Room Assistant is a significant hurdle that has also kept me away.

Like you, I already have a few ESP devices (a mix of 8266s and 32s) tracking other data around the house and it would be pretty simple to upgrade everything to 32s and deploy this solution.

Amazing, and thank you!

I’ve also read with interest the discussion regarding active/passive BLE and on-device vs off-device processing. Just to express my opinion, I also would prefer an off-device solution that doesn’t require an app to run, but that is just a bit of feedback. I am more than pleased with this solution and look forward to deploying it!

does yours work with apple watch?

i love the idea of using the bluetooth ring! I dont want to rely on carrying my phone around in order for automations to work, but a ring or smart watch is a great idea

This sounds very cool! Nice work!

Few questions:

  • Does the app work in the background on your phone?
  • Did you link to the project on GitHub already? Did I miss that? Or were you checking to see if the community was interested before sharing?

More questions id ask about ESP32s, but won’t ask them yet until I learn a bit more/figure out if this could work for me.

i would also like to test it

Amazing work @st0nedB thanks for sharing :slight_smile:

quick question, is the battery drain on the iphone bad? would you implement the app on android ?

thanks

This is something I’d be very interested in and happy to test! (just need to order a few ESP32’s)

If you don´t want to have an app for each OS (Android & iOS), go with the other direction, as @rsokolowski mentioned. Additionally, try listening for BLE signal of another device such a Fitness tracker e.g Xiaomi mi band (any version), that’s the way I do it and it works pretty well.

I have about 6 nanos and have been wanting to do just this in a 4bdr house. I see use cases for visually and hearing impaired users that may not have crossed your path. Would be glad to help with cross platform support too. Have you checked out Unity?

Hey everyone, thank you all so much for the replies, suggestions, and questions.
During weekdays I can’t find much time to post here, but I’ll do my best to provide appropriate answers.
First, to all who have expressed their willingness to help me test it on a broader audience, thank you :hugs:! I’m doing my best to set everything up as quickly as possible, please be patient. Workdays in Homeoffice are sometimes unexpectedly exhausting :wink:

Surely, passive scanning might work for most BLE devices (but I’m still not sure about iOS) and I looked at monitor (great project btw!). However, from what I understand, it works for presence detection, not room, and uses the RPi platform. Please correct me if I’m wrong.
In the end, passive is also a matter of perspective. In all wireless communication systems, some device is transmitting, another one is receiving. Both actions require power, nothing comes for free.
As minimalistic as I try to be, having an extra app is not a big hassle for me. It is designed to be in the background most of the time, makes collecting the training data easy, and consumes only some MB of disk space.

Yes, it does work in the background. I’m currently trying to improve the power consumption and pause the beacon measurements as often as possible.
Sorry, no GitHub link available, yet. But it’s planned. It should also help to assure all users, that the app is not doing something fishy in the background. As you assumed correctly, I first wanted to find out if the approach is even interesting for the community.

Please see above, I provided some debugging screenshots from Xcode to showcase the current progress. I hope it can be improved further. In some debugging sessions, the power consumption would drop too “low”, sometimes it won’t. According to my intuition, the new features are still a little buggy.

Maybe, but first I want to finish the iOS version. Any help in the development will be greatly appreciated, as I don’t own Android devices. That’s gonna make debugging hard :upside_down_face:.

Superb! I’d love to hear your use-cases and if it can help visually and hearing impaired users, all the better :sunglasses:!
Let’s get in touch and discuss it via PM, to not take it too far off-topic here.

Stay healthy everyone!

1 Like

No worries mate I can help in debugging :slight_smile:

hahah. I have a bluetooth thingy on my keys and a couple esp32 around the house to track me. As well as a useless automation that lets my phone know when I leave the house with out my keys. Which of course is too late as I am already locked out . . .

sounds very promising as it uses esphome which I already have around my appartment. Will have to wait for a android version tho. Will be following this thread.