6

I am trying to figure out how effective my laptop battery is. Therefore, I woud like to see for how long the battery has been running without AC, since reboot or since AC was plugged in last.

Is this possible? If not, I'll just have to time it manually myself of course.

I'm running Ubuntu 14.

anaotha
  • 846
  • 1
  • 7
  • 12

2 Answers2

5

I think that upower -d can give you some answers, it shows info about the batteries.

Another source of info is /sys/class/power_supply/XX where XX is any battery listed in the folder...

You can see upower official docs to find more info

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
  • 3
    It doensnt answer my particular question, sadly, but does contain useful info. Thanks anyway:) – anaotha Aug 24 '17 at 13:20
  • 3
    In my case, ```upower -d``` also outputs info for the AC device. The 'updated:' timestamp is the moment the AC power was either connected or disconnected. On Ubuntu 18.04, it also displays how many seconds ago this was. – anneb Mar 10 '20 at 10:45
  • @anneb no it doesn't. It's the last time it was started "in use". Nothing to do with AC being plugged in or not. eg unplug,, run on battery, shut down, restart - the updated is the time it turned back on. – RichieHH Apr 30 '21 at 04:40
  • @RichieHH Majority of people I'd say would be calculating the time their computer can run on battery. And in most cases that wouldn't include a reboot (just constant usage). And for that scenario, time update is very relevant. – Muhammad bin Yusrat Jul 27 '21 at 21:36
0

It's absolutely inexcusable and horrible Linux doesn't have this feature (at least in XFCE/or using any console utilities), so that's how I added it:

# cat /etc/udev/rules.d/99-battery-charging.rules
SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/usr/local/bin/battery-logger.sh Plugged-in or charging"

# cat /etc/udev/rules.d/99-battery-discharging.rules
SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/usr/local/bin/battery-logger.sh Discharging"

# cat /usr/local/bin/battery-logger.sh
#! /bin/bash

export LANG=en_DK.UTF-8
echo "$(date +"%x %X") $(cat /sys/class/power_supply/BAT0/capacity)% $@" >> /var/log/battery.log
Artem S. Tashkinov
  • 26,392
  • 4
  • 33
  • 64