Help, need to filter out value over 100% in battery SOC sensor

Hi, I’ve created an SOC sensor based on my battery voltage.
While it works great, sometimes it will give readings over 100%!

Here is my sensor:

  - platform: copy
    source_id: voltage
    name: "SOC"
    unit_of_measurement: "%"
    filters:
    - calibrate_linear:  
        # Map 0.0 (from sensor) to 0.0 (true value)
        - 40.1 -> 0.0
        - 43.7 -> 2.6
        - 44.5 -> 7.0
        - 46.0 -> 36.0
        - 47.9 -> 70.0
        - 48.9 -> 75.0
        - 49.9 -> 80.0
        - 50.0 -> 85.0
        - 50.1 -> 88.0
        - 50.2 -> 90.0
        - 50.25 -> 93.0
        - 50.80 -> 95.0
        - 51.5 -> 98.5
        - 52.8 -> 100.0
    - median:
        window_size: 7
        send_every: 4
        send_first_at: 3

How do I filter out the state over 100% ?

Thank you

Maybe worth a try?

Ah! That’s a good idea.
I’ll try it out

Welp turns out it’s not really linear… So I have to adjust the value of 100 with trial and error

Yeah - I thought of that after I posted - Maybe whittle it down to close the the maximum overcharge value.

Maybe with calibrate_polynomial?

You can use a lambda filter as last one:

filters:
...
  - lambda: if (x>100) return 100 else return x;
1 Like

Yes, in the I found the best fit curve by going to Wolfram Alpha and plot a curve there manually. I’m using “interpolating polynomial calculator” in WA.