home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.53k stars 30.35k forks source link

[zha] The "Adding device" workflow is buggy, no sensors detected #127936

Open antonGritsenko opened 6 days ago

antonGritsenko commented 6 days ago

The problem

I'm using ZHA about a year and have a very bad experience about adding a device workflow. I did small research and found out that the same problem causes a lot of custom quirks to be developed that actually are not required.

Now about the issue: when you are adding a device it will be found, correctly recognized and attached to the correct quirk, but you have no sensors at all except one (Firmware Update). But device itself works, you can manually query data using Manage Zigbee device dialog and selecting correct cluster and attribute.

After a lot of testing with different devices I think I have found the main reason: this is connected to the expected measure_value and its limitation. I want to show this on the CO2 sensor, but all other devices usually have pretty the same issue.

Expected value for CarbonDioxideConcentration are between 30 and 900 (btw, why 900?) with multiplier 1e-06, its confirmed by the log:

Successfully configured reporting for '{'measured_value': (30, 900, 1e-06)}' on 'carbon_dioxide_concentration' cluster: [ConfigureReportingResponseRecord(status=<Status.SUCCESS: 0>)]

But device could return something like 0,0006659999999999999 instead 0,000666. I was not able to validate what's responsible for it, is it device itself, gateway or ZHA, but it is as it is. There are no logs about the actual value, but if during the initial setup or during reboot of the HA the device return such weird value then you got this in the log:

DEBUG (MainThread) [zha.application.platforms.sensor] measured_value is not supported - skipping CarbonDioxideConcentration entity creation

and sensor not added to the HA. You may need to do several reboots of the HA to catch the correct value and then, by magic, device adding the sensor.

My suggestion will be to try to detect such values and try to convert it to the expected value. Unfortunately, I was not able to find the code that handling this part, so can't says anything more specific. If someone can point me to the right codebase, I will try to prepare some review and maybe PR.

What version of Home Assistant Core has the issue?

core-2024.9.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

ZHA

Link to integration documentation on our website

https://www.home-assistant.io/integrations/zha/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2024-10-08 05:24:43.364 DEBUG (MainThread) [zha.zigbee.cluster_handlers] [0xB0CE:1:0x040d]: Successfully configured reporting for '{'measured_value': (30, 900, 1e-06)}' on 'carbon_dioxide_concentration' cluster: [ConfigureReportingResponseRecord(status=<Status.SUCCESS: 0>)]
2024-10-08 05:24:43.364 DEBUG (MainThread) [zha] Emitting event zha_channel_configure_reporting with data ClusterConfigureReportingEvent(cluster_name='Carbon Dioxide (CO₂) Concentration', cluster_id=1037, attributes={'measured_value': {'min': 30, 'max': 900, 'id': 'measured_value', 'name': 'measured_value', 'change': 1e-06, 'status': 'SUCCESS'}}, cluster_handler_unique_id='a4:c1:38:94:ff:be:25:24:1:0x040d', event_type='zha_channel_message', event='zha_channel_configure_reporting') (0 listeners)

2024-10-08 05:24:43.581 DEBUG (MainThread) [zha.application.platforms.sensor] measured_value is not supported - skipping CarbonDioxideConcentration entity creation

Additional information

No response

home-assistant[bot] commented 6 days ago

Hey there @dmulcahey, @adminiuga, @puddly, @thejulianjes, mind taking a look at this issue as it has been labeled with an integration (zha) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `zha` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign zha` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


zha documentation zha source (message by IssueLinks)

antonGritsenko commented 6 days ago

home-assistant_zha_2024-10-08T02-24-56.490Z.zip Full log of the communication with the device

dmulcahey commented 6 days ago

The problem is actually with the quirk. We’ll look into it.