Linux get battery charge

How can I find the discharge rate of the battery?

Maybe this question was made earlier but I can’t find it. I want to see a terminal command or gui program that can show me the discharge rate of the battery. What hardware parts or programs are using more watts. EDIT: Found additional information regarding my question when using for example PowerTop: https://bbs.archlinux.org/viewtopic.php?id=128319 https://bugs.archlinux.org/task/26416 Both related to the having disable ACPI_PROCFS_POWER in the kernel.

6 Answers 6

You can try powerstat , which gives you the watts used over a period of 5 minutes. To install it, try the following commands:

sudo apt-get install powerstat 

Or you can try the power-usage-report, which I guess, depends on fatrace and powertop.

This indeed showed the Watt usage. I am hoping that powertop or the Gnome power window will have easier to read information on 12.04 about this. Very useful. Thank you jokerdino.

Maybe you’re looking for «Rate» in Power Statistics > Laptop battery > Details?

Power Statistics screenshot

+1. Thank you WarriorIng64. Although in my case the rate always shows 0.0W. So I have never paid attention to it. But nevertheless very good point there. Going to see on 12.04 if it works correctly when it comes out. The laptop is an HP DV6000.

«Linux Power Top» may help (currently available from https://01.org/powertop )

enter image description here

But how are you getting the «Power Usage (ACPI estimate): 14.1W». I am only getting percentages and values I can’t relate to watt usage. My version is 1.97

Ok going out of my mind here. Haven’t found an option to show me what you are showing me in that image. I would be awesome if I could directly see the power usage like that. Even better if I could output that, you know, as a variable for a program or something.

Yeah which shows the same image as yours but there is nothing that says «Hey use this parameter or change this option in the config file to see the power usage».

Linux is in the process of removing things that used to live in proc and putting them in sysfs (a highly structured filesystem for keeping information about the machine).

On my machine, I can find information about the power supply in

Читайте также:  How to scroll linux terminal

This has a current rate file which keeps the charging rate:

So the following gives you an approximation of the charging rate.

calc \( $(cat charge_full) - $(cat charge_now) \) / $(cat current_now) 

calc comes from the apcalc package.

If you want better rate you might be better looking at how charge_now changes over time.

You might also be interesting in looking at this realtime graph

while true; do cat current_now; sleep 1; done | feedgnuplot --stream --line --ymin 0 

To get a feeling of how charge rate is changing over time. I can cause nice juddering drops in charge rate by quickly switching between desktops.

Источник

How to Check Battery Status Using Linux Command Line

How to Check Battery Status Using Linux Command Line

Checking the battery status through GUI is easy. Hovering the mouse cursor over the battery indicator given in the Laptop task bar simply shows the battery level. But, did you know you can find the battery status through the Linux command line as well?

Yes, there are some utilities in Linux that can be of help in this regard.

This article explains 4 different methods of checking laptop battery status using the Linux command line. So,

Why Do You Need to Check Battery Status?

So, why do you need to check the battery status? Knowing laptop battery health on a monthly basis is a good practice. It’ll inform you about any issues your computer might have related to charging or battery life. You can get alerted earlier and take the measures required, such as charging or altering batteries.

When your PC is not active, the power management feature levels down its components to a low-power state. And also turns off the power.

Similarly, knowing the power source, battery model name, the technology used, vendors, etc helps operate your devices better and keep work going without any hassles.

How to Check Battery Status Using Linux Command Line

Follow the methods mentioned below to check battery status using the Linux command line. Check Battery Status with “upower” CommandThe command produces output

Check Battery Status with upower Command

The upower command-line tool helps extract information related to the power source (batteries). It provides an interface to list down all the power sources of your PC or laptop.

Options Used with the upower Command

  • –monitor: You can print a line each time a battery or power source is added by connecting –monitor to upower. It also produces outputs while the power sources are removed or changed.
  • –monitor-detail: This option prints the full power source detail whenever an event occurs.
upower -i /org/freedesktop/UPower/devices/battery_BAT0 upower -i `upower -e | grep 'BAT'` upower -i $(upower -e | grep BAT) | grep --color=never -E "state|to\ full|to\ empty|percentage"

The above are three different ways of using acpi command to find power source information.

Читайте также:  Linux find distribution version

Use cat and find

The “cat” and “find” commands also help find details about your battery and power source.

For the battery capacity, the syntax would be:

cat /sys/class/power_supply/BAT0/capacity

For more detailed battery information use the find command.

find /sys/class/power_supply/BAT0/ -type f | xargs -tn1 cat

Check Battery Status with acpi Command

The acpi command extracts information from the /sys or the /proc filesystem. You get to know the battery status and thermal information using acpi.

Options Used with the acpi Command

  • -b: The shortened form of –battery and it gives battery details.
  • -t: The shortened form of –thermal and shows thermal details.
  • -a: The shortened form of –ac-adapter to give ac adapter details.
  • -c: The abbreviation of –cooling. It gives information regarding your cooling device.
  • -V: Stands for –everything. It produces output about every device connected and overrides other options.
  • -f: The abbreviation of –fahrenheit. Once given as input, -f produces temperature results in fahrenheit units instead of celsius.
  • -i: The abbreviation of –details. It shows additional battery details, such as battery capacity or temperature trip points.
  • -s: The short form of –show-empty. It shows non-operational devices.

Above we have given two different acpi examples.

Use batstat Program

The batstat is a ncurses-based CLI utility. It displays the laptop battery status in Linux. Using batstat you’ll get full charge energy, current energy, level of the battery, battery level history, and the time passed from the beginning of the program. It doesn’t count the sleep time of your machine.

Steps to View Your Battery Status with batstat

Step 1: Install batstat in your machine by:

git clone https://github.com/Juve45/batstat.git

Git cone helps clone the latest version of batstat available. And it’ll create a folder named “batstat” to save all the contents.

Step 2: Then change the current directory to batstat/bin/ directory typing:

Step 3: Bring batstat binary file copied to the PATH, for instance, /usr/local/bin/

sudo cp batstat /usr/local/bin/

Step 4: Make the file executable using:

sudo chmod +x /usr/local/bin/batstat

Step 5: View the battery status through:

The Conclusion

We have reached the ending of our article. If you’re here until now, then you have probably understood how to check battery status using the Linux command line. The above methods work as expected in order to find out your battery information. So, go ahead and do some experiments on your batteries today using Linux.

Suparna is a freelance writer who writes about Linux including tips, tricks, and how-tos.

Источник

How to Check Your Laptop’s Battery Health in Linux

Think your laptop battery is running down quicker than it should? Here’s how to check Linux laptop battery health.

Читайте также:  Install git for linux

analyzing battery health on linux

Readers like you help support MUO. When you make a purchase using links on our site, we may earn an affiliate commission. Read More.

Does your laptop battery come with a «Help, I’m sick» indicator? Most likely, the answer is «No». Since that’s the case for everyone, regularly checking if your laptop needs a battery replacement is an important task.

Luckily, Linux has all kinds of utilities for checking the status and health of your device’s battery. Since most of them are terminal-based, an average user might find it hard to decode the information provided by such utilities.

Don’t worry. By the end, you will have a good understanding of laptop batteries and how to check battery health on Linux, using both graphical and command-line tools.

Battery Cycles and Design Capacity

First, you need to understand which factors play the most important role in calculating the health of a battery. Every battery has a limited amount of energy that it can store, measured in mAh, or milliamp hour. Batteries are manufactured with a specific energy limit, also known as their design capacity.

A battery cycle is a unit used by manufacturers to denote the life of a battery. When you use your laptop and the battery drains from 100% to 0%, it is counted as one battery cycle. The numbers don’t always have to be 100 and a zero, though. You can discharge your battery from 100% to 75% four times, and that would count as a single battery cycle.

battery cycles and design capacity

Over time, as the battery gets old and the amount of battery cycles increases, the design capacity of the battery degrades. This means that if you own a battery with a design capacity of 40,000 mAh and 100 battery cycles, the current energy capacity of the battery would be somewhere around 35,000 mAh (informed guess).

Therefore, if the difference between the design capacity and current capacity is very little, you can conclude that your battery is healthy. On the contrary, a battery whose current capacity is significantly less than the design capacity needs to be replaced.

Check Your Laptop’s Battery Life Using the Terminal

On Linux, several utilities provide information associated with your laptop’s battery. You can try any of the following methods to get a rough estimate of battery health.

The upower Command

If you’re using Linux, the simplest way to get battery-related statistics is using the upower command. You can use this utility to list down all the power sources available and manage the overall power management on your system.

To display a list of all the available power sources, type:

Источник

Оцените статью
Adblock
detector