Espresense device id - how to get them?

hi there

thanks for all the comments. actually I switched to https://www.room-assistant.io/ which (in my opinion) works better and even has an app for iOS, check it out :wink:

I installed it on a Raspberry Zero 2W

I started off in that direction until I saw the Raspberry Zero 2W going for $94 on Amazon. So I opted for Espresense with D1 mini esp32s which were 3 for under $20. Maybe when prices get back to normal.

yeah, Raspi became very rare and expensive. I recommend to regularly check this website: rpilocator - Find Raspberry Pi Computers in Stock It tracks which models are available at the official resellers, I had the luck to get some 2W for around 20$ each.

Hi all

It is possible to get the unique identity for Apple iPhone and Watches. The documentation does exist on the ESPresense website, it’s not overly obviously and it’s a bit of a pickle initially but seems to work perfectly well for my setup now that I followed the instructions:

Basically, you need to identify the IRK (Identity Resolving Key) for your Apple device. Note, that if you use the auto option for the phone, the ESPresense will start broadcasting to MQTT using the name of the device you gave when you “Enrol” it. Whilst this is easy, it really isn’t ideal, as if you run multiple ESP’s, you need to enrol the same device on every ESP with the same name for it to work. Best to get the IRK, either using the Enrol option, or the Keychain Access option (works for phones as well as watches) and then add the IRK’s to the ESP configuration on each ESP. The MQTT output will then use the IRK which will match on all ESP’s and the HASS config.yaml can be set to the IRK meaning it will be picked up from the same IRK from all ESP’s. Hope that makes sense.

3 Likes

I’ve been staring at this for so long I’m screen blind so, whilst I’m sure you did a banner job of explaining, can you show a sample of your config that made this work, please?

I’m a very visual learner at this point lol

1 Like

Hi, I’ll try!!!

So for an iPhone (different practice for the watch)…

Open the web ui for your Espresense device, change the default page to http://your_espresense_ipaddress/ui. This will show a basic page as follows:

Enter the device name (I don’t think it really matters as we’re going to drop this later - in my example here I have used “MyNewDevice1”) and press enroll.

Now take your iPhone, goto Bluetooth settings and join the Espresense device (obviously you need to be in range!). Make sure that it pairs successfully, if it doesn’t, turn the bluetooth off and back on again on your device until you get a successful pair. Note that your phone will not stay connected to the Espresense for long, even after a successful pair, do not be concerned with that.

When this is done, switch to the Fingerprints link in the left menu and you should see your device show using the name you entered in the Enroll stage.

Next, to get the IRK value (not shown in the fingerprint screen), you will need to take a look at the MQTT data your Espresense is publishing. To do this, I use an app called MQTTExplorer to view all the MQTT data being published to the MQTT broker (super handy tool if you haven’t already discovered it). Under the node espresense > settings you will find an irk:your_irk_value_here entry. To confirm its the right device, if you expand it, you will find a config entry with the device name you used during the first Enroll step.

Now that you have the irk, you need to add it to your HA configuration.yaml as a sensor:

The device_id is where you put the IRK value, you need to enter it as follows (note that I have mine extracted to the secrets file which is a good practice):

device_id: "irk:abc123etc"

You should also then visit the default config page on your Espresense device to populate the configuration with the known IRK number. Note the format here is without any irk: prefix, just the value and for multiple irk values, space separate them. Ideally, register all your devices in one session on a single Espresense device and add all the IRK values to one, and then copy and paste the entire string into all your other Espresense device configs.

So the next part I found a bit fickle. But because the device is “Enrolled” with whatever name you used, this is what is published to MQTT (initially at least), not the IRK number… :frowning:

To resolve this, I delete the espresense/settings topic on my MQTT broker and restart the espresense device that I did all the enrolment on. There’s a bit of a timing knack to this as they seem to re-populate from each other. I would have thought that this means you should be able to not have to use the IRK values in HA at all, and just use the enrolment names, but I found that this doesn’t work across multiple Espresense devices, whereas using the IRK values does. YMMV

Hopefully you have the MQTT broker installed in HA already, which should pick up these entries after a restart possibly.

You should also have a sensor entity in HA for the device you enrolled.

And then if you look at the state history it will show where it was detected.

You can then use the sensor state for automations / cards etc as you wish.

For Apple Watch’s, the process for retrieving the IRK value requires that you use a computer to access your iCloud Keychain data, but once you have the IRK value, the rest of the process is identical.

I hope that helps.

17 Likes

This is a brilliant explanation and with it I nailed it. Thanks very much - this really should be pinned somewhere.

1 Like

No worries, glad it worked and that I could put something back into the community. I’ve picked up so much from here myself.

To be honest, it should probably be pinned on the espresense web site, the documentation requires a little bit of improvement IMO, but we can’t have everything for free, so it’s good to help each other where we can! My bit of kindness for the weekend. :slight_smile:

4 Likes

Big thanks from my side! Your post is gold.

1 Like

I am trying your steps, but I do not see my device name under Fingerprints after a successful pair. I do see the irk under settings in mqtt explorer, but the irk id does not show under devices in mqtt explorer.

So just to be clear, you did type a device name (doesn’t matter what) in the text box next to the Enroll button before pressing the button? This is the name you should be looking for in the Fingerprints list, not your actual device name.

yes, I enter an name before pressing the enroll button. Do I need to remove my old id I am using to detect my iphone which is apple:1007:11-2 in the espresense gui setting page under the Filtering tab??

Possibly. I don’t have anything filtered on mine.

ok. Thanks got it working now. The filter line must be blank for the irk id to be detected it seems.

If you use MQTT Explorer, just select the topic on the left side then click the delete button.

Had to amend my post as I was having a few problems with set up but all working now - this is amazing. Thanks so much for the walk through guide - so helpful - thank you!!!

Do you know how to make Android phones update faster? It takes my device 10 mins to change rooms

Sorry, I have zero experience with android phones.

if your issue is with the time it takes to pick up the device when you enter a room, it’s certainly not instant so not really usable for PIR type detection. But in my experience it can be delayed but sometimes it picks me up before I even enter the room.

If you have multiple espresense devices then as you move around this can also take a short while. I believe the espresense uses the distances to work out which receiver you are closer to and the distance on each espresense is an average over the last number of pings, so if you move quickly it actually takes longer to follow you if that makes sense. You can see this for yourself if you open the fingerprints page on each espresense and watch the distance values. I wouldn’t read too much into the distance values. I probably wasted about 3 hours trying to tune them to create a virtual boundary between two rooms using a tape measure and the readouts!!! I failed miserably and actually after resetting all the defaults it seems to work pretty well out of the box!

One other thing to note, I think the amount of Bluetooth pings from your phone may also be linked to battery state. I find that sometimes when my iPhone is in low power mode that my presence in a room can be lost causing my automations to shut the lights off and then shortly after they come back on! I can probably tune this out by increasing the delay on the lights off automation to accommodate the longer period between Bluetooth pings.

Thank you for your response! It looks like it was an Android issue. I was able to setup an iPhone, Tile, and a Blue Charm beacon which all work pretty well. I would say the Blue Charm beacons are the best and will probably just get more of those. One individual in my home doesn’t want to carry a beacon around so I want to get their Apple Watch connected. Unfortunately I’m having trouble with step 9. After I copy the highlighted section I am unable to do anything with it. Step 9 says I need to paste the piece I just copied in step 8 into the box and click “decode” but the option says “convert”. How do I proceed?


This step 9 on the ESPresnse page