Would it not be nice to also get an alert via UptimeKuma if power has gone down? This is an ideal case for a passive (push) monitor that would go from your RPi to regularly report the state.
- On your UptimeKuma instance:
- Click the “Add New Monitor” button.
- Fill out the form:
- Monitor Type: Select “Push”.
- Friendly Name:
UPS Battery Status - Heartbeat Interval:
70(This means if the Pi fails to check in for 70 seconds, the monitor will go “Down”). - After you select “Push,” Uptime Kuma will generate a Push URL. It will look something like this:
http://A.B.C.D:3001/api/push/LzGjP4k9q - Copy this URL up to the code (not the part after ?).
- Keep it open and save it once the crontab job (later on) is set up.
- On your RPI:
sudo -i
nano /usr/local/sbin/push_ups_to_kuma.sh
#!/bin/bash
# --- CONFIGURATION ---
PUSH_URL="<http://A.B.C.D:3001/api/push/CODE>"
#PUSH_URL="<http://192.168.8.60:3001/api/push/nXndhcQRH7ohAw9Ip9nOP3BMk9kcf2zr>"
# Full paths for all commands (cron-safe)
APCACCESS_CMD="/usr/sbin/apcaccess"
GREP_CMD="/usr/bin/grep"
AWK_CMD="/usr/bin/awk"
CURL_CMD="/usr/bin/curl"
# Get the raw status text (e.g., "ONLINE" or "ONBATT")
STATUS_MSG=$($APCACCESS_CMD | $GREP_CMD "STATUS" | $AWK_CMD '{print $3}')
# Get the battery value (per your UPS model)
BATT_VAL=$($APCACCESS_CMD | $GREP_CMD "BCHARGE" | $AWK_CMD '{print $3}')
# Set as 'up' only if battery is 'ONLINE'
KUMA_STATUS="up"
if [ "$STATUS_MSG" != "ONLINE" ]; then
KUMA_STATUS="down"
fi
echo "Sending to Kuma: Kuma Status=${KUMA_STATUS}, UPS Status=${STATUS_MSG}, Battery=${BATT_VAL}%"
# Send the data to Uptime Kuma
$CURL_CMD \\
--get \\
--data-urlencode "status=${KUMA_STATUS}" \\
--data-urlencode "msg=${STATUS_MSG}, battery at ${BATT_VAL}%." \\
"$PUSH_URL"
- Make the script executable:
chmod +x /usr/local/sbin/push_ups_to_kuma.sh
- Add it to crontab to run every minute:
crontab -e # Send UPS status to Uptime Kuma every minute * * * * * /usr/local/sbin/push_ups_to_kuma.sh >/dev/null 2>&1
- Ensure the UptimeKuma monitor is saved and watch the magic happen 😇
Ok, we are ready for a battery test at last – let’s see what happens when we unplug the power!


