Devices that use Bluetooth randomised mac address security and an IRK (Identity Resolving Key) - which is to say all smartphones - can be tracked by installing the Private BLE Device integration which is part of HA core. You will need to tell the integration the IRK for each of your devices.
This is how to find the IRK for your phone - it works for Android and Apple devices.
Summary:
Install Arduino IDE (Integrated Development Environment) on a desktop or laptop - Windows, Linux or Mac; it will not run on a Chromebook.
Connect the ESP32 device of your choice (in this guide an M5STACK ATOM LITE).
Download esp32_get_irk from GitHub and flash it to your device.
With the ESP32 device still connected to Arduino IDE, pair your phone with it.
The IRK will be displayed in the IDE.
What do you need?
Set up Arduino IDE
- On your PC/laptop, download and install the Arduino IDE. The screenshot below is Arduino IDE 2.
- Add support for the M5STACK Atom
- Open the Arduino IDE and click File in the top left corner, then Preferences
- Paste the following URL into Additional boards managers URLs and click OK
https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json
- In the left hand toolbar, click the Boards icon (second one down)
- Search for M5STACK and click install
The IDE is now ready for your device.
This topic is part of the community-driven cookbook where you can find other topics you might be interested in or might like to contribute to.
Flashing the M5STACK
- Download the code from Github (click the green “Code” button, then download Zip)
- Extract the contents of the zip
- In Arduino IDE - open the extracted esp32_get_irk folder and then open the file esp32_get_irk.ino
- Connect the M5STACK atom to the computer
- In the top bar of the IDE, click on the dropdown and select the port the device is connected to.
- Select the board type (M5STACK Atom)
- Click the arrow button in the top left corner, the IDE will start compiling and uploading the package to your device
Getting the IRK
- In Arduino IDE
- In the top right corner, click on the magnifying glass (on windows Tools | Serial Monitor), this will open the serial monitor in a panel at the bottom of the screen.
- In the top right-hand corner of the serial monitor panel, change the baud rate to 115200
- On your phone
- Go to Bluetooth settings
- Select pair new device
- In the available devices list, search for ESP_BLE_SECURITY and pair
- In Arduino IDE you will get the IRK key in several foramats:
- IRK: ,0x1A,0x1B,0x1C,0x5E,0x87,0xD2,0x1D,0x57,0x27,0x14,0x4B,0x19,0xAD,0x58,0xCF,0x41
- IRK, Base64 encoded for the Home Assistant Private BLE Device service: GhscXofSHVcnFEsZrVjPQQ==
- IRK, reverse order for Home Assistant ESPrensence: 41CF58AD194B1427571DD2875E1C1B1A
You can now unpair your phone.
This is a simplified version of a post by @legoracers with a couple of screenshots added.