this post was submitted on 19 May 2026
25 points (100.0% liked)

Linux

66302 readers
197 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 7 years ago
MODERATORS
 

The battery tray indicators I've tried on Linux so far only seem to take the instantaneous power consumption into account. Is there one that estimates remaining battery life based on power draw over a longer time window and integrates easily with my desktop environment's tray?

top 10 comments
sorted by: hot top controversial new old
[–] Wfh@lemmy.zip 6 points 1 month ago

Most of them are just a frontend for upower anyway.

[–] whatiswrongwithyou@lemmy.ml 2 points 1 month ago (1 children)

What is your desktop environment?

[–] monovergent@lemmy.ml 1 points 1 month ago (1 children)
[–] eldavi@lemmy.ml 1 points 1 month ago (1 children)

is the behavior the same in any other xwindows environment?

[–] monovergent@lemmy.ml 1 points 1 month ago (1 children)
[–] eldavi@lemmy.ml 1 points 1 month ago (1 children)

this would be a useful troubleshooting step and, since you're already using xfce, you should be able to easily and temporarily switch your display manger to switch to something like gnome to check.

if gnome shows battery correctly; then you know that it's xfce and then you have you answer.

[–] monovergent@lemmy.ml 2 points 1 month ago* (last edited 1 month ago)

Not going after a bug though, it's just the way the included battery meter in Xfce (and other X11 battery indicators I've found) works, while things like Android track usage over time to give a better estimate.

But based on the other responses, it looks like I'll have to cook it up myself.

[–] MonkderVierte@lemmy.zip 1 points 1 month ago* (last edited 1 month ago)

I mean, you can take x samples in y time and average them, but what else?

About that, maybe script it and then display the data in Verve plugin? I've created one a while back but currently don't use the laptop much, so a bug with calculating the remaining time remains. But it might serve as a start.

#!/bin/sh
#
# pretty-print battery-info and time on shell
# last change: 09.01.2024

battery_path=/sys/class/power_supply/BAT0
timeout1=10
timeout2=5

error() { printf '%s:\t%s\n' "error" "$1" >&2; [ -n "$2" ] && exit "$2"; }   # complain to STDERR and exit if given code

[ -d "$battery_path" ] || error "Device has no battery" 1

# while true; do
# 🔌🔌
# reading uevent line for line, because f** idiots and whitespaces in int of voltage
while read line; do
	IFS='='
	set -- $line
	case "$1" in
		"POWER_SUPPLY_NAME")                bat_name="$2"
	;;	"POWER_SUPPLY_STATUS")              bat_state="$2"
	;;	"POWER_SUPPLY_TYPE")                bat_type="$2" # = Battery
	;;	"POWER_SUPPLY_CAPACITY_LEVEL")      bat_warn="$2"
	;;	"POWER_SUPPLY_CAPACITY")            bat_perc="$2"
	;;	"POWER_SUPPLY_ENERGY_NOW")          bat_chrg=$(($2 / 1000))
	;;	"POWER_SUPPLY_ENERGY_FULL")         bat_full=$(($2 / 1000))
	;;	"POWER_SUPPLY_ENERGY_FULL_DESIGN")  bat_chrg_des=$(($2 / 1000))
	;;	"POWER_SUPPLY_VOLTAGE_NOW")         bat_volt=$(($2 / 1000))
	;; esac
done < "$battery_path"/uevent

tt_empty=$(((bat_full - bat_now) / bat_volt)) # TODO
tt_full=$(((bat_full + bat_now) / bat_volt)) # TODO
bat_ttef="${tt_empty:-"$tt_full"}h"
# printf 'tt_empty: %s\n' "$tt_empty"


fgcol="$(tput setaf 2)" # green
reset="$(tput sgr0)"
symbol="🔋"

# conditionals
if [ "$bat_state" = "Discharging" ]; then
	fgcol="$(tput setaf 1)" # red
	symbol="🪫"
fi
if [ "$bat_warn" != "Normal" ]; then
	fgcol="$(tput setaf 1)" # red
	symbol="⚠"
	envwarn "Battery ${bat_name}: ${bat_warn}"
fi

# override bat_ttef only every 2nd time
# if $flipflop; then
	string="${fgcol}${bat_perc}%${reset}/${bat_ttef}"
# 	sleep $timeout1
# 	flipflop=false
# else
# 	symbol="🕑"
# 	string=" $(date +%R)"
# 	sleep $timeout2
# 	flipflop=true
# fi

_time="$(date +%R)"

tput sc # save cursor position
tput cup 0 $(($(tput cols)-20)) # set cursor position
printf "%s %s / %s 🕑\n" "$string" "$symbol" "$_time"
tput rc # reset cursor position

# done

Edit: ah, envwarn is a little utility of me, that puts errors in a statefile, which gets echoed on every shell load.

[–] Sunsofold@lemmings.world 0 points 1 month ago (1 children)

I never thought about it much but how hard would it be to add PID to your power info?

[–] monovergent@lemmy.ml 2 points 1 month ago

I think I could hack such a feature into the tray indicator as a weekend project, but wanted to see if someone already accomplished it before I go reinventing the wheel.