How is battery percentage correct?

The code below from Muse Luxe maps battery voltage to percent, specifically 4.58V to 100% and 3.27V to 0%. How?? A Li-Ion cell has a nominal voltage of 3.7V and usually 3V is considered 0% and 4.2V is considered 100%. This code makes absolutely zero sense.

Needless to say, my battery percentage makes no sense either:

  - platform: template
    name: Battery
    id: battery_percent
    device_class: battery
    unit_of_measurement: "%"
    accuracy_decimals: 0
    state_class: measurement
    entity_category: diagnostic
    update_interval: 15s
    filters:
      - calibrate_polynomial:
          degree: 3
          datapoints:
            - 4.58 -> 100.0
            - 4.5 -> 97.1
            - 4.47 -> 94.2
            - 4.44 -> 88.4
            - 4.42 -> 82.7
            - 4.41 -> 76.9
            - 4.41 -> 71.1
            - 4.37 -> 65.3
            - 4.35 -> 59.5
            - 4.31 -> 53.8
            - 4.28 -> 48.0
            - 4.26 -> 42.2
            - 4.23 -> 36.4
            - 4.21 -> 30.6
            - 4.19 -> 24.9
            - 4.16 -> 19.1
            - 4.1 -> 13.3
            - 4.07 -> 10.4
            - 4.03 -> 7.5
            - 3.97 -> 4.6
            - 3.82 -> 1.7
            - 3.27 -> 0.0
      - lambda: return clamp(x, 0.0f, 100.0f);

Can anyone explain how the code above makes sense?

yes it’s off, stay tunned we are about to make a major update for HA on Luxe, Proto, Mn Cast and the Radio

A new version (2025.3.1) is available. It fixes several minor issues, including battery management.

You can download it from raspiaudio.github.io (or from the RASPIAUDIO/esphomeLuxe GitHub repository) or let Home Assistant suggest it to you…

1 Like

Thank you, appreciated!! Will install tonight.

One question, which else was changed besides the battery? Just comparing the diff only shows delta in the battery reporting.

Thank you!

the battery lookup table was updated