How to count battery cycles?

12,811

I've just looked into your question... so it might be too late to answer you since it's been years you've posted it.

You are using a rather old ubuntu that is known/was known at that time to have trouble in that specific domain.

However I encourage you to see this question : How to check battery status using terminal?

The answer of Lekensteyn is the start of what you are looking for.

As you can see in the answer the matter evolves along the kernel version and so the solution ...

To be more specific and retaking your conditions (get status and ubuntu 12.04), you need upower in your system and can create a script like :

#!/bin/sh
DATE=$(date +%Y-%m-%d:%H:%M:%S)
STATE=$(upower -i /sys/class/power_supply/BAT0 | awk '/state/ {print $2}')
echo "$DATE $STATE" >> /var/log/battery_status.log

Then add it in a monitoring process loop ... or a crontab.

It might need root privilege (sudo)

Hope this helps.

Share:
12,811

Related videos on Youtube

The_guy_with_a_laptop
Author by

The_guy_with_a_laptop

Updated on September 18, 2022

Comments

  • The_guy_with_a_laptop
    The_guy_with_a_laptop over 1 year

    Like most users that have searched know, Manufacturers ACPI implementation is a mess and for most of our laptops, battery info is unavailable or wrong (on a dell inspiron 15z, the rate is divided by 10).

    Is there a way (using a perl/python/bash script, an existing package or whatever) to log battery cycles on Ubuntu 12.04?

    (what is a battery cycle ?)

    A charge cycle means using all of the battery’s power, but that doesn’t necessarily mean a single charge. For instance, you could listen to your [device] for a few hours one day, using half its power, and then recharge it fully. If you did the same thing the next day, it would count as one charge cycle, not two, so you may take several days to complete a cycle. Each time you complete a charge cycle, it diminishes battery capacity slightly, but you can put [device battery] through many charge cycles before they will only hold 80% of original battery capacity. Apple courtesy

    My laptop is a Clevo W150HRM, and when I do : cat /sys/class/power_supply/BAT0/cycle_count I get: 0 My laptop is 2 years old.

    Thank you by advance.

    • grantbow
      grantbow about 9 years
      counters are not hard. what data can you use to count?
    • Bahaïka
      Bahaïka almost 9 years
      Of course counters are hard ! They're stored on the battery firmware. (Yes, batteries DO have firmwares)
  • GCP420
    GCP420 over 5 years
    I tried, the $STATE returns blank. even just running the line separately. What is missing? ys GCP
  • AstroFloyd
    AstroFloyd over 2 years
    You can run upower -d to dump all data and see what your device is (mine is called /org/freedesktop/UPower/devices/battery_BAT0). upower -h provides more help. Here's a script that stores the date and eight relevant numbers to a log file for my situation: gist.github.com/AstroFloyd/456f7db5ec80409d617211ce1579c2b4