Capture iOS and Android BLE Identity Resolving Keys (IRK) using an ESP32 running ESPHome. Use the captured IRKs with Private BLE Device integration in Home Assistant for reliable presence detection.
The ESP32 advertises as a Bluetooth heart rate monitor, which iOS and Android will pair with. During the pairing process, the device's IRK is exchanged and captured. This IRK can then be used to track the device even when it uses randomized MAC addresses.
- ESP32 board (any variant with Bluetooth)
- ESPHome 2024.x or newer
- Home Assistant (optional, for integration)
-
Copy
irk-capture.yamlto your ESPHome config directory -
Create a
secrets.yamlfile in your ESPHome config directory:wifi_ssid: "Your WiFi" wifi_password: "your_password" ap_pass: "fallback_ap_password" encrypt_key: "your-32-byte-base64-key==" ota_pass: "ota_password"
-
Flash to your ESP32:
esphome run irk-capture.yaml
- Open your phone's Bluetooth settings
- Look for the device (default name: "JBL Tune")
- Tap to pair - accept the pairing request
- The IRK will be captured and shown in Home Assistant
| Entity | Type | Description |
|---|---|---|
| Last Captured IRK | Text Sensor | The captured IRK (format: irk:xxxx...) |
| Last Device Address | Text Sensor | MAC address of the paired device |
| BLE Advertising | Switch | Enable/disable Bluetooth advertising |
| Generate New MAC | Button | Generate a new random MAC address |
| BLE Device Name | Text | Change the advertised Bluetooth name |
To change the BLE device name, add this to your irk-capture.yaml:
irk_capture:
ble_name: "Beats Solo4" # Name shown in Bluetooth settingsTo change the ESP32 board type:
esp32:
board: esp32-s3-devkitc-1 # For ESP32-S3- Copy the IRK from the "Last Captured IRK" sensor (e.g.,
irk:xxxxxxxxxxxxxxxxxxxxxxxxx) - Go to Home Assistant β Settings β Devices & Services
- Add the "Private BLE Device" integration
- Paste the IRK
Get notified when an IRK is captured:
automation:
- alias: "IRK Captured Notification"
trigger:
- platform: state
entity_id: sensor.last_captured_irk
condition:
- condition: template
value_template: "{{ trigger.to_state.state not in ['', 'unknown', 'unavailable'] }}"
action:
- service: persistent_notification.create
data:
title: "π IRK Captured!"
message: |
IRK: {{ states('sensor.last_captured_irk') }}
Address: {{ states('sensor.last_device_address') }}Build Fails:
- Clean the build folder and retry
Device not visible in Bluetooth settings:
- Press "Generate New MAC" button
- Make sure advertising switch is ON
"IRK does not match" in Home Assistant:
- Keep your phone's Bluetooth active while adding
- The phone must be advertising BLE
Based on ESPresense enrollment functionality.