Computed Battery formula needed

kaykor7 years ago

I would like a computed formula to calculate percentage of remaining battery life. Lithium batteries are not linear so their discharge rate is not a simple formula. I don't seem to be smart enough to use examples to make this work, or any computed formula for that matter. On phones and higher end devices their is a circuit with intelligence that does this more accurately.

Any ideas or help would be greatly appreciated.

Pseudo:
If battery >=4.20 then 100% else >=4.03 then 75% else >=3.86 ...etc
With a popup(alert) on the the web interface for equal to and below 3.67

4.20v = 100%
4.03v = 76%
3.86v = 52%
3.83v = 42%
3.79v = 30%
3.70v = 11%
3.6?v = 0%

jovi7 years ago

Hello Friend.
It depends a lot on external factors but maybe this web can help you understand
http://bateriasdelitio.net/?p=80

kaykor7 years ago

Not pretty, and not even sure if totally functional yet. But here is my solution to Battery percentage Levels. Five separate computed Attributes. Are there any suggestions for a better way.

75-100Percent

Battery Level

if (battery <=4.50 && battery >=4.00) { 100; } else {null;}```

50Percent

Battery Level

if (battery <=3.99 && battery >=3.83) { 50; } else {null;}```

25Percent

Battery Level

if (battery <=3.79 && battery >=3.73) { 25; } else {null;}```

10Percent

Battery Level

if (battery <=3.72 && battery >=3.67) { 10; } else {null;}```

solow

Alarm

if (battery <=4.50 && battery >=3.65) { null; }  else {'Help';}```
kaykor7 years ago

Previous post does not work. But it turn's out you can use nested if-else statements. Will let you know if it works as expected.

kaykor7 years ago

This does work:

Description: batteryPercentage

Attribute: BatteryLevel

if (battery <=4.60 && battery >=4.03) { 100; } else
if (battery <=4.03 && battery >=3.86) { 76; } else
if (battery <=3.86 && battery >=3.83) { 52; } else
if (battery <=3.83 && battery >=3.79) { 42; } else
if (battery <=3.79 && battery >=3.70) { 30; } else
if (battery <=3.70 && battery >=3.6) { 10; } else {null;}

Type: Number

I use this to send alarm:

Description: LowBattery

Attribute: Alarm

if (battery <=4.50 && battery >=3.65) { null; } else {'Help your killing me';}

Type: String

Alejandro Ma year ago

nice thank you, it seems to work sometimes i will try with my ruptela trace5

Hello, this command worked for me

battery ? battery <= 3.6 ? 0 : battery >= 4.2 ? 100 :math:round(((battery - 3.6) / (4.2 - 3.6)) * 100) : null