HS 500 APC Ups to domoticz

Last Updated or created 2023-03-03

A friend of mine wanted to monitor his UPS using domoticz.
This UPS only had a simple web interface with information.

So we needed to scrape this information and push this into domoticz.

First create a dummy device in domoticz and note its IDX.

Then we can scrape needed information using below script.

#!/bin/bash
#set -x
# Domoticz server
SERVER="127.0.0.1:8080"

# APC Back-UPS HS 500 status URL
UPS="http://IP-OF-UPS/status.cgi"

# The number of the IDX in the list of peripherals
IDX="362"

# Path for temporary file (RAM drive)
TMPFILE="/tmp/apc-hs500-status.txt"

# Get APC Back-UPS HS 500 status and write to temporary file
wget $UPS -O $TMPFILE 2>/dev/null
if [ $? = 0 ]
then
PWR=$(cat $TMPFILE| tr -dc '[[:print:]]' |awk -F"Watts" '{print $1}' |rev |cut -f1 -d\> |rev |cut -f1 -d\&)
fi

if [ $PWR ]
then
echo "Load on Battery in Watts: $PWR"
# Send data to Domoticz
curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=udevice&idx=$IDX&nvalue=0&svalue=$PWR"
PWR=""
fi
rm $TMPFILE
Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *