APC UPS Monitoring

All kinds of 'OS' scripts

Moderator: leecollings

Kruu
Posts: 49
Joined: Tuesday 17 January 2017 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: APC UPS Monitoring

Post by Kruu »

I am getting communication lost often. Can I do something about it?

2017-11-14 17:35:16 +0100 Communications with UPS lost.
assenzuid
Posts: 135
Joined: Friday 13 November 2015 9:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands, Emmen Area
Contact:

Re: APC UPS Monitoring

Post by assenzuid »

Rene wrote: Tuesday 13 January 2015 2:56 I made one too, this one is in Python script for whoever wants it, now with auto shutdown when battery power is down to 10%

Code: Select all

#!/usr/bin/python 
#
#		Script to read APC battery backups settings and voltages.
#   	And publish these to domoticz software.
#
#		(C)reated by Rtm-soft Jan 2015
#	
#		This code is Free Software and comes with absolutely
#		no warranty and may freely be modified and distributed.


#Modules used in this program

import subprocess	#For OS calls
import time
import requests		#For URL calls

#Install APC driver with:
#
#Read https://help.ubuntu.com/community/apcupsd or follow below lines
#
#Quick Install for USB-based APC units
#    install the daemon: apt-get install apcupsd
#    edit /etc/apcupsd/apcupsd.conf and change these lines
#        UPSNAME myownups
#        UPSCABLE usb
#        UPSTYPE usb
#        comment out DEVICE (it contains a TTY link, which will prevent it from working) 
#    edit /etc/default/apcupsd
#        change ISCONFIGURED from no to yes 
#    /etc/init.d/apcupsd start
#    apcaccess 

#Shutdown access to user without password:
#
#sudo visudo -f /etc/sudoers.d/myOverrides 
#
#<myusername>    ALL = NOPASSWD: /sbin/shutdown


#Constants (Modify these to match your own settings)

DOMOTICZ_URL = "http://localhost:8080"	#http://<username:password@>domoticz-ip<:port>
APCACCESS	= "/sbin/apcaccess"			#Location of apcaccess program
LINEV		= "40"							#Idx for Line Voltage
BATTV		= "44"							#Idx for Battery Voltage
LOADPCT		= "45"							#Idx for Load Percentage
BCHARGE		= "46"							#Idx for Battery Charge
MINBATT		= 10							#Shut down when battery power is at 10%

#Variables

def apc_probe() :
	batt = 100	#Needs to be >MINBATT to not do a false processor stop
	dict = {'LINEV' : LINEV, 'BATTV' : BATTV, 'LOADPCT' : LOADPCT, 'BCHARGE' : BCHARGE } #Convert Keyword to Domoticz index.
	while True :						#Endless loop
		res = subprocess.check_output(APCACCESS) 
		for line in res.split('\n') :
			(key,spl,val) = line.partition(': ')
			key = key.rstrip()			#Strip spaces right of text
			val = val.strip()			#Remove outside spaces
			if key == 'STATUS' and 'ONBATT' in val and batt < MINBATT : #If there is less then 10 percent battery power left and we are offline then shutdown
				subprocess.call("sudo shutdown -h now", shell=True)	#Edit /etc/sudoers.d/myOverrides to make shutdown without password work
			val = val.split(' ',1)[0] 	#Split using space and only take first part
			if key in dict : 			#Are we interested in this parameter?
				if key == 'BCHARGE' :
					batt = int(float(val))		#Save battery level for Offline mode.
				url= DOMOTICZ_URL+"/json.htm?type=command&param=udevice&idx="+dict[key]+"&nvalue=0&svalue="+val #Publish value to Domoitcz by means of json.
				requests.get(url)		#Print url
		time.sleep(60) #Take a minute break

#Main Loop
print "APC Probe running..."
apc_probe()					
Is there a way to see in an log file if it shutdowns the PI is batt. status is 10 min?
ausonius
Posts: 1
Joined: Monday 08 October 2018 12:53
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: APC UPS Monitoring

Post by ausonius »

Hello everyone

In relation to the script below I can not figure out where it is inserted? in the installation directory domoticz script? under what name?

excuse me for my english


assenzuid wrote: Saturday 21 October 2017 22:46
Rene wrote: Tuesday 13 January 2015 2:56 I made one too, this one is in Python script for whoever wants it, now with auto shutdown when battery power is down to 10%

Code: Select all

#!/usr/bin/python 
#
#		Script to read APC battery backups settings and voltages.
#   	And publish these to domoticz software.
#
#		(C)reated by Rtm-soft Jan 2015
#	
#		This code is Free Software and comes with absolutely
#		no warranty and may freely be modified and distributed.


#Modules used in this program

import subprocess	#For OS calls
import time
import requests		#For URL calls

#Install APC driver with:
#
#Read https://help.ubuntu.com/community/apcupsd or follow below lines
#
#Quick Install for USB-based APC units
#    install the daemon: apt-get install apcupsd
#    edit /etc/apcupsd/apcupsd.conf and change these lines
#        UPSNAME myownups
#        UPSCABLE usb
#        UPSTYPE usb
#        comment out DEVICE (it contains a TTY link, which will prevent it from working) 
#    edit /etc/default/apcupsd
#        change ISCONFIGURED from no to yes 
#    /etc/init.d/apcupsd start
#    apcaccess 

#Shutdown access to user without password:
#
#sudo visudo -f /etc/sudoers.d/myOverrides 
#
#<myusername>    ALL = NOPASSWD: /sbin/shutdown


#Constants (Modify these to match your own settings)

DOMOTICZ_URL = "http://localhost:8080"	#http://<username:password@>domoticz-ip<:port>
APCACCESS	= "/sbin/apcaccess"			#Location of apcaccess program
LINEV		= "40"							#Idx for Line Voltage
BATTV		= "44"							#Idx for Battery Voltage
LOADPCT		= "45"							#Idx for Load Percentage
BCHARGE		= "46"							#Idx for Battery Charge
MINBATT		= 10							#Shut down when battery power is at 10%

#Variables

def apc_probe() :
	batt = 100	#Needs to be >MINBATT to not do a false processor stop
	dict = {'LINEV' : LINEV, 'BATTV' : BATTV, 'LOADPCT' : LOADPCT, 'BCHARGE' : BCHARGE } #Convert Keyword to Domoticz index.
	while True :						#Endless loop
		res = subprocess.check_output(APCACCESS) 
		for line in res.split('\n') :
			(key,spl,val) = line.partition(': ')
			key = key.rstrip()			#Strip spaces right of text
			val = val.strip()			#Remove outside spaces
			if key == 'STATUS' and 'ONBATT' in val and batt < MINBATT : #If there is less then 10 percent battery power left and we are offline then shutdown
				subprocess.call("sudo shutdown -h now", shell=True)	#Edit /etc/sudoers.d/myOverrides to make shutdown without password work
			val = val.split(' ',1)[0] 	#Split using space and only take first part
			if key in dict : 			#Are we interested in this parameter?
				if key == 'BCHARGE' :
					batt = int(float(val))		#Save battery level for Offline mode.
				url= DOMOTICZ_URL+"/json.htm?type=command&param=udevice&idx="+dict[key]+"&nvalue=0&svalue="+val #Publish value to Domoitcz by means of json.
				requests.get(url)		#Print url
		time.sleep(60) #Take a minute break

#Main Loop
print "APC Probe running..."
apc_probe()					
I'm using this great script, but how to be sure that its running after a reboot op my PI?
NiCOOLaS
Posts: 4
Joined: Tuesday 09 October 2018 20:53
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: APC UPS Monitoring

Post by NiCOOLaS »

Hello all.

I set up monitoring of remote APC UPS SMT3000 using SNMP on the server (windows) connected to the UPS.
Here is the instruction:

On a server running an OS, for example Windows, to which UPS APC is connected, you must install / start the SNMP service. It will collect statistics on the operation of the UPS and provide information to customers.
The Domoticz management server (SNMP service client) will request information from the / UPS server for further processing.
Install / configure the SNMP service in Windows

Install/configure the SNMP service in Windows
Programs -> Programs and Components -> Windows Components (choose SNMP)
Start the service control and select the SNMP service
On the “Security” tab, add the community name “Public” with “read only” rights and select the “Receive SNMP packets from any node” option (it is possible to specify only specific addresses of clients).
On the “SNMP Agent” tab, fill in the data as you wish:
You also need to add a “trap” as in the picture, the ip address is Domoticz

image5.png

2. Install APC PowerChute
On the manufacturer's website, download the APC PowerChute suitable for your UPS
https://www.apc.com/shop/ru/ru/categori ... /N-13kn0i4
I used the version - PowerChute Business Edition v9.2, it does not support SNMP v3 and settings are easier.

During installation, the system will automatically query the ports and configure the connection to the UPS(USB), and also request a password for the UPS Web Management Interface.
After installation, you must go to the Web interface at: https://localhost:6547 . Most likely, the browser will block the transition and write that we’ll ignore the “connection is not protected” and proceed.
On the “PowerChute” tab, select “SNMP Settings” and activate “SNMPv1”

image3.png

Reboot.
The server is ready to transfer the UPS parameters, now we will configure Domoticz to read them.

Install SNMP on Raspberry Pi

Code: Select all

sudo apt-get install snmpd
sudo apt-get install snmp
Reboot the Pi

Code: Select all

sudo reboot
Run to check:

Code: Select all

snmpget -v 1 -c public -O qv IPserver 1.3.6.1.4.1.318.1.1.1.1.1.1.0
Where is the “public” community that you specified when configuring SNMP,, “IPserver ” - is the IP address of the server with UPS
We will get a response with the name:

Code: Select all

"Smart-UPS 3000"

Now creating in Domoticz 1 virtual switch and several sensors (3 for voltage, 2 for %, 1 text and 1 temperature)
The script itself is created here:
UPS_APC.sh in the /domoticz/scripts/ folder
script

#!/bin/bash

Code: Select all

# Settings
UPSIP="192.x.x.x"                   # UPS (SNMP server) IP Address
PASSWORD="public"                   # SNMP Password
DOMO_IP="192.x.x.x"                # Domoticz IP Address
DOMO_PORT="8080"                    # Domoticz Port

# Monitoring parameters
UPS_IDX="53"                                   # UPS Switch IDX (ON/OFF State)
upsAdvInputLineVoltage_IDX="50"                # APC UPS Input Voltage (V AC)
upsAdvBatteryTemperature_IDX="52"              # APC UPS Internal Temperature (C)
upsAdvBatteryCapacity_IDX="54"                 # APC UPS Battery Capacity (%)
upsAdvBatteryRunTimeRemaining_IDX="55"         # APC UPS Battery Runtime Remaining (TimeTicks)
upsAdvBatteryActualVoltage_IDX="56"            # APC UPS Battery Voltage (V DC)
upsAdvOutputLoad_IDX="57"                      # APC UPS Output Load (%) VA
upsAdvOutputVoltage_IDX="58"                   # APC UPS Output Voltage (V AC)
 
# Check if UPS in online 
PINGTIME=`ping -c 1 -q $UPSIP | awk -F"/" '{print $5}' | xargs`
echo $PINGTIME
if expr "$PINGTIME" '>' 0
then

    curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=devices&rid=$UPS_IDX" | grep "Status" | grep "On" > /dev/null
    if [ $? -eq 0 ] ; then
        echo "UPS already ON"
    else
        echo "UPS ON"
        # Send data
        curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$UPS_IDX&switchcmd=On"
    fi
    
    # UPS Input Voltage (V AC)
    UPSInVolt=`snmpget -v 1 -c $PASSWORD -O qv $UPSIP 1.3.6.1.4.1.318.1.1.1.3.2.1.0`
    # Send data
    curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$upsAdvInputLineVoltage_IDX&nvalue=0&svalue=$UPSInVolt"

    # UPS Battery Temperature 
    UPSBattemp=`snmpget -v 1 -c $PASSWORD -O qv $UPSIP 1.3.6.1.4.1.318.1.1.1.2.2.2.0`
    # Send data
    curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$upsAdvBatteryTemperature_IDX&nvalue=0&svalue=$UPSBattemp"

    # UPS Battery Capacity (%)
    UPSBatCapst=`snmpget -v 1 -c $PASSWORD -O qv $UPSIP 1.3.6.1.4.1.318.1.1.1.2.2.1.0`
    # Send data
    curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$upsAdvBatteryCapacity_IDX&nvalue=0&svalue=$UPSBatCapst"

    # UPS Battery Runtime Remaining (TimeTicks)
    UPSTimeRem=`snmpget -v 1 -c $PASSWORD -O qv $UPSIP 1.3.6.1.4.1.318.1.1.1.2.2.3.0`
    # Send data
    curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$upsAdvBatteryRunTimeRemaining_IDX&nvalue=0&svalue=$UPSTimeRem"

    # UPS Battery Voltage (V DC)
    UPSBatVolt=`snmpget -v 1 -c $PASSWORD -O qv $UPSIP 1.3.6.1.4.1.318.1.1.1.2.2.8.0`
    # Send data
    curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$upsAdvBatteryActualVoltage_IDX&nvalue=0&svalue=$UPSBatVolt"

    # UPS Output Load (%) VA
    UPSOutLoad=`snmpget -v 1 -c $PASSWORD -O qv $UPSIP 1.3.6.1.4.1.318.1.1.1.4.2.3.0`
    # Send data
    curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$upsAdvOutputLoad_IDX&nvalue=0&svalue=$UPSOutLoad"

    # UPS Output Voltage (V AC)
    UPSOutVolt=`snmpget -v 1 -c $PASSWORD -O qv $UPSIP 1.3.6.1.4.1.318.1.1.1.4.2.1.0`
    # Send data
    curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$upsAdvOutputVoltage_IDX&nvalue=0&svalue=$UPSOutVolt"


else
    
    curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=devices&rid=$UPS_IDX" | grep "Status" | grep "Off" > /dev/null
    if [ $? -eq 0 ] ; then
        echo "UPS already OFF"
    else
        echo "UPS OFF"
        # Send data
        curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$UPS_IDX&switchcmd=Off"
    fi
fi

In the script IP addresses and identifiers (№ IDX) replace with your own.
If Domoticz is password protected, you need to add 2 variables:

Code: Select all

DOMO_LOGIN="yourusername"
DOMO_PASS="yourpassword"
And change the link in the request to this view:

Code: Select all

http://$DOMO_LOGIN:$DOMO_PASS@$DOMO_IP:$DOMO_PORT 
Instead:

Code: Select all

 http://$DOMO_IP:$DOMO_PORT

Making the script executable:
In the folder with the script type:

Code: Select all

 sudo chmod +x UPS_APC.sh
Run to check:

Code: Select all

 ./UPS_APC.sh
Configure the scheduler

Code: Select all

 crontab -e
Updating once a minute:

Code: Select all

 */1 * * * * /home/pi/domoticz/scripts/UPS_APC.sh
Done!
image3.png

p.s. sorry for my english :roll:
Attachments
image2.png
image2.png (15.47 KiB) Viewed 12836 times
image3.png
image3.png (25.78 KiB) Viewed 12836 times
image3.png
image3.png (25.78 KiB) Viewed 12837 times
image5.png
image5.png (68.31 KiB) Viewed 12837 times
dzjr
Posts: 45
Joined: Monday 02 July 2018 23:35
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.100xx
Location: Alkmaar, The Netherlands
Contact:

Re: APC UPS Monitoring

Post by dzjr »

Hello everybody;

I also have an APC UPS for my domoticz server, and I manage to read the data from the UPS in domoticz.

Only I have two problems; 1; if I run the script with

Code: Select all

~/domoticz/scripts $ ./readapc.sh
, then I get as output:

Code: Select all

curl: (7) Failed to connect to 12.0 port 80: Verbinding is verlopen
this is the content of readapc.sh

Code: Select all


#!/bin/bash
#Script to grab APC status and update domoticz vars

SERVER='127.0.0.1:8080/'
SERVER_CMD='json.htm?type=command&param=udevice&'
SWITCH_CMD='json.htm?type=command&param=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_load=`awk '/LOADPCT / {print $3}' <<< "$cap_data"`
apc_bcharge=`awk '/BCHARGE / {print $3}' <<< "$cap_data"`
apc_batt=`awk '/BATTV / {print $3}' <<< "$cap_data"`



#echo $apc_stat
#echo $apc_volts
#echo $apc_load
#echo $apc_bcharge
#echo $apc_batt

hostcmd="http://${SERVER}${SERVER_CMD}idx=171&nvalue=0&svalue=${apc_volts}"
curlres=`curl -sS $hostcmd`
hostcmd="http://${SERVER}${SERVER_CMD}idx=174&nvalue=0&svalue=${apc_load}"
curlres=`curl -sS $hostcmd`
hostcmd="http://${SERVER}${SERVER_CMD}idx=175&nvalue=0&svalue=${apc_bcharge}"
curlres=`curl -sS $hostcmd`
hostcmd="http://${SERVER}${SERVER_CMD}idx=173&nvalue=0&svalue=${apc_batt}"
curlres=`curl -sS $hostcmd`


if  [ "$apc_stat" = "ONLINE" ]; then
#echo "APC SYSTEM IS ONLINE"
hostcmd="http://${SERVER}${SWITCH_CMD}idx=178&switchcmd=On&level=0"
curlres=`curl -sS $hostcmd`

else
#echo "APC SYSTEM IS OFFLINE"
hostcmd="http://${SERVER}${SWITCH_CMD}idx=178&switchcmd=Off&level=0"
curlres=`curl -sS $hostcmd`

fi


2; I have tried to create the crontab, only I do not know where to make it, and what the exact content should be, I found a crontab in " /etc/crontab " and modified it, only then will the data be not updated in domoticz, in apcupsd i get the actual reading.

Can someone help me with this?
NUC Proxmox VM Stable & Raspberry Pi-3 Domoticz Beta
Tradfri Pluging by Moroen, Home made MySensors, Luftdaten, Home & Garden automatisation.
APC Back-UPS XS 700U, Modbus RTU & Janitza UMG103, RF-Link
Sonos plugins
dzjr
Posts: 45
Joined: Monday 02 July 2018 23:35
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.100xx
Location: Alkmaar, The Netherlands
Contact:

Re: APC UPS Monitoring

Post by dzjr »

I tried everything but did not get it through the script.

Now I have used the Phyton from @rene, just on the PI, and that works!
I start it up via a separate script that is started by crontab when starting the PI.

Sometimes the script stops, but I've only seen it once!
NUC Proxmox VM Stable & Raspberry Pi-3 Domoticz Beta
Tradfri Pluging by Moroen, Home made MySensors, Luftdaten, Home & Garden automatisation.
APC Back-UPS XS 700U, Modbus RTU & Janitza UMG103, RF-Link
Sonos plugins
kimhav
Posts: 148
Joined: Tuesday 01 October 2013 8:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Sweden
Contact:

Re: APC UPS Monitoring

Post by kimhav »

How is the monitoring of the apcupsd working out on your side; asking since I'm looking at adding similar statistics gathering to Domoticz; so curious how it's working out?
dzjr
Posts: 45
Joined: Monday 02 July 2018 23:35
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.100xx
Location: Alkmaar, The Netherlands
Contact:

Re: APC UPS Monitoring

Post by dzjr »

kimhav wrote: Sunday 13 January 2019 19:46 How is the monitoring of the apcupsd working out on your side; asking since I'm looking at adding similar statistics gathering to Domoticz; so curious how it's working out?
for me it is working fine, but only with the Python script, i read the input voltage, Battery voltage, load %, Charge %, and online/battery state.

The only thing i have to figure out is how ik can adjust APCUPSD to restart when the battery is charged for 25% or more.
Attachments
Knipsel.PNG
Knipsel.PNG (9.38 KiB) Viewed 12431 times
NUC Proxmox VM Stable & Raspberry Pi-3 Domoticz Beta
Tradfri Pluging by Moroen, Home made MySensors, Luftdaten, Home & Garden automatisation.
APC Back-UPS XS 700U, Modbus RTU & Janitza UMG103, RF-Link
Sonos plugins
sach
Posts: 111
Joined: Wednesday 12 October 2016 14:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: APC UPS Monitoring

Post by sach »

Python script works for me, but how do i get it to run automatically when the server starts?

Any chance of this becoming a Python Plugin?
f14driver
Posts: 18
Joined: Sunday 24 June 2018 16:19
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: APC UPS Monitoring

Post by f14driver »

I created a simple script to test the connection when the pi boots.

Explanation of the script:
The first command halts the process apcupsd
The second command tests the configuration of your apcupsconfig file located at /etc/apcupsd/apcupsd.conf
The third command lets the system wait for 5 seconds to complet the test.
The fourth command enables the process apcupsd again.


The script is called apcautotest.sh
Step 1
create the script in the directory /domoticz/scripts/
touch apcautotest.sh

It's a bash script that you will have to create;

Step 2
copy the lines underneath into the script:

#!/bin/bash

sudo systemctl stop apcupsd
sudo apctest
sleep 5
sudo systemctl start apcupsd

Step 3
Save the script.

Step 4
Make the script executable:
chmod +x apcautotest.sh

Step 5 test the script:
from the /domoticz/scripts directory
sudo ./apcautotest.sh

After that the proces is automaticly running and the apcaccess status command wil give you a full printout of the APC ups
Without doing the apctest command it will give you a shortend version (ommiting for instance wheter or not the UPS Is online).

Step 6
Add the script to /etc/rc.local:

sudo /home/pi/domoticz/scripts/apcautotest.sh

step 7 reboot the Pi and check if you get a full printout from the APC UPS:
apcaccess status
If this is the case it will run the script every time on boot of the Pi.
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

Re: APC UPS Monitoring

Post by erem »

you can put a cron entry like this

@reboot /path/to/shell.script

make sure script is executable
Regards,

Rob
jgaalen
Posts: 15
Joined: Monday 11 February 2019 9:05
Target OS: Linux
Domoticz version:
Contact:

Re: APC UPS Monitoring

Post by jgaalen »

I've made a domoticz plugin for the APC UPS monitoring. It can be found here: https://github.com/jgaalen/domoticz-apc-ups-plugin

Also, here's a dzVents script that I use to alert myself when it starts running on battery:

Code: Select all

return {
	on = {
		devices = {
			'APC - Status'
		}
	},
	execute = function(domoticz, device)

        lastValue = domoticz.variables('lastApcStatus').value
        
        if (device.text == 'ONBATT' and lastValue == 'ONLINE') then
            domoticz.notify('Power failure! Server running on battery now!' ) 
        end
        
        if (device.text == 'ONLINE' and lastValue == 'ONBATT') then
            domoticz.notify('Power back online! Server running on net power now!' ) 
        end
        
        
        if (device.text ~= lastValue) then
            domoticz.variables('lastApcStatus').set(device.text)
        end

	end
}
User avatar
user4563
Posts: 96
Joined: Tuesday 19 October 2021 17:24
Target OS: Windows
Domoticz version: 2023.2
Contact:

Re: APC UPS Monitoring

Post by user4563 »

Thank you. I'm already using apcupsd so I'll have to try this for the Domoticz integration
Domoticz 2023.2 running as a service on Windows 10 w/ Aeotec Z-Stick Gen5+, HAProxy (remote access)
Domoticz for Android
Domoticz Scenes add-on in Kodi
Hiero
Posts: 1
Joined: Tuesday 11 January 2022 23:03
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: APC UPS Monitoring

Post by Hiero »

jgaalen wrote: Wednesday 05 January 2022 17:57 I've made a domoticz plugin for the APC UPS monitoring. It can be found here: https://github.com/jgaalen/domoticz-apc-ups-plugin

Also, here's a dzVents script that I use to alert myself when it starts running on battery:

Code: Select all

return {
	on = {
		devices = {
			'APC - Status'
		}
	},
	execute = function(domoticz, device)

        lastValue = domoticz.variables('lastApcStatus').value
        
        if (device.text == 'ONBATT' and lastValue == 'ONLINE') then
            domoticz.notify('Power failure! Server running on battery now!' ) 
        end
        
        if (device.text == 'ONLINE' and lastValue == 'ONBATT') then
            domoticz.notify('Power back online! Server running on net power now!' ) 
        end
        
        
        if (device.text ~= lastValue) then
            domoticz.variables('lastApcStatus').set(device.text)
        end

	end
}
Your plugin works like a charm! couple of minutes and it was running. Thanks :)
User avatar
madpatrick
Posts: 639
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: APC UPS Monitoring

Post by madpatrick »

Nice plugin. Good job
-= HP server GEN8 Xeon(R) E3-1220L_V2 -=- OZW -=- Toon2 (rooted) -=- Domoticz v2024.7 -=- Dashticz v3.12b on Tab8" =-
Darkneo
Posts: 24
Joined: Sunday 10 February 2019 16:22
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: APC UPS Monitoring

Post by Darkneo »

Hi there,

Just adding my2cents there. I am using the dedicated plugin to monitor my UPS connected to my Domoticz through USB since years now, and have no issues (viewtopic.php?t=18154)

Nothing special, everything is well explained and documented and working properly.

On my side, I added an CM180+ sensor, that gives me my real time consumption for my house .

Just a tricky thing: the CM180 only gives the current, thus I made a custom event to translate it to real power consumption:

Code: Select all

local idx = 96 --idx of device virtual to show power consumption
local cm180 = 'Wattmeter' --name of the CM180+ sensor preventing issue if IDX changes
local tension = otherdevices['EDF Voltage'] --Voltage taken from the UPS devices using its name to prevent issues if IDX changes
function round(num, dec)
   if num == 0 then
	 return 0
   else
	 local mult = 10^(dec or 2)
	 return math.floor(num * mult + 0.5) / mult
   end
end

commandArray = {}


if (devicechanged[cm180]) then
    --Computing current
    --print('Valeur '..otherdevices[cm180])
    p1, p2 = string.match(otherdevices_svalues[cm180], "(%d+.%d*);(%d+.%d*)")
    --on les transforme en Ampere
	intensite = p1 / tension
	--0.01 precision only
	intensite = round(intensite, 2)
	commandArray[#commandArray+1]={['UpdateDevice'] = idx..'|0|'..intensite} ---- updating power dummy sensor
end
return commandArray
Attachments
UPC.png
UPC.png (22.99 KiB) Viewed 8435 times
JanAtHome
Posts: 38
Joined: Wednesday 10 January 2018 16:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 38153
Location: Raalte Holland
Contact:

Re: APC UPS Monitoring

Post by JanAtHome »

Hello all
Just installed an APC ups, a BE550G-GR, this is a simple ups without network connection, on the PC it works with PowerChute version-3.0.2 and a USB cable is present.
Now I have tried to install it in domoticz via the Plugin (discussed above above) but this does not work because there is no network connection. My question Can I adjust this plugin, or should I use the separate script that has already been discussed.
Please respond what to do.
Jan

Hallo Allemaal
Heb net een APC ups geinstalleerd, een BE550G-GR, dit is een eenvoudige ups zonder netwerk aansluiting, op de pc werkt deze wel met PowerChute versie-3.0.2 en er is een USB kabel aanwezig.
Nu heb ik deze geprobeerd in domoticz te installeren via de Plugin (jgaalen boven eerder besproken) maar dit werkt niet omdat er geen netwerk aansluiting is. Mijn vraag Kan ik deze plugin aanpassen, of kan ik beter de losse script gebruiken die ook al besproken is.
Gaarne respons wat to do.
Jan
kimhav
Posts: 148
Joined: Tuesday 01 October 2013 8:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Sweden
Contact:

Re: APC UPS Monitoring

Post by kimhav »

JanAtHome wrote: Monday 26 December 2022 17:23Just installed an APC ups, a BE550G-GR, this is a simple ups without network connection, on the PC it works with PowerChute version-3.0.2 and a USB cable is present.
Now I have tried to install it in domoticz via the Plugin (discussed above above) but this does not work because there is no network connection. My question Can I adjust this plugin, or should I use the separate script that has already been discussed.
Please respond what to do.
Hi Jan,
See that this is an old posting and don't sure whether you got it to work or not, but the Domoticz plugin requires that 1) that the APC UPS is connected to the host using the USB-cable that came along to the system that you're running your Domoticz installation on, and 2) that you have apcupsd installed as the script is making use of the command 'apcaccess' to retrieve the data from the APC UPS.
User avatar
madpatrick
Posts: 639
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: APC UPS Monitoring

Post by madpatrick »

You can use the plugin on a different system as your UPS is connected.
The only thing is you need to install apcupsd on the system where the uPS is connected and your domoticz system
On your domoticz system the chane the config file apcupsd.conf with the following parametesrs

Code: Select all

UPSCABLE ether
DEVICE 192.168.1.1:3551
192.168.1.1 is the IP of the system with UPS connected

I think you can also put in Domoticz hardware setup the IP of the host instead of local IP
Then you don't have to install APCUPSD
-= HP server GEN8 Xeon(R) E3-1220L_V2 -=- OZW -=- Toon2 (rooted) -=- Domoticz v2024.7 -=- Dashticz v3.12b on Tab8" =-
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest