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?

          • eldavi@lemmy.ml
            link
            fedilink
            English
            arrow-up
            1
            ·
            7 days ago

            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.mlOP
              link
              fedilink
              arrow-up
              1
              ·
              edit-2
              7 days 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
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    7 days 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.

    • monovergent@lemmy.mlOP
      link
      fedilink
      arrow-up
      2
      ·
      8 days 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.