Skip to content

Battery Time Left formula

Chris Monahan edited this page Jan 11, 2023 · 1 revision

The Time Left section under Battery reports as follows:

  • When the laptop is unplugged, Time Left shows remaining time until battery is depleted.
  • When the laptop is plugged in and charging, Time Left shows remaining time until battery is fully charged.
  • When the battery is fully charged, Time Left will often time say Full which the author feels is more pleasant than 0m

Others have asked why the calculation differs from other tools, notably Gnome itself. First, rest assured there is no magic in Vitals, as it simply reports data from the /sys/class/power_supply/BATx/uevent file. In our findings, the data in this file is very volatile. If you open or close an app that has high CPU usage, reading the contents of this file back to back will change the battery time left estimation from 3 hours to 1 hour by simply launching an app.

Gnome itself queries the battery states very infrequently so these numbers don't appear random or invalid. I would estimate that it polls the battery every minute or so.

Vitals can be configured to poll the sensors down to 1 second intervals. When developing the Time Left feature, the Time Left value would jump around quite a bit as described above. Thus, an array tracking the last 10 values is used, and the average is displayed.

In closing, reporting numbers differ from other apps is still valid, so long as there is a definition and reason for it. This is how Vitals shows this data.