Last active
April 27, 2022 06:21
-
-
Save tserong/7c38a777aaecbcd2c13dd08928978eb6 to your computer and use it in GitHub Desktop.
Log ZCell contactor state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Polls the ZCell BMS REST API once per second and prints the | |
# state of the Charge, Discharge and Energy Extrator (Strip) | |
# contactors if they've changed since the last poll. Will | |
# run forever, or until all three contactors are open at the | |
# same time, whichever comes first. | |
# 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:-1}" | |
LAST="" | |
echo "Polling ${STATUS_URL} at ${INTERVAL} second intervals" | |
while true ; do | |
CONTACTORS="$(curl -s ${STATUS_URL} | jq -r '[(if .list[0].charge_contactor_state then "C" else "_" end), (if .list[0].discharge_contactor_state then "D" else "_" end), (if .list[0].strip_contactor_state then "E" else "_" end)] | join(" ")')" | |
if [ "$CONTACTORS" != "$LAST" ] ; then | |
echo -e "$(date --iso-8601=seconds)\t${CONTACTORS}" | |
LAST="${CONTACTORS}" | |
fi | |
if [ "$CONTACTORS" = "_ _ _" ] ; then | |
echo "All contactors open, exiting" | |
break | |
fi | |
sleep $INTERVAL | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment