startup.sh script I use for looping the main script in the background:
Code: Select all
# Start upsmonitor
/usr/bin/screen -S upsmonitor -d -m /root/ups/updatedomoticz.sh
Code: Select all
#!/bin/bash
while true; do
# Check if UPS is connected
state=$(/usr/sbin/pwrstat -status | grep 'State' | awk '{print $2}')
if [ "$state" != "Lost" ]; then
# Mains Voltage
mainsvoltage=$(/usr/sbin/pwrstat -status | grep 'Utility Voltage' | awk '{print $3}')
curl -s "http://USERNAME:[email protected]/json.htm?type=command¶m=udevice&idx=316&svalue=${mainsvoltage}"
# Load in Watts
loadwatts=$(/usr/sbin/pwrstat -status | grep 'Load' | awk '{print $2}')
curl -s "http://USERNAME:[email protected]/json.htm?type=command¶m=udevice&idx=318&svalue=${loadwatts}"
# Remaining Runtime
remainingruntime=$(/usr/sbin/pwrstat -status | grep 'Remaining Runtime' | awk '{print $3}')
curl -s "http://USERNAME:[email protected]/json.htm?type=command¶m=udevice&idx=319&svalue=${remainingruntime}"
else
echo "Communication with UPS lost, attempting reconnection..."
service pwrstatd stop
service pwrstatd start
fi
sleep 10
done