Button to reset the Zigbee2Mqtt integration

The Zigbee2mqtt integration has an “Enable/Disable” button that stops the containers, but does not clean up either database variables or files on disk. There is no way to start from scratch without manual intervention. The idea is to add a “Reset” button on the setup page, with confirmation (like on matterbridge/node-red), that performs a full reset: disconnection, deletion of variables, deletion of files and containers.

Reset procedure:

  1. Call this.disconnect() (stop containers + MQTT disconnection)
  2. Delete all config variables in the database via this.gladys.variable.destroy(key, this.serviceId) for each CONFIGURATION key in constants.js:
  • ZIGBEE2MQTT_DRIVER_PATH, Z2M_BACKUP, ZIGBEE_DONGLE_NAME, Z2M_MQTT_MODE, Z2M_TCP_POR, Z2M_MQTT_URL
  • Z2M_MQTT_USERNAME_KEY, Z2M_MQTT_PASSWORD_KEY
  • GLADYS_MQTT_USERNAME_KEY, GLADYS_MQTT_PASSWORD_KEY
  • DOCKER_MQTT_VERSION, DOCKER_Z2M_VERSION
  1. Delete the zigbee2mqtt/ folder on disk
  2. Reset state (discoveredDevices, usbConfigured, status flags, etc.)
  3. Emit a status event via this.emitStatusEvent()

:warning: Only available in “Install from Gladys” mode

Design proposal + messages

With confirmation

For Gladys devices linked to this integration, I think they should be kept (otherwise, we might break scenes?).

For what it’s worth, it looks perfect to me. It’s very clear!

Regarding Gladys + backup, if we restore a version with an old dongle, is there any risk? Or conversely, is it an additional safety net because we could restore in case of a mistake?

That’s something to test, I don’t know how it behaves. In the cases we’ve seen on the forum, it was a different situation: dongle change with files already on the disk.

In the case of a Gladys Plus restore, we don’t restore the Zigbee2mqtt files

1 Like

For me, we back up the entire contents of the zigbee2mqtt folder (so configuration.yaml, database.db and coordinator_backup.json).

But the restore checks whether a new configuration is present. If you restore a backup made with an old dongle (while a new dongle is plugged in and z2m is not initialized), you will also need to use that button.

Ok, I implemented it this morning!

I took the opportunity to strengthen the integration’s robustness, because there were instabilities that became even more apparent with this new feature.

Notably the stopped-container bug: until now, in Gladys, if the Zigbee2mqtt container was already stopped, a 304 error was issued and we never proceeded to remove the container. It’s fixed for all integrations :white_check_mark:

I tested many cases locally on a mini-PC, and it works really well!

Screenshots:

The PR:

The Docker image:

gladysassistant/gladys:zigbee2mqtt-reset-button

(Already built on x64, being built for arm64)

I’ll do a release this afternoon, if you want to test before then it’s possible :wink:

1 Like

Tested on an instance with a dongle but no paired devices. It works well, the states are correct afterwards and the folders/variables/containers are properly deleted :check_box_with_check:

1 Like

Thanks for the quick test @cicoub13! I’m making a new version of Gladys this afternoon

The new button is available in Gladys Assistant v4.70: