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

Xiami/Aqara door/window sensor mistakenly detected as switch #31589

Closed
daniele-athome opened this issue Feb 7, 2020 · 12 comments · Fixed by #31619
Closed

Xiami/Aqara door/window sensor mistakenly detected as switch #31589

daniele-athome opened this issue Feb 7, 2020 · 12 comments · Fixed by #31619

Comments

@daniele-athome
Copy link
Contributor

daniele-athome commented Feb 7, 2020

The problem

I have a Xiaomi/Aqara door/window sensor that I can use with a ConBee II USB stick.
Joining procedure goes fine, but I notice that the OnOff cluster is detected as an output cluster. If I understand ZigBee correctly, output clusters are used for controlling a device, whereas input clusters are used to receive information and data from a device.

Anyway, after restarting HA, the OnOff cluster becomes an input cluster and what was a binary sensor before now becomes a switch. This is due to this I believe: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/zha/core/registries.py#L73

If I understand correctly, that line should have "BINARY_SENSOR", much like the other ones.
The opposite change would be needed here: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/zha/core/registries.py#L86

Anyway, I checked in the ZigBee database file, and the OnOff cluster is correctly (again, "correctly" if I'm understanding ZigBee clusters the right way) persisted as an input cluster. It seems like in-memory data in the zha component is not matching data stored in the zigbee database?

Also, the power cluster (that is, battery status) is not persisted at all in the database, but I shall open a separate bug for that later.

Environment

  • Home Assistant release with the issue: 0.105.2
  • Operating environment (Hass.io/Docker/Windows/etc.): Debian Linux, virtualenv-based installation
  • Integration causing this issue: zha
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/zha

Problem-relevant configuration.yaml

(Not applicable I believe)

Traceback/Error logs

I'm not sure what to provide here. ZHA device joining logs maybe?

Additional information

This issue might have some relation with #15477.

@daniele-athome
Copy link
Contributor Author

This might be also related to #31592 (I'm having that issue too)

@Adminiuga
Copy link
Contributor

Enable debug logging in configuration.yaml to set level permanently

logger:
  default: info
  logs:
    asyncio: debug
    homeassistant.components.zha: debug
    zigpy: debug
    bellows: debug
    zigpy_xbee: debug
    zigpy_deconz: debug
    zigpy_zigate: debug

Remove the device from zha config panel -> pick the device -> remove the device, click on the device button a few times with 1s interval.

Refresh page to doublecheck the device and entities are gone.
Enable debug logging and join device again -- We need to see the device signature. Restart hass and post both logs here

Raw zigpy device has cluster id 0x0006 as input cluster, but there's a quirk which makes it an output cluster. For some reason the quirk isn't applying after a reboot?

@probot-home-assistant
Copy link

Hey there @dmulcahey, mind taking a look at this issue as its been labeled with a integration (zha) you are listed as a codeowner for? Thanks!

@Adminiuga
Copy link
Contributor

could be related to #31592
Try the same work around, only with Xiaomi it is trickier. You need to wake up the device with the button and then read the attribute. may take a few attempts. Make sure you successfuly read both manufacturer and model attrs, depending on which one are misssing in the db

@daniele-athome
Copy link
Contributor Author

Raw zigpy device has cluster id 0x0006 as input cluster, but there's a quirk which makes it an output cluster.

Why should an input cluster be wrong in this case? It is a sensor sending data. I have another Aqara sensor too exposing input clusters for reading temperature, pressure and humidity. Am I missing something?

For some reason the quirk isn't applying after a reboot?

I'll try the workaround in #31592 in the meantime and get back to you later today with the logs.

@Adminiuga
Copy link
Contributor

After a reboot, does Xiaomi device shows model and manufacturer? If either of those are Unknown, then I strongly suspect the problem is with zigpy. Let me know if the workaround works then can skip the logs

@daniele-athome
Copy link
Contributor Author

daniele-athome commented Feb 7, 2020

After a reboot, does Xiaomi device shows model and manufacturer? If either of those are Unknown, then I strongly suspect the problem is with zigpy.

Yes, that was the case: both unknown. And the workaround worked for the door sensor: it correctly restores both battery status and on/off binary sensor. Also manufacturer and model were correctly loaded.
However I'm still in doubt whether it's right to consider it an output cluster. What do you think?

@Adminiuga
Copy link
Contributor

Well, for that kind of sensor, it was supposed to be an IAS Zone cluster.
I wish Xiaomi implemented it as an output cluster, as it would allow me to pair that sensor directly to lights, but alas.
Currently any input on_off clusters are discovered as "switches" if there's no proper device type and it is a problem with Xiaomi cause we cannot actively query device status. It is more of a workaround for now, until a better solution exists

@daniele-athome
Copy link
Contributor Author

Ok I see your point. Should we keep this issue open then? Should I open an issue to zigpy? And if so, what should I tell them?

@Adminiuga
Copy link
Contributor

open one in zigpy and link this issue there too.

@Adminiuga
Copy link
Contributor

I mean issue related to manufacturer info being lost.

@daniele-athome
Copy link
Contributor Author

Opened zigpy/zigpy#289. I'm keeping this one open until zigpy publishes a fix. Thanks for the help @Adminiuga!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants