Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IRK for Android Device #247

Closed
kilian-f-za opened this issue Jul 17, 2024 · 17 comments
Closed

IRK for Android Device #247

kilian-f-za opened this issue Jul 17, 2024 · 17 comments

Comments

@kilian-f-za
Copy link

How can I read the IRK from an Android device and add it as a private BLE device in Home Assistant? The Home Assistant page only says how to add macOS devices. Here in the wiki it is also possible with Android. Can someone help me there?

I use Android 14.

Many thanks

@droans
Copy link

droans commented Jul 17, 2024

Take a spare ESP chip and install ESPresense on it. Connect it to your network. While still connected to your PC, either view the logs on ESPHome (you can use any random existing device to view the logs, just select "Plug into this computer"), using the ESPresense web terminal, or any other way you'd like.

Go to http://ESP_DEV_IP/ui/#/devices and click Enable. Pair your phone to the ESPresense chip. In the logs, you'll see it list an IRK. It'll be formatted something like irk:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. Copy that whole string, including irk:, and add it as a Private BLE Device in Home Assistant.

Or, alternatively, you can enable the BLE Transmitter in the HA companion app.

@kilian-f-za
Copy link
Author

Thanks for the explanation. I did everything that way, but when I inserted the IRK into Home Assistant, this message comes. What can I do now?

Screenshot_20240717-215235.png

@jleinenbach
Copy link

jleinenbach commented Jul 21, 2024

... Copy that whole string, including irk:, and add it as a Private BLE Device in Home Assistant.
No, put it there without the irk: and without spaces, if any.

And your device needs to be visible to one of your BLE proxies, of course.

@jleinenbach
Copy link

Additionally, I wrote a guide for Windows:

home-assistant/home-assistant.io#33676

@kilian-f-za
Copy link
Author

... Copy that whole string, including irk:, and add it as a Private BLE Device in Home Assistant.
No, put it there without the irk: and without spaces, if any.

And your device needs to be visible to one of your BLE proxies, of course.

Can I check whether my device is visible?

@jleinenbach
Copy link

jleinenbach commented Jul 21, 2024 via email

@kilian-f-za
Copy link
Author

I tried to do it that way but unfortunately this message always comes when I insert the IRK.

@jleinenbach
Copy link

Having an IRK does not guarantee that your device supports BLE. I guess your device is quite up-to-date?
I don't know for sure, but I think you also need to keep the pairing on your device, so do not delete the pairing after you extracted the IRK of that connection.

@kilian-f-za
Copy link
Author

Yes, I have a Google Pixel 6.
However, esprecense does not have to run permanently? I only used it to read the IRK. I try to keep the coupling to the ESP via Bluetooth.

@jleinenbach
Copy link

If you have connected your smartphone to the scanner, make sure not to delete the connection on your smartphone. This is because the IRK is associated with this connection and is crucial for maintaining the pairing. The IRK is used in Bluetooth connections to generate and resolve random private addresses, ensuring that the devices recognize each other in future connections. Deleting the connection would require re-pairing and exchanging new IRKs.

@kilian-f-za
Copy link
Author

I tried it but unfortunately it doesn't work and home assistant doesn't know the IRK.
I will then have to do it via the Companion app.

@jleinenbach
Copy link

Did the IRK look like the example provided when you entered it? In my case, it did.

An Identity Resolving Key (IRK) in Bluetooth Low Energy (BLE) has a specific format that consists of 128 bits (16 bytes). It is a binary string that exclusively contains hexadecimal values. The exact structure is as follows:

  1. Length and Format: An IRK is exactly 16 bytes (128 bits) long and is represented in hexadecimal form. Each position in the key represents four bits.

  2. Permissible Characters: Since an IRK consists of hexadecimal values, the permissible characters are 0-9 and A-F. Special characters, letters outside A-F, or any other non-hexadecimal characters are not allowed.

  3. Example:

    4A5B6C7D8E9F0A1B2C3D4E5F67890ABC
    

In practice, the IRK is exchanged during the pairing and bonding process between two BLE devices and is stored in a secure database. It is used to verify the identity of devices and to generate and check Random Resolvable Private Addresses to protect user privacy.

For more technical details and precise specifications, you can refer to the Bluetooth Core Specification and documentation from sources like Texas Instruments.

@kilian-f-za
Copy link
Author

Thanks, I'll do it with the Home Assistant Companion App.

@agittins
Copy link
Owner

If you have connected your smartphone to the scanner, make sure not to delete the connection on your smartphone. This is because the IRK is associated with this connection and is crucial for maintaining the pairing. The IRK is used in Bluetooth connections to generate and resolve random private addresses, ensuring that the devices recognize each other in future connections. Deleting the connection would require re-pairing and exchanging new IRKs.

I don't think this is correct. The IRK is used purely for identifying if a a given mac address belongs to the same device that gave the IRK. For Private Bluetooth Device this happens without a connection at all. I'm open to evidence to the contrary, though.

This means once you have the IRK for a device, you can delete that connection and if you used say an espresence device to get it, you can then re-flash the device with something else, all that matters is having the IRK.

@agittins
Copy link
Owner

Thanks, I'll do it with the Home Assistant Companion App.

Using the companion app (and asking Bermuda to track the iBeacon id) certainly works, so you should hopefully have no trouble setting that up.

The latest version of Bermuda will show you some info in the config dialog so you can tell if HA is receiving bluetooth data OK - it's possible that your original problem might have been that the IRK was OK but HA wasn't seeing any data.

If you have any trouble feel free to reopen this issue or create a new one.

@Raul-7-7
Copy link

Hi @agittins I am running into the same issue, Can you please confirm for Android:

  • Enable BLE on companion app
  • Enter the UUID from Companion app into the iBeacon tracker that is now shown in Home Assistant (New device discovered)
    that is all I need to do? there is no need to find the IRK for Android devices?

Also, if its ok, once I have everything up and running, I would like to contribute to better documentation for this plugin.
Thank you for your time.

@agittins
Copy link
Owner

Hi @Raul-7-7, you don't need the iBeacon integration at all.

If you don't want to use irk, all you need to do is:

  • enable "BLE Transmitter" in the companion app
  • in Bermuda, "CONFIGURE", "SELECT DEVICES" you should find the uuid listed near the top of the drop-down. Select it and click submit.

You'll now have Bermuda sensors for that iBeacon.

The benefit of irk is that then you don't actually need the app to be broadcasting at all, (so no iBeacon uuid) as Bermuda will recognise any broadcast from the device.

For iphones this is a bigger benefit because they will often stop an app from advertising for power saving, which is less a problem for Android.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants