Determine when laptop was last plugged in to power

I am looking for log entries of when my device is plugged and unplugged to/from mains power, or when the battery changes from discharging/charging state. Which log entries do I need to look for for this?


Solution 1:

See this question:

UPower stores its historical information in four files in /var/lib/upower/
This is the data gnome-power-statistics uses to draw its charge/discharge profiles.
For example:

$ ls -t /var/lib/upower/* | head -4
/var/lib/upower/history-time-empty-AL15B33-48-3241.dat
/var/lib/upower/history-time-full-AL15B33-48-3241.dat
/var/lib/upower/history-charge-AL15B33-48-3241.dat
/var/lib/upower/history-rate-AL15B33-48-3241.dat

Looks like you could check charging/discharging state changes in the history-charge file:

$ cat history-charge-AL15B33-48-3241.dat
1475784954      58.000  discharging
1475785164      57.000  discharging
1475785344      56.000  discharging
1475785598      57.000  charging
1475786432      58.000  charging

Fist column is timestamp. You could use date -s @timestamp to get something more readable:

$ cat history-charge-AL15B35-48-3241.dat | while read f; do
  d=$(date +"%b %e %H:%M:%S" -s @`echo $f | cut -d\  -f1`);
  echo "$d  $f" ; done
Oct  6 22:15:54  1475784954      58.000  discharging
Oct  6 22:19:24  1475785164      57.000  discharging
Oct  6 22:22:24  1475785344      56.000  discharging
Oct  6 22:26:38  1475785598      57.000  charging
Oct  6 22:40:32  1475786432      58.000  charging