-
Notifications
You must be signed in to change notification settings - Fork 36
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
Set up reporting on AC attribute divisor and multiplier #348
Conversation
AttrReportConfig( | ||
attr=ElectricalMeasurement.AttributeDefs.ac_power_divisor.name, | ||
config=REPORT_CONFIG_IMMEDIATE, | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put these at the very beginning just in case the device's attribute reports are sent in the order of the reporting config. If this is the case, you may need to re-join the device to get this to work.
6d53bb8
to
a29cfdf
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #348 +/- ##
=======================================
Coverage 96.52% 96.52%
=======================================
Files 61 61
Lines 9499 9506 +7
=======================================
+ Hits 9169 9176 +7
Misses 330 330 ☔ View full report in Codecov by Sentry. |
Should also resolve: home-assistant/core#129723 |
I unfortunately haven't had time to drive and pick one of these plugs up yet so if anyone has one to test, let me know if this PR is enough. |
Oh sure, I'll try to merge it into my production environment and test it during this week still! Thanks for the potential fix :) |
@puddly: You set the divisor / multiplier attribute reporting to "immediate" -> Wouldn't it maybe be better/more consistent, to set the same value as for the attribute itself, i.e. REPORT_CONFIG_OP? I mean just a bit worried we might flood the network a lot, if a sensor would toggle a lot between x10 and x1 for example, and the attribute/value isn't might not even gonna update as fast. Important note for users: They have to reconfigure the plugs ZHA entity, in order to update the reporting configuration (otherwise the fix won't help). |
Reporting is based on a "minimum change", subject to a minimum and maximum reporting interval (i.e. don't report more often than once every "min" seconds and report at least once every "max" seconds). Since the reporting config is based on the value of the actual attribute, using the same config for multiple attributes won't really synchronize things. If a device is somehow jittering between 999W and 1001W, I don't think there's a way around it: the divisor and multiplier attributes must be accurate for the power reading to be in any way useful. If they ever are not perfectly synchronized, the power reading will be off by a factor of 10.
Could you record a debug log of the attribute reports ZHA receives when this happens? Maybe the order in which the attribute reports are received is causing issues. Or we aren't reacting properly to them all coming in at once. |
All attributes in Like |
@TheJulianJES That's actually rly interesting. But then if they're changing frequently (like changing load every few seconds, right after it updated in HA), it's a just a matter of push-updates, I mean they shouldn't be polled in this case, right? |
ZHA currently still polls them regardless (every 30 to 45 seconds), as they match the The reason ZHA polls by default is that quite a few smart plugs don't actually support attribute reporting (Tuya included, of course). Theoretically, we could make polling opt-in or opt-out via a But I'm not saying that the issue you're seeing is definitely related to the polling behavior. |
b848e7a
to
c6da8c6
Compare
I've rebased the PR for now, as it was conflicting quite a bit. With #354, we've also separated the attributes that we're polling for the EM cluster from the To keep the same behavior in this PR from before the rebase, I've also added all multipliers and divisors to Also to keep in mind that attributes in And in a future PR, we might want to include |
I was adding that in #339 since it adds phases b/c of the power factor too. |
Ok, let's merge #339 first then (if the last changes are made). Looking at Z2M, I also wanna disable polling completely for this device, as it seems to fully support attribute reports. We'll still poll the attributes once when HA/ZHA is restarted. To disable polling, it's enough to just add the model here:
That might reduce/eliminate the jumping between old/new divisor for the power, assuming the device sends the attribute reports in the correct order. With our polling implementation, I guess the order can't be guaranteed. In the future, instead of adding all models in ZHA, we can use |
@TheJulianJES I can test it and make the logs for @puddly - To drop polling I can just revert commit c6da8c6 ? |
That will disable polling for those specific attributes only, but for all devices, so if you have some Tuya plugs, they might not work after doing that. What I'd recommend is just adding "INSPELNING Smart plug" here:
That should disable polling completely, only for the IKEA plug. |
It looks like the original code shadowed `attrs`
c6da8c6
to
f38f7dd
Compare
Rebased again. Also completely disabled polling for the IKEA plug now, as it supports attribute reporting (1d4e423). And also removed polling for the multipliers/divisors for all plugs (4757673). One downside of this PR is still that attributes in For now, I think this should be good to go. |
Should resolve zigpy/zha-device-handlers#3374
I'll test it out with a real plug when I get one.