Skip to content

Instantly share code, notes, and snippets.

@tserong
Last active April 27, 2022 06:22
Show Gist options
  • Save tserong/6e4167c3b02387acc199a158cc95fafe to your computer and use it in GitHub Desktop.
Save tserong/6e4167c3b02387acc199a158cc95fafe to your computer and use it in GitHub Desktop.
Log ZCell state of charge
#!/bin/bash
#
# Polls the ZCell BMS REST API once per minute and prints the
# current state of charge. Runs indefinitely.
# Requires `curl` and `jq`.
#
# Note: this only looks at the first battery in the system
# (".list[0]" in the `jq` invocation).
#
if [ -z "$1" ]; then
echo "Usage: $(basename $0) BMS_IP [POLL_INTERVAL]"
exit 1
fi
STATUS_URL="http://${1}:3000/rest/1.0/status"
INTERVAL="${2:-60}"
LAST=""
echo "Polling ${STATUS_URL} at ${INTERVAL} second intervals"
while true ; do
curl -s ${STATUS_URL} | jq -r '.list[0].state_of_charge'
sleep $INTERVAL
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment