ZHA won't start

After adding 9 new Hue lights to my crowded Nortek HUSBZB-1 controlled ZHA zigbee network, my ZHA integration fails to start after a server restart and gives the following message.

This has happened twice now. The first time I restored a snapshot and re-added the lights. It was ok for a couple of days, then I restarted the host NUC and it failed to start again and had this in the logs. I’d appreciate any help you can provide.

‘’’
Logger: homeassistant.config_entries
Source: components/zha/core/gateway.py:157
First occurred: 11:44:15 PM (1 occurrences)
Last logged: 11:44:15 PM

Error setting up entry ZHA for zha
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 293, in async_setup
result = await component.async_setup_entry(hass, self) # type: ignore
File “/usr/src/homeassistant/homeassistant/components/zha/init.py”, line 102, in async_setup_entry
await zha_gateway.async_initialize()
File “/usr/src/homeassistant/homeassistant/components/zha/core/gateway.py”, line 157, in async_initialize
self.application_controller = await app_controller_cls.new(
File “/usr/local/lib/python3.8/site-packages/zigpy/application.py”, line 64, in new
await app._load_db()
File “/usr/local/lib/python3.8/site-packages/zigpy/application.py”, line 56, in _load_db
await self._dblistener.load()
File “/usr/local/lib/python3.8/site-packages/zigpy/appdb.py”, line 470, in load
await self._load_attributes(“attrid=4 OR attrid=5”)
File “/usr/local/lib/python3.8/site-packages/zigpy/appdb.py”, line 491, in _load_attributes
dev = self._application.get_device(ieee)
File “/usr/local/lib/python3.8/site-packages/zigpy/application.py”, line 392, in get_device
return self.devices[ieee]
KeyError: 00:17:88:01:02:9c:ee:41
‘’’

Smells like a zigbee.db corruption to me.

I suspect you are correct, but it seems to have repeated. I can restore from backup again, but it seems entirely possible, even likely, that’s its going to corrupt yet again.

Re-adding all my zigbee devices is a big ask. There are 117 of them with 247 entities after adding those 9 new Hue bulbs.

I might end up taking that step, but not until I’ve exhausted every other option.

So if it is a zigbee.db corruption… what’s the fix for that?

The stupid answer is delete it.
The smart answer is restore it, as you did.

But as the corruption is re-occuring, the db issue would only be a symptom.
Or you have a file system issue, or something on your ZHA setup is corrupting the db over and over again.

Could this be related to the size of the network? When it crashed there were 117 devices connected to ZHA. I have plans to add several more beyond that.

I’ve been wondering if I need to move off that Nortek stick before the network gets much bigger.

Doubtful if it worked with 108, before you added the Hue ones.
The db is quite small and only contain static data

I’ve restored from backup again. I’ll make a copy of the zigbee.db file this time before trying to re-add those lights again.