Skip to content

Instantly share code, notes, and snippets.

@mstolin
Created July 24, 2022 14:03
Show Gist options
  • Save mstolin/e9441b228eff06b41d99e98c7d7957ad to your computer and use it in GitHub Desktop.
Save mstolin/e9441b228eff06b41d99e98c7d7957ad to your computer and use it in GitHub Desktop.
CloudFree Plug Power Consumption monitor
Time Total Today Power Voltage Current
2022-07-24T15:03:02 0.037 0.037 40 227 0.282
2022-07-24T15:03:07 0.037 0.037 39 227 0.282
2022-07-24T15:03:12 0.037 0.037 38 227 0.283
#!/bin/sh
if [ "$#" -eq 0 ]; then
echo "Usage: observe.sh <ip> [interval] [runtime]"
exit 1
fi
ip="${1}" # ip of the tasmota device
url="http://${ip}/cm?cmnd=status%2010" # api url
interval="${2:-5}" # in seconds
runtime="${3:-30} second" # how long, in seconds
endtime=$(date -ud "$runtime" +%s)
header="Time, Total, Today, Power, Voltage, Current"
data=""
while [[ $(date -u +%s) -le $endtime ]]; do
sleep $interval
resp=$(curl -s ${url} | jq -r '.StatusSNS | [.Time, .ENERGY.Total, .ENERGY.Today, .ENERGY.Power, .ENERGY.Voltage, .ENERGY.Current] | @csv')
data="${data}\n${resp}"
done <<< $data
echo -e "${header}${data}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment