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

Improved battery level accuracy with updated voltage-to-percentage calculation #7929

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

RubenKelevra
Copy link

@RubenKelevra RubenKelevra commented Sep 2, 2024

  • Updated the voltage-to-percentage conversion to provide a more realistic view of battery levels, especially at lower voltages.
  • The previous method sometimes showed full or half-full batteries even when they were actually low.

Fixes Koenkk/zigbee2mqtt#8499

Comparison

Voltage Old Conversion Percentage New Conversion Percentage
2600 12.4 0.0
2650 14.4 0.0
2700 16.4 10.0
2750 19.5 25.0
2800 27.0 40.0
2850 34.5 55.0
2900 42.0 70.0
2950 71.0 80.0
3000 100.0 90.0
3050 100.0 95.0
3100 100.0 97.5
3150 100.0 98.8
3200 100.0 100.0

@RubenKelevra
Copy link
Author

@Koenkk I guess it would make sense to adapt the "3V_1500_2800" conversion as well?

@RubenKelevra RubenKelevra marked this pull request as ready for review September 2, 2024 02:09
@Koenkk
Copy link
Owner

Koenkk commented Sep 2, 2024

Where is the calculation based on?

@RubenKelevra
Copy link
Author

RubenKelevra commented Sep 2, 2024

Where is the calculation based on?

I've explained that here:

Koenkk/zigbee2mqtt#8499 (comment)

It's a mix of two things: Remaining battery energy capacity specs by battery manufacturers and the fact that most devices won't accept 2.5 V and will often struggle with 2.6 V. So the remaining battery energy capacity below 2.7 V is ignored - because it's not useable.

For specs see:

https://www.duracell.com/wp-content/uploads/2021/06/CR2032CH_245mAh-CS.pdf
https://www.cr2032.co/cms/prodimages/panasonic_cr2032_datasheet.pdf

@Koenkk
Copy link
Owner

Koenkk commented Sep 2, 2024

I see, note that this change won't affect Lumi devices (which are often referred to in Koenkk/zigbee2mqtt#8499) since those use e.g. meta: {battery: {voltageToPercentage: {min: 2850, max: 3000}}},

@RubenKelevra
Copy link
Author

RubenKelevra commented Sep 2, 2024

Where do min/max come from? Does the device send those?

Like is that the measuring width of the voltage meter on the device or something like that?

In this case I would change the PR to do the same conversion like above, just clamp the maximum value (and everything above) to 100% and clamp the minimum value (and everything below) to 0%.

…lculation

- Updated the voltage-to-percentage conversion to provide a more realistic view of battery levels, especially at lower voltages.
- The previous method sometimes showed full or half-full batteries even when they were actually low.
@Koenkk
Copy link
Owner

Koenkk commented Sep 3, 2024

Like is that the measuring width of the voltage meter on the device or something like that?

I believe these values came from Koenkk/zigbee2mqtt#8499, everything below 2850 mv is considered dead

@RubenKelevra
Copy link
Author

RubenKelevra commented Sep 3, 2024

Ah, alright.

I've looked through my dead battery container yesterday, and they were either below 1 V or between 2.6-2.7 Volt, measured with a multimeter. So most of my sensors must have kept going until 2.7 or 2.6 Volt — despite being made by Xiaomi.

So my suggestion would be to keep the minimum voltage variable, which can be set if we know a specific voltage at which the device will usually stop working.

If it is set, the percentage calculation is modified to reflect this.

The upper end however isn't needed.

If you like this solution, LMK and I implement it.

@RubenKelevra RubenKelevra marked this pull request as draft September 3, 2024 19:56
@Koenkk
Copy link
Owner

Koenkk commented Sep 4, 2024

So my suggestion would be to keep the minimum voltage variable, which can be set if we know a specific voltage at which the device will usually stop working.

Maybe I'm not understanding it, but that's what we do right? It may be a bit on the high side but the voltage at which the Xiaomi devices dies is somewhere between 2600-2850mv.

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.

🔋 (Xiaomi) Batteries values are questionable
2 participants