Achronite / mqtt-energenie-ener314rt

MQTT interface for Energenie ENER314-RT add-on board for the Raspberry Pi, designed for use by Home Assistant.
MIT License
13 stars 5 forks source link

Refine battery % calculation #31

Closed Achronite closed 1 year ago

Achronite commented 1 year ago

After some testing, when the switch statement for battery % calculation uses this formula: 9412 - 23449(v/batteries) + 19240(vv/batteries) - 5176(vvv/batteries)

It does not seem to work properly and can return a -ve value. Fix this to work!

Achronite commented 1 year ago

Thoughts: Could try using the table here: https://en.wikipedia.org/wiki/Alkaline_battery#Voltage

Achronite commented 1 year ago

New code for calculation released to development branch based on the values above:

let v = msg[key]/batteries;
let charge = 0;
if (v >= 1.55){
   charge = 100;
} else if (v < 1.1 ){
   charge = 0
} else if (v < 1.18 ){
   charge = 5;
} else {
   // use a simple linear equation for the rest (y=mx+c), based on 1.44v=90% and 1.2v=10%
   charge = (333.3*v) - 390;
}