HomeKit doesn't save device room assignment


I just started using the HomeKit component for HA and previously was running the Homebridge add-on in Hassio. One thing I’ve noticed is when I had Homebridge on Hassio, I could restart my RPi3 and when everything loaded up, all of my room assignments in my iOS Home app were saved. However, with the HomeKit component, everything appears to change back to the same room the Home Assistant homekit.bridge is located. This obviously isn’t ideal as I have to go back through each device and re-assign the rooms but worse is all of my automations in HomeKit lose their devices as well.

I noticed on the HomeKit component page it mentions HomeKit doesn’t support any kind of persistent storage. I’m not sure if this is what the page is referring to but any ideas how Homebridge was able to make this work?


I would assume room assignments are stored in the Home app, not in home assistant. In that case, I suspect the accessoiries presumably have been given a new unique id.


I see. So each time HA is restarted, it assigns a new unique_id to each device? If so, then this statement would explain it from the HomeKit component page which basically matches with what you said:

Currently this component uses the entity_id to generate a unique accessory id (aid) for HomeKit. The aid is used to identify a device and save all configurations made for it. This however means that if you decide to change an entity_id all configurations for this accessory made in the Home app will be lost.

That being said, is there a way for the unique_id to not change after HA restarts? It’s pretty frustrating having to re-assign rooms to each device and re-build all my automations in HomeKit after a HA restart.


No. Unique IDs only change when you change the entity id. So it is safe to do restarts if you have not changed entity id.

However you should be aware that all entities need to be available before HomeKit is started. I myself have built in a 1 minute delay to let hue and zwave start.


I also have the exact same issue about the HA devices brought by Homekit component in my Homekit setup; loses room assignment (and Homekit kit custom name BTW).
Although, this is not happening when I reboot HA (I also have the start delay of 1 minute).
This is only happening when my entire house has a power failure (so everything reboots (Apple TV, HA, router, etc…))

The way I understand it, if the device isn’t loaded in HA when HK component starts, it won’t show up in Homekit (and I get that that).
But in what scenario the device would get a different ID (and appear back in Homekit in default HA room with default name)?

Just trying to figure out the order of things to avoid this issue… Thanks in advance!


You just need to ensure that all of your devices are loaded (with the same entity_id as previously) before HomeKit.

This could be a problem on the RPi when using discovery, for example, because discovery could take some time to find all of your devices. A longer delay before starting HomeKit would help this.

This also means (I think) that if your device is in HomeKit, then is powered off, then you restart HA, then the device will be removed from HomeKit. Even if you then power it on and restart HA, it will revert back to its default room as HomeKit is seeing it again for the first time (this is also the case with Homebridge).


ok but if the delay is too short and device wasn’t loaded before HK component starts, the device won,t be there at all no? So what scenario would cause the device to get a different ID (sorry, I might just not understand correctly)


Only if you change the entity_id; but my point was that there may be other reasons that an accessory reverts to the default room other than that.


ah well, it must be something else causing this in this case…


I think there’s something else causing my issue because the device_id is not changing but HomeKit is losing room assignments when HA is restarted.

Edit: So disabling auto_start and adding an automation to start HomeKit 1 minute after HA is started seems to keep my device room assignments in the iOS Home app. However, my automations still lose all of their device assignments. Additionally, my ‘Favorite Accessories’ section on the iOS Home app setup seems to get reset (i.e. devices are not setup in the order I had them) along with ‘Include in Favorites’ and ‘Status and Notification’ settings. I didn’t have these issues with Homebridge so hopefully it’s something that can be adjusted for this HomeKit component.


Well, I didn’t change anything but I restarted HA several times today and all of my HomeKit room, zones, automations, etc. all saved. I also removed the HomeKit one minute delay start automation as I’m pretty certain that’s unnecessary for my setup (all of my devices are via Abode), and all of the HomeKit settings remained save.

Not sure what was causing the issue before…


I’ve also been experiencing the same problem. Seems to me that the problem resides in the homekit component for Home Assistant. In init.py, there is a function that generates the accessory ID for each accessory that relies on the adler32 function of the zlib package to compute a checksum on the entity ID.

According to the Python documentation, the adler32 function changed in version 3.0:

This seems to imply that depending upon your platform and Python version you might generate different accessory IDs if you do not perform a bitwise AND on the output of the adler32 function with 0xffffffff. I manually updated the homekit component to do this and afterwards I can restart Home Assistant and my HomeKit accessories do not move to the same room as the hub. Here is the resulting code:


Hi, this sounds like a great fix - because I also have the same issue.
Can you provide this fix to Home Asssistant Source, to include this fix in future releases?



I was strongly considering doing this but just yesterday I had to restart Home Assistant and sure enough all the entities exported through the HomeKit Controller component again ended up in the same HomeKit room as the Home Assistant “hub”. They had persisted in the correct rooms across numerous HA restarts as I have been doing a lot of work building up my HA instance so I’m not sure why this most recent restart caused a regression. I will keep testing and if I can determine a fix I will certainly submit a pull request.