I've been using ESPresense for a good few months to trigger automations in my Home Assistant setup. Unfortunately, I've started noticing issues where some automations that are based on presence detection have become unreliable.

I track my presence in the house either via my iPhone or iPad. These are both Apple devices, and Apple's focus on security and privacy means that they've designed their hardware and OS to make it difficult for you to track. Usually, this is a good thing, but this is currently harming the reliability of my home automations.

Fortunately, with V3 of ESPresense there is a more reliable way to track Apple devices.

Recap: ESPresense

ESPresense runs on ESP32 devices, and by placing a number of ESP32s throughout your home you can determine with room someone is in by tracking the bluetooth signature of a device that they carry (such as a phone). ESPresense determines which room you are in based on with ESP32 you are closest to based on the bluetooth signal of the tracking device (beacon) that you're using.

For a comprehensive introduction to ESPresense you may want to check out my original post on ESPresense:

In the original blog posts I installed the Room Assistant app so that my iOS devices provided a unique and persistent identifier that ESPresense could track. This was the theory atleast, in practice this hasn't proven to be too reliable.

Enroll Flow and IRK - V3 Required

The Enroll Flow and IRK support are new features in V3 of ESPresense. So the first thing to do is to check the version of ESPresense that you are running and to update to the latest version if you aren't already running V3.

You can check which version of ESPresense you are running by navigating to the configuration page of your ESPresense device. The version is listed below the language.

ESPresense configuration page showing version

Enroll a device

Each Apple device that you want to track will need to be enrolled. You only need to do this once per device you want to track.

Navigating to the IP address of your ESP should take you to the ESPresense configuration screen shown above.

Navigating to /ui/ (e.g. http://192.168.2.38/ui/) will take you to the new enrollment UI that is available in V3.

Enter a name for the device you want to enroll and press "Enroll":

Specifiying a device name to enroll in ESPresense UI

After oressing "Enroll" you should now see a message informing you that you can now pair your device:

Instruction to pair device from ESPresense UI screen

As directed by the insturctions, go into the bluetooth settings on your chosen device and pair with the "ESPresense" device that appears. This is what the process looked like when I did this with my iPhone:

Pair iOS device with ESPresense over bluetooth

Once the device is "Paired" it will appear as "Not Connected" within your iOS bluetooth settings. Don't worry about this; this is normal.

When pairing has completed you should be able to see the device identified by the friendly name in the Fingerprints section of the ESPresense UI:

The next step is for us to determine the IRK (Identity Resolving Key) for our device. We can do this by looking at the information published in MQTT for our given device:

Under espresense/settings you should see the irk value listed for each device that you have added. We will need the irk value for Home Assistant and ESPresense.

In the "Scanning" part of my ESPresense configuration I have ensured that "Known BLE identity resolving keys, should be 32 hex chars space seperated" is set to the irk values for my devices. I have done this on all of my ESP32s. Note that in this setting the irk values should be without the "irk:" prefix:

Set IRK values in the Scanning settings of the ESPresense configuration page

Finally, we now need to update Home Assistant configuration to use the device name that is being tracked via the IRK value rather than the Room Assistant identifier that I was using before. Previosuly, my sensor.yaml looked as follows:

- platform: mqtt_room
  name: "James iPad BLE"
  device_id: "roomAssistant:xxxx-xxxx-xxxx"
  state_topic: "espresense/rooms"
  timeout: 5
  away_timeout: 120
- platform: mqtt_room
  name: "James iPhone BLE"
  device_id: "roomAssistant:xxxx-xxxx-xxxx"
  state_topic: "espresense/rooms"
  timeout: 5
  away_timeout: 120

The device_id now needs to be updated to match the ID/name that I inputted into the ESPresense enrollment page, and that is now showing up in MQTT, therefore my sensor.yaml changes to:

- platform: mqtt_room
  name: "James iPad BLE"
  device_id: "jamesipadpro"
  state_topic: "espresense/rooms"
  timeout: 5
  away_timeout: 180
- platform: mqtt_room
  name: "James iPhone BLE"
  device_id: "jamesiphone13pro"
  state_topic: "espresense/rooms"
  timeout: 5
  away_timeout: 180

Conclusion

If you're using ESPresense with Apple devices, changing to the IRK-based approach with the new enrollment flow is a definite must. Since implementing the change, I've seen reliable and consistent tracking of my iOS devices between rooms.

This process of migrating to use the enroll flow has a few steps, but you can easily complete the migration in under 10 minutes.