From 0b6e2a2fb23c852bd876b32071cf4a3fb201169d Mon Sep 17 00:00:00 2001 From: pants Date: Sat, 26 Sep 2026 13:27:41 -0700 Subject: optimize and improve --- bin/st-power | 55 ++++++++++++++++++++----------------------------------- 1 file changed, 20 insertions(+), 35 deletions(-) (limited to 'bin/st-power') diff --git a/bin/st-power b/bin/st-power index e3fe69a..ebed025 100755 --- a/bin/st-power +++ b/bin/st-power @@ -1,8 +1,8 @@ #!/bin/sh -# for UPS monitoring with NUT +# for UPS monitoring with NUT, and AMD GPU power querying through lm_sensors (09-26-2026) # -#DATA_CMD="upsc ups@localhost" +DATA_CMD="upsc ups@localhost" # on debian and freebsd, ups.realpower is not available. # calculate load in watts with load percent and max output instead. @@ -10,45 +10,30 @@ #LOAD_VALUE=$($DATA_CMD | grep ups.load: | awk '{print $2}') #LOAD_PERCENT=$(echo "scale=2; $LOAD_VALUE/100" | bc) #POWER=$(echo "scale=0; $LOAD_PERCENT*$MAX_OUTPUT" | bc) +UPS_POWER="$($DATA_CMD | grep ups.realpower: | awk '{print $2}')W" -# on void, ups.realpower is available! -#POWER="$($DATA_CMD | grep ups.realpower: | awk '{print $2}') W" - -# "round" to integer. just removes decimal and whatevers after. not necessary with ups.realpower. +# "round" to integer. just removes decimal and whatevers after. #POWER="${POWER%.*} W" -#CHARGE="$($DATA_CMD | grep battery.charge: | awk '{print $2}')%" +UPS_CHARGE="$($DATA_CMD | grep battery.charge: | awk '{print $2}')%" -#if [ "$CHARGE" = "100%" ]; then -# echo $POWER -#else -# echo "$CHARGE $POWER" -#fi +GPU_POWER="$(sensors | grep "PPT" | awk '{print $2}' | sed 's/\.00//g')W" -# for battery monitoring everywhere else -# -# if power_now is present, just divide it to watts. -# (from micro watts on thinkpads, perhaps something else on other platforms) -if test -f /sys/class/power_supply/BAT*/power_now; then - POWER=$(cat /sys/class/power_supply/BAT*/power_now) - POWER="$(echo "scale=2; $POWER/1000000" | bc)W" +if [ "$UPS_CHARGE" = "100%" ]; then + echo "UPS: $UPS_POWER GPU: $GPU_POWER" else -# if power_now is not present, calculate it: - VOLTAGE=$(cat /sys/class/power_supply/BAT*/voltage_now) - CURRENT=$(cat /sys/class/power_supply/BAT*/current_now) - POWER="$(echo "scale=2; $VOLTAGE*$CURRENT/1000000000000" | bc)W" + echo "UPS: $UPS_CHARGE $UPS_POWER GPU: $GPU_POWER" fi -STATUS=$(cat /sys/class/power_supply/BAT*/status) - -#case "$STATUS" in -# "Charging") -# STATUS="+";; -# "Discharging") -# STATUS="-";; -# "Not Charging") -# STATUS="...";; -#esac +# for battery monitoring everywhere else +# +# if power_now is not present, calculate it: +#VOLTAGE=$(cat /sys/class/power_supply/BAT*/voltage_now) +#CURRENT=$(cat /sys/class/power_supply/BAT*/current_now) +#POWER=$(echo "scale=2; $VOLTAGE*$CURRENT/1000000000000" | bc) -CHARGE="$(cat /sys/class/power_supply/BAT*/capacity)%" +# if it is present, just divide it to watts (from micro watts on thinkpads, perhaps something else on other platforms) +#POWER=$(cat /sys/class/power_supply/BAT*/power_now) +#POWER="$(echo "scale=2; $POWER/1000000" | bc)W" +#CHARGE="$(cat /sys/class/power_supply/BAT*/capacity)%" -echo "$CHARGE $POWER $STATUS" +#echo "$CHARGE $POWER" -- cgit v1.2.3