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

Linux

66367 readers
467 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?

you are viewing a single comment's thread
view the rest of the comments
[–] 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.