update to test for power_now

This commit is contained in:
2026-03-05 22:11:36 -08:00
parent 6826688d9d
commit d48c568f7a

View File

@@ -2,7 +2,7 @@
# for UPS monitoring with NUT # for UPS monitoring with NUT
# #
DATA_CMD="upsc ups@localhost" #DATA_CMD="upsc ups@localhost"
# on debian and freebsd, ups.realpower is not available. # on debian and freebsd, ups.realpower is not available.
# calculate load in watts with load percent and max output instead. # calculate load in watts with load percent and max output instead.
@@ -12,28 +12,33 @@ DATA_CMD="upsc ups@localhost"
#POWER=$(echo "scale=0; $LOAD_PERCENT*$MAX_OUTPUT" | bc) #POWER=$(echo "scale=0; $LOAD_PERCENT*$MAX_OUTPUT" | bc)
# on void, ups.realpower is available! # on void, ups.realpower is available!
POWER="$($DATA_CMD | grep ups.realpower: | awk '{print $2}') W" #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. not necessary with ups.realpower.
#POWER="${POWER%.*} W" #POWER="${POWER%.*} W"
CHARGE="$($DATA_CMD | grep battery.charge: | awk '{print $2}')%" #CHARGE="$($DATA_CMD | grep battery.charge: | awk '{print $2}')%"
if [ "$CHARGE" = "100%" ]; then #if [ "$CHARGE" = "100%" ]; then
echo $POWER # echo $POWER
else #else
echo "$CHARGE $POWER" # echo "$CHARGE $POWER"
fi #fi
# for battery monitoring everywhere else # 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"
else
# if power_now is not present, calculate it: # if power_now is not present, calculate it:
#VOLTAGE=$(cat /sys/class/power_supply/BAT*/voltage_now) VOLTAGE=$(cat /sys/class/power_supply/BAT*/voltage_now)
#CURRENT=$(cat /sys/class/power_supply/BAT*/current_now) CURRENT=$(cat /sys/class/power_supply/BAT*/current_now)
#POWER=$(echo "scale=2; $VOLTAGE*$CURRENT/1000000000000" | bc) POWER="$(echo "scale=2; $VOLTAGE*$CURRENT/1000000000000" | bc)W"
fi
# 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" CHARGE="$(cat /sys/class/power_supply/BAT*/capacity)%"
echo "$CHARGE $POWER"