Re-paired device stays unavailable in Home Assistant until Z2M restart (availability never published after remove)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 90/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- backend
Research direction
Start with lib/extension/availability.ts, especially the device removal and availability-publication paths, then inspect test/extensions/availability.test.ts for existing availability coverage. Reproduce the remove-and-re-pair sequence with a test that expects the device's retained availability state to be published as online again. The work is done when the regression test passes, the availability behavior is restored without a Z2M restart, and the project checks pass.
Written by the indexing model from the issue text.
Description
What happened?
I removed a contact sensor (SNZB-04P) from Z2M and paired the same device again without restarting Z2M. Pairing and interview went fine and the device kept sending contact/tamper/battery updates, but all of its entities in Home Assistant stayed unavailable.
Checking the MQTT debug info in HA, zigbee2mqtt/0xa4c138121812ffff/availability had no message at all. The removal clears the retained topic, and after the device joined again nothing was published there. Another device (Aqara MCCGQ12LM) that I paired a few minutes earlier got {"state":"online"} right away. It had not been in Z2M before.
After restarting the add-on, publishAvailabilityForAllEntities() published online and the sensor showed up correctly in HA.
Looking at lib/extension/availability.ts, publishAvailability() skips publishing when lastPublishedAvailabilities already holds the same value. When a device is removed, clearDevice() clears the timer and the debouncer but keeps that entry. So the re-paired device, which was online before removal, is never published as online again until a restart.
What did you expect to happen?
After removing a device and pairing it again, <device>/availability should be published as online once the device is seen, the same as for a new device.
How to reproduce it (minimal and precise)
- Enable availability. Have a device that is currently
online. - Remove it (frontend, or
zigbee2mqtt/bridge/request/device/remove). - Pair the same device again, without restarting Z2M.
zigbee2mqtt/<ieee>/availabilitystays empty, so entities in HA that use it remainunavailable.
I have a small fix with a test for this: clearDevice() also deletes the device from lastPublishedAvailabilities. Two lines in availability.ts plus a test in test/extensions/availability.test.ts that fails before the change. The full test suite and pnpm run check pass. I used an AI assistant to help find the cause and write the fix and test, and I've reviewed and tested it myself. Would a PR for this be welcome?
Zigbee2MQTT version
2.14.2 (the same code is on dev at 3a0a038)
Adapter firmware version
20210708
Adapter
ZStack3x0
Setup
Home Assistant OS add-on
- Dominant language
- TypeScript
- Stars
- 15.9k
- Forks
- 2.1k
- Avg merge
- 13h 22m
- Merged PRs (30d)
- 37
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Koenkk/zigbee2mqtt
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
Koenkk/zigbee2mqtt#33890 ·
Maintainers usually reply within 1 day
-
problem
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Koenkk/zigbee2mqtt#33882 ·
Maintainers usually reply within 1 day
-
problem
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
Koenkk/zigbee2mqtt#33869 ·
Maintainers usually reply within 1 day
-
[New device support]: TERNCY DIM004 (24 W Jingwei dimmer)Possibly taken @calvinastroboy claimed this today. Opennew device support
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Koenkk/zigbee2mqtt#33868 · 1 comment ·
Maintainers usually reply within 1 day
-
new device support
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Koenkk/zigbee2mqtt#33861 · 1 comment ·
Maintainers usually reply within 1 day
All issues in Koenkk/zigbee2mqtt
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
eliasstravik/herdr-projects#1700 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
[bug] Socrates launchd-path adapter throws EISDIR when an import names a folder beside its .ts fileOpen
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
danielmiessler/LifeOS#3123 ·
Maintainers usually reply within 5 days
-
[Feature]: Skill Workshop skill diet should use the configured utility model, not always the primaryOpenclawsweeper:fix-shape-clear clawsweeper:needs-live-repro clawsweeper:needs-maintainer-review clawsweeper:needs-product-decision clawsweeper:no-new-fix-pr impact:auth-provider issue-rating: 🐚 platinum hermit P2
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
openclaw/openclaw#210348 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
platform:windows provider:antigravity-cli providers setup triaged wontfix
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
can1357/oh-my-pi#21349 · 1 comment ·
Maintainers usually reply within 1 day