Presence detection with low cost BLE devices and Raspberry Pi/Zero W

Yes, I get the most important and more :slight_smile:

That is the mac address and the RSSI that are needed for detection as well as (not always) the ManufacturerData, ServiceUUID and Name (not published to mqtt).

Itā€™s only a very quick and dirty piece of code that still need a lot of improvement but you can already see it here:

Iā€™ll for example certainly replace the MQTT library with another one as this one is giving me trouble, it lost connection after a while (I had the same phenomena on ESP8266 with the default PubSubClient).

Happy-Bubbles can treat the received mqtt message without problem:

Iā€™ve just implemented the first type of message, no Eddystone beacons or iBeacons, I honestly donā€™t know the difference and donā€™t know how to separate one from another, Iā€™ll also have to check into that.
https://www.happybubbles.tech/presence/docs/mqtt/

8 Likes

@touliloup very great jobā€¦ Iā€™m really interested to your work. I hope you could produce new releases of your ESP32 BLE solution for better integration with HA. Thank you for your contributionā€¦

@touliloup There has been a comment from the happy bubbles developer a while ago: https://groups.google.com/d/msg/happybubbles/0V9tfZICKIk/OmdUHjexAgAJ but perhahps youā€™ll overcome this.

1 Like

Ah yes, you are right, thanks for the hint.
Some module now offer connector for external antennas, Iā€™ll try to get my hand on such a module, and see if it works better.

1 Like

I have installed room-assistant on a rpi3 and rpi zero w. It was installed successfully on both but thereā€™s no detection on the console after it initializes BLE/iBeacon. No logs nor error. WHen I try to scan using hcitool, it shows ble/bluetooth devices. Iā€™m trying to track my mi band2. I used below config btw:

{
  "app": {
    "unsafe": false
  },
  "mqtt": {
    "enabled": false,
    "url": "mqtt://192.168.1.157:1883",
    "username": "",
    "password": "",
    "reject_unauthorized": true,
    "topic": "room/entertainment"
  },
  "console": {
    "enabled": true
  },
  "ble": {
    "enabled": true,
    "channel": "room_presence",
    "max_distance": 5,
    "whitelist": [""],
    "use_mac": false,
    "system_noise": 0.01,
    "measurement_noise": 3,
    "update_frequency": 5
  },
  "ibeacon": {
    "enabled": true,
    "channel": "room_presence",
    "max_distance": 0,
    "whitelist": [""],
    "system_noise": 0.01,
    "measurement_noise": 3,
    "major_mask": "0xFFFF",
    "minor_mask": "0xFFFF"
  }
}

If the band is a ble device you probably want ā€˜use_macā€™ to be true, but as with watches it doesnā€™t seem to be easy to track wearables. Try using scan on in bluetoothctl but you may have to work out MAC addresses for your devices.

I tried the mac option too, and removed the whitelist content so it could show all ble devices but the console doesnt show any discovery at all. The scan on on bluetoothctl and hcitool acan shows ble devices around me.

Have you granted permission for node to talk to bluetooth?
sudo setcap cap_net_raw+eip $(eval readlink -f which node)

yes, even running it as root.

Yay! Just got mine working on my Pi Zero W with Mosquitto running on it. A few observations followed by a question:

Observations:

  • I couldnā€™t get mine to work with the newest version of Node, as @getsmokes mentioned in his post from Nov 1, and using the built in version worked A-Ok.

  • Once I had all the room assistant config done, I cloned my Pi Zero W SD card so I could easily spin up new SD cards for new Pi Zeros as I spread them across the house.

  • I managed to blow up my Pi at first by not updating the update_frequency to 5 seconds. Will probably up it a bit more for good measure.

As for my question:

  • I had thought that this would let me track my Galaxy S8, my daughterā€™s iPhone 7 and my wifeā€™s Pixel, but Iā€™m not seeing their MACs / UUIDs in the logs. Is this not possible? Or am I missing something?

Thanks much for the post and all the helpful comments. Wouldnā€™t have achieved success without them!

2 Likes

To track phones and other devices you need to add a BLE beacon app, and thereā€™s no guarantee that it will work as default permissions donā€™t always allow it- I never had any joy with unrooted LineageOS on my phone.

Thanks, @sfgreenwood .

Follow-up question:
Based on your response, Iā€™m now looking to add Pi Zero W Beacon to my Owntrack regionsā€¦I have it (Owntracks) running on each of the phones I want to track, and my research indicates that I can tie the Pi Beacon to a specific Region/Lat/Long. Doing so requires the UUID of the Beacon.

For the life of me, I cannot figure out how to find that. Iā€™ve done scanning with various apps on my phone and my wifeā€™s phone and no joy. Any thoughts?

Have you set the beacon UUID on the Zero? There are a few tutorials on how to do it. This was the one I used: https://www.beaconzone.co.uk/choosinguuidmajorminor

Is Room Assistant still needed if you just want your Pi (witch is also running HA) to detect an ibeacon with builtin bluetooth in Home Assistant? Doesnā€™t have HA a built in bluetooth tracker now?

The HA Bluetooth LE tracker comes with a warning:

We have received numerous reports that this integration will have a big impact on the performance of the server.

and I think thatā€™s why Room Assistant exists. It also provides a multiroom solution that doesnā€™t need HA running in every room.

But do i need Bluetooth LE tracker as i only want to track an BLE device witch i can view with bluetoothctl. As the warning does not exist on the Bluetooth tracker page. I do not need a room detection, only a prƩsence detect of a BLE device Home / not home

If you can see the device with bluetoothctl then it should probably work.

My HASS Pi is in the same room as the table i always put my keys on. Is this enough to track if im home? Of course adding a bluetooth tracker to my keys.

It should be. With a single device just detecting the name should be fine. With more than one you would need to get their UIDs.

1 Like

Well i need one for me and my girlfriend. Is it hard to find the UIDā€™s?