2021.10 broke ZigBee with zha/husbzb1

Hi all,

Over the past couple of months, I haven’t been able to update my HA instance, because every time I do my zigbee integration fails. The configuration screen shows an error stating “failed to set up”. I finally got a chance to dig in deeper today, and here’s what I found in the logs:

HA has the following: `Logger: homeassistant.config_entries
Source: components/zha/core/gateway.py:152
First occurred: 4:25:23 PM (1 occurrences)
Last logged: 4:25:23 PM

Error setting up entry HubZ Smart Home Controller, s/n: C13019EA - Silicon Labs for zha
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 304, 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 152, in async_initialize
    self.application_controller = await app_controller_cls.new(
  File "/usr/local/lib/python3.9/site-packages/zigpy/application.py", line 61, in new
    await app._load_db()
  File "/usr/local/lib/python3.9/site-packages/zigpy/application.py", line 50, in _load_db
    self._dblistener = await zigpy.appdb.PersistingListener.new(database_file, self)
  File "/usr/local/lib/python3.9/site-packages/zigpy/appdb.py", line 85, in new
    await listener.initialize_tables()
  File "/usr/local/lib/python3.9/site-packages/zigpy/appdb.py", line 72, in initialize_tables
    await self._run_migrations()
  File "/usr/local/lib/python3.9/site-packages/zigpy/appdb.py", line 571, in _run_migrations
    await migration()
  File "/usr/local/lib/python3.9/site-packages/zigpy/appdb.py", line 709, in _migrate_to_v7
    await self._migrate_tables(
  File "/usr/local/lib/python3.9/site-packages/zigpy/appdb.py", line 593, in _migrate_tables
    await self.execute(
  File "/usr/local/lib/python3.9/site-packages/aiosqlite/core.py", line 184, in execute
    cursor = await self._execute(self._conn.execute, sql, parameters)
  File "/usr/local/lib/python3.9/site-packages/aiosqlite/core.py", line 129, in _execute
    return await future
  File "/usr/local/lib/python3.9/site-packages/aiosqlite/core.py", line 102, in run
    result = function()
sqlite3.IntegrityError: UNIQUE constraint failed: attributes_cache_v7.ieee, attributes_cache_v7.endpoint_id, attributes_cache_v7.cluster, attributes_cache_v7.attrid

`

I searched and found a couple other people have posted this issue, but absolutely no resolution or traction toward solving it.

I also have the following database issue in my logs, which isn’t there if i reinstall a backup:

Logger: zigpy.appdb
Source: /usr/local/lib/python3.9/site-packages/zigpy/appdb.py:69
First occurred: 4:25:23 PM (1 occurrences)
Last logged: 4:25:23 PM

SQLite database file is corrupted! row 98 missing from index attributes_idx_v6 row 99 missing from index attributes_idx_v6 row 100 missing from index attributes_idx_v6 row 101 missing from index attributes_idx_v6 row 102 missing from index attributes_idx_v6 wrong # of entries in index attributes_idx_v6

Anyone have any advice as to where to start with this?

If you are not particularly attached to your history data you can delete the recorder database and restart Home Assistant. It will create a new one.

What do I lose by deleting it? And how do I go about deleting the database? I can’t navigate to /usr/local/lib/python3.9/site-packages/zigpy via ssh (everything beyond /usr/local/lib doesn’t exist), and if I have no idea how to navigate inside the HA CLI interface I can access through my virtualbox dashboard

All your history data.

The database is stored in your Home Assistant configuration directory (’/config/’) and is named home-assistant_v2.db. Just delete that file, then restart.

If that is too drastic for you, search the forum there are a couple of topics on repairing the database.

Thanks. I’ll do some looking before I nuke it, but I’m not too scared to nuke it if I won’t have to set everything up again.

A word of encouragement: I’ve deleted the database and it was relatively painless. Turns out I don’t rely on history data nearly as much as I would have thought.

Also, I have a HUSBZB on a RPi 3B+ and updated to 10.6 without issue. I’ve updated a few times since, and am currently on 11.5. ZHA is still purring along perfectly.

No you don’t lose any configuration, just state history (pretty graph data).

So I deleted the database file, but upon reboot, I trigger the same DB file is corrupted error, escept that the row numbers are changed… Now it’s row 96-100 instead of 98-102.

Any thoughts on why that issue is persistent and how to fix it? I don’t have anything else in my logs relating to zigbee. I rolled back to 2021.9.7 so that my Zigbee network would be online again, just so that I was resolving one problem at a time, but it seems I clearly have some issue in my Zigbee network/integration I need to resolve.

Something is incorrectly using your database. I would start by disabling any third party integrations you have.

I just disabled everything under integrations except for Supervisor, Mobile App, Z-wave JS and ZHA… Still have the error.

Experiencing this issue now… did you ever get this resolved?