Use this guide to get the UPS daemon working on your PI
http://raspisimon.no-ip.org/ups.php
In Domoticz create your virtual devices - in my case I created four devices to monitor but if you look at the apcaccess status command there are quite a few variables if you choose to add
Line voltage
Temperature
Load
and finally on battery or not
Here is the bash script - you will need to change the idx numbers to align to your devices
I called my readapc.sh in /home/pi/domoticz/scripts
Code: Select all
#!/bin/bash
#Script to grab APC status and update domoticz vars
SERVER='localhost:8080/'
SERVER_CMD='json.htm?type=command¶m=udevice&'
SWITCH_CMD='json.htm?type=command¶m=switchlight&'
cap_data=`apcaccess status`
#apc_total = "apcaccess status"
#echo "$cap_data"
apc_stat=`awk '/STATUS / {print $3}' <<< "$cap_data"`
apc_volts=`awk '/LINEV / {print $3}' <<< "$cap_data"`
apc_itemp=`awk '/ITEMP / {print $3}' <<< "$cap_data"`
apc_load=`awk '/LOADPCT / {print $3}' <<< "$cap_data"`
#echo $apc_stat
#echo $apc_volts
#echo $apc_itemp
#echo $apc_load
hostcmd="http://${SERVER}${SERVER_CMD}idx=25&nvalue=0&svalue=${apc_itemp}"
curlres=`curl -sS $hostcmd`
hostcmd="http://${SERVER}${SERVER_CMD}idx=26&nvalue=0&svalue=${apc_volts}"
curlres=`curl -sS $hostcmd`
hostcmd="http://${SERVER}${SERVER_CMD}idx=34&nvalue=0&svalue=${apc_load}"
curlres=`curl -sS $hostcmd`
if [ "$apc_stat" = "ONLINE" ]; then
#echo "APC SYSTEM IS ONLINE"
hostcmd="http://${SERVER}${SWITCH_CMD}idx=36&switchcmd=On&level=0"
curlres=`curl -sS $hostcmd`
else
#echo "APC SYSTEM IS OFFLINE"
hostcmd="http://${SERVER}${SWITCH_CMD}idx=36&switchcmd=Off&level=0"
curlres=`curl -sS $hostcmd`
fi
chmod +x readapc.sh
test the script to make sure the vars are updating
./readapc.sh
add a cron to run it every minute
crontab -e
add the following to the end of the file
* * * * * sudo ~/domoticz/scripts/readapc.sh
Enjoy ...
Modbreak: i added
Code: Select all
tags to improve readability (ThinkPad)[/b][/color]