summaryrefslogtreecommitdiff
path: root/bin/st-power
diff options
context:
space:
mode:
authorpants <niklasjo2004@gmail.com>2026-09-21 14:17:03 -0700
committerpants <niklasjo2004@gmail.com>2026-09-21 14:17:03 -0700
commit7b21727285e50b0b050c4ddd70d07542229c5366 (patch)
tree5d369153c5df5b41f3750d25479a68f20169c8ff /bin/st-power
init
Diffstat (limited to 'bin/st-power')
-rwxr-xr-xbin/st-power54
1 files changed, 54 insertions, 0 deletions
diff --git a/bin/st-power b/bin/st-power
new file mode 100755
index 0000000..e3fe69a
--- /dev/null
+++ b/bin/st-power
@@ -0,0 +1,54 @@
+#!/bin/sh
+
+# for UPS monitoring with NUT
+#
+#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.
+#MAX_OUTPUT=$($DATA_CMD | grep ups.realpower.nominal: | awk '{print $2}')
+#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)
+
+# 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.
+#POWER="${POWER%.*} W"
+#CHARGE="$($DATA_CMD | grep battery.charge: | awk '{print $2}')%"
+
+#if [ "$CHARGE" = "100%" ]; then
+# echo $POWER
+#else
+# echo "$CHARGE $POWER"
+#fi
+
+# 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:
+ 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"
+fi
+
+STATUS=$(cat /sys/class/power_supply/BAT*/status)
+
+#case "$STATUS" in
+# "Charging")
+# STATUS="+";;
+# "Discharging")
+# STATUS="-";;
+# "Not Charging")
+# STATUS="...";;
+#esac
+
+CHARGE="$(cat /sys/class/power_supply/BAT*/capacity)%"
+
+echo "$CHARGE $POWER $STATUS"