Checking the battery in terminal mode?

How can you check the battery level in no-desktop mode? This is with the default Raspbian installed. I tried looking it up more generally and couldn’t find a command that worked. Could it be hardware-specific?

Might be able to with upower

@Dzaczek does it like this in his i3 scripts : https://github.com/dzaczek/Uconsole-i3/blob/master/scripts/rpibat.sh

Works for me in a terminal :slight_smile:

2 Likes

Thank you so much!

For anyone else who wants to use this, here’s what I did to that script to make it work nicely in the terminal:

Replace the unicode characters with ascii art:

ICON_CHARGING="[>>>}"
ICON_DISCHARGING="[<<<}"

And then I added an alias in my .bashrc so that I could easily run it:

alias batt=(path to script)

Don’t forget to make it runnable with chmod +x (path to script) and restart the shell (running bash will do the trick) to get it to work!

> batt
[>>>} 100%
#!/usr/bin/python3

# The file representing battery capacity
BATT_CURR_PATH = '/sys/class/power_supply/axp20x-battery/capacity'

# Open read format
with open(BATT_CURR_PATH, 'r') as f:
    battper = int(f.read())

# STDOUT
print(battper)

you can also just cat /sys/class/power_supply/axp20x-battery/capacity

I often have btop running in some tmux session already, so I use that.

cat /sys/class/power_supply/axp20x-battery/capacity for when you aren’t there.