Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support z2m devices with / in 'friendly name' #66

Merged
merged 2 commits into from
Jan 29, 2025

Conversation

duvholt
Copy link
Contributor

@duvholt duvholt commented Jan 26, 2025

All my zigbee2mqtt devices use the namespace convention described here:
https://www.zigbee2mqtt.io/guide/usage/mqtt_topics_and_messages.html#zigbee2mqtt-friendly-name

This doesn't work in Bifrost as it ignores all device messages with a /. I've therefore been using a forked version where I just removed that check until I could investigate how this could be properly fixed.

Initially I thought this would require handling the weird edge cases with device1/set/attribute described here:
https://www.zigbee2mqtt.io/guide/usage/mqtt_topics_and_messages.html#zigbee2mqtt-friendly-name-set
But that's not relevant as all those messages are only sent to the websocket server and it seems like the only case we really need to handle is availability messages.

At least it looks like that's what the z2m frontend does:
https://github.com/nurikk/zigbee2mqtt-frontend/blob/25d88e716e4313e0643a48f32575974c0f4d1a98/src/ws-client.ts#L298-L304

@duvholt
Copy link
Contributor Author

duvholt commented Jan 26, 2025

Just saw that there is another edge case with device1/action from looking at the gradient PR (and verifying with a hue dimmer). Doesn't look like that is documented in the z2m MQTT section and I suspect the z2m frontend doesn't really handle them correctly either.

@duvholt
Copy link
Contributor Author

duvholt commented Jan 26, 2025

Did some more digging and there's also this weird wildcard: https://github.com/Koenkk/zigbee2mqtt/blob/c586df82429546fba56ab10b579bf225bb33ebb2/lib/extension/homeassistant.ts#L1277

Looks like it was implemented for a pretty specific use case, but I'm not sure how that message is supposed to be handled.

Other than that it looks like availability and action are the only exceptions.

@chrivers
Copy link
Owner

Great work! And nice analysis. I completely agree with your review.

Yes, unfortunately the z2m design is a bit of a mess in this respect. There is no perfect solution, except maybe avoiding / in device names 😅

Since the next check in the code checks that the name exists in our device map, the worst case of this change should be that users see a number of spurious warnings in the log.

Not great, but not fatal - and it only happens in case we've both missed something.

So let's do this 👍 And thank you for another good contribution :)

@chrivers chrivers merged commit c257680 into chrivers:master Jan 29, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants