Monitor CyberPower UPS devices with Raspberry Pi

Mike R
6 min readSep 16, 2019

I have 2 CyberPower UPS units in my network cabinet (model #OR2200LCDRTXL2U)

CyberPower UPS device

I was looking for a way to monitor both UPS devices and send out an email in case either one loses external power.

CyberPower does provide a Remote Management card, but at $160 a piece, they’re pricey, and I would need 2 of these.

optional Remote Management card

Instead, here’s a solution that wont run you over 50$

I had a spare Raspberry Pi 2 lying around, and doing some DuckDuck searches, I found several articles on how to setup monitoring for my UPS units using the Raspberry Pi unit.

Here are the steps:

Raspberry Pi setup

install appropriate distro on your Pi, in my case I’m using Lubuntu, but this should work with any Debian-based OS including Raspbian.

Place your Pi in your network cabinet and connect a Cat6 cable to your switch to obtain a LAN IP address (you can also do this via Wifi) — basically connect your Pi to the internet and be able to SSH to it to do configuration

Once this is done, plugin the 2 UPS units to your Pi using USB cables (see photo)

2 USB connections from Pi to your UPS devices
USB cables plugged in.

NUT-Client Configuration setup

SSH to your Pi as root and install the necessary packages that will connect to your UPS devices,

Here we are installing NUT packages (Network UPS Tools)

root@mrxpi:~# apt-get update && apt-get install nut nut-client nut-server

once installed, reboot the Pi, once rebooted, check if you can see your UPS devices,

root@mrxpi:~# lsusb
Bus 001 Device 050: ID 0764:0601 Cyber Power System, Inc. PR1500LCDRT2U UPS
Bus 001 Device 049: ID 0764:0601 Cyber Power System, Inc. PR1500LCDRT2U UPS

configure the /var/run/nut directory

root@mrxpi:~# mkdir /var/run/nut
root@mrxpi:~# chown nut:nut /var/run/nut

define your UPS devices,

vi /etc/nut/ups.conf
add the entires for your devices, here I am giving the description of each UPS and its position in my cabinet .

[cyberpower1]
driver = usbhid-ups
port = auto
desc = "CyberPower OR2200LCDRTXL2U-TOP"
[cyberpower2]
driver = usbhid-ups
port = auto
desc = "CyberPower OR2200LCDRTXL2U-BOTTOM"

If your UPS model is different, see the driver list and choose appropriate driver

Start the NUT Client service

systemctl restart nut-client.service

restart Driver

root@mrxpi:~# upsdrvctl stop
root@mrxpi:~# upsdrvctl start

Test to see if you can see your UPS devices,

root@mrxpi ~# upsc cyberpower1@localhost

The command will return bunch of UPS information,

Init SSL without certificate database
battery.charge: 100
battery.charge.low: 10
battery.charge.warning: 20
battery.mfr.date: CPS
battery.runtime: 4710
battery.runtime.low: 300
battery.type: PbAcid
battery.voltage: 27.5
battery.voltage.nominal: 24
device.mfr: CPS
device.model: OR2200LCDRTXL2U
device.type: ups
driver.name: usbhid-ups
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.version: 2.7.2
driver.version.data: CyberPower HID 0.3
driver.version.internal: 0.38
input.transfer.high: 140
input.transfer.low: 90
input.voltage: 118.0
input.voltage.nominal: 120
output.voltage: 118.0
ups.beeper.status: enabled
ups.delay.shutdown: 20
ups.delay.start: 30
ups.load: 8
ups.mfr: CPS
ups.model: OR2200LCDRTXL2U
ups.productid: 0601
ups.realpower.nominal: 1650
ups.status: OL
ups.timer.shutdown: -60
ups.timer.start: -60
ups.vendorid: 0764

You can also check your 2nd UPS device the same way,

root@mrxpi ~# upsc cyberpower2@localhost

Configure NUT-Server and NUT-monitor

edit the NUT server file

vi /etc/nut/upsd.conf
add the following

LISTEN 127.0.0.1 3493
LISTEN <IP of your Rasp PI>
# (in my case I'm using Raspberry LAN IP of 192.168.30.135)
LISTEN 192.168.30.135

Add UPS devices to monitor,

vi /etc/nut/upsmon.conf

MONITOR cyberpower1@<IP of Rasp PI> 1 upsmaster myPass123 master
MONITOR cyberpower2@<IP of Rasp PI> upsremote myPass123 slave

vi /etc/nuts/hosts.conf
add these lines

MONITOR cyberpower1@localhost “CyberPower OR2200LCDRTXL2U-TOP”
MONITOR cyberpower2@localhost “CyberPower OR2200LCDRTXL2U-BOTTOM”

Create Nut-Monitor service script

locate the Nut Monitor (lol) binary and get the path

which upsmon

create the systemd script

root@mrxpi# vi/etc/systemd/system/nut-monitor.service 
[Unit]
Description=Network UPS Tools - power device monitor and shutdown controller
After=nut-server.service
[Service]
ExecStart=/sbin/upsmon
PIDFile=/run/nut/upsmon.pid
Type=forking
[Install]
WantedBy=multi-user.target

enable the monitor on reboot

systemctl enable nut-monitor

edit the monitoring mode

vi /etc/nut/nut.conf

MODE=netclient

set permissions & restart all services

sudo chown root:nut /etc/nut/*
sudo chmod 640 /etc/nut/*
systemctl nut-server restart
systemctl nut-client restart

Monitor UPS log

upslog -s cyberpower1@localhost -l -

unplug USB from Pi and watch to make sure log shows offline, replug it in and see it come back up,

root@mrxpi /e/nut# upslog -s cyberpower1@localhost -l -
Network UPS Tools upslog 2.7.2
logging status of cyberpower1@localhost to - (30s intervals)
Init SSL without certificate database
20190726 161546 100 118.0 8 [OL] NA NA
20190726 161616 100 118.0 8 [OL] NA NA20190726 161646 NA NA NA [NA] NA NA
20190726 161716 100 118.0 8 [OL] NA NA
20190726 161746 100 118.0 8 [OL] NA NA
20190726 161816 100 119.0 8 [OL] NA NA

Configure Email alerts

for email alerts, I’m using Postfix, install it on the Pi if you dont have it,

this article describes the process of setting up Postfix + Gmail

Follow the guide to install and configure Postfix with Gmail.

My final postfix main.cf configuration looks like this,

queue_directory = /var/spool/postfix
command_directory = /usr/sbin
data_directory = /var/lib/postfix
mail_owner = postfix
myhostname = mrxpi.company.com
myorigin = $myhostname
inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, localhost
unknown_local_recipient_reject_code = 550
mynetworks = 192.168.30.0/24
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
message_size_limit = 25600000
debug_peer_level = 2
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.6.6/samples
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

Test sending out email from your Pi and tail -f the mail log to see any messages,

# install mailutils
apt-get install mailutils

# test sending out email
mail -s "test pi" yourname@emailaddress.com < /dev/null

Follow the log in case any errors

tail -f /var/log/mail.log

once emailing works, move on to next part

Configure Monitoring Alerts

add Alerting conditions

vi /etc/nut/upsmon.conf

NOTIFYCMD /etc/nut/notifycmd.sh
NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
NOTIFYFLAG LOWBATT SYSLOG+WALL+EXEC
NOTIFYFLAG FSD SYSLOG+WALL+EXEC
NOTIFYFLAG COMMOK SYSLOG+WALL+EXEC
NOTIFYFLAG COMMBAD SYSLOG+WALL+EXEC
NOTIFYFLAG SHUTDOWN SYSLOG+WALL+EXEC
NOTIFYFLAG REPLBATT SYSLOG+WALL+EXEC
NOTIFYFLAG NOCOMM SYSLOG+WALL+EXEC
NOTIFYFLAG NOPARENT SYSLOG+WALL

create the shell script

vi /etc/nut/notifycmd.sh

#!/bin/bashTO='user@email.com'printf "Subject: UPS POWER SUPPLY ALERT: $NOTIFYTYPE\n\nUPS: $UPSNAME\r\nAlert type: $NOTIFYTYPE" | | mail -s "subject" $TO

add permissions

sudo chown root:nut /etc/nut/*
sudo chmod 755 /etc/nut/notifycmd.sh

restart all services

systemctl restart nut-server
systemctl restart nut-client

Your final files and permissions should look like this,

Heres the contents of each file,

cat /etc/nut/hosts.conf

MONITOR cyberpower1@localhost "CyberPower OR2200LCDRTXL2U-TOP"
MONITOR cyberpower2@localhost "CyberPower OR2200LCDRTXL2U-BOTTOM"

cat /etc/nut/notifycmd.sh

cat /etc/nut/notifycmd.sh#!/bin/bashTO='admin@company.com'printf "Subject: UPS POWER SUPPLY ALERT (Office cabinet): $NOTIFYTYPE\n\nUPS: $UPSNAME\r\nAlert type: $NOTIFYTYPE" | mail -s "subject" $TO

cat /etc/nut/nut.conf

MODE=netserver

cat /etc/nut/ups.conf

maxretry = 3[cyberpower1]
driver = usbhid-ups
port = auto
desc = "CyberPower OR2200LCDRTXL2U-TOP"
#pollinterval = 15
[cyberpower2]
driver = usbhid-ups
port = auto
desc = "CyberPower OR2200LCDRTXL2U-BOTTOM"
#pollinterval = 15

cat /etc/nut/upsd.conf

LISTEN 127.0.0.1 3493
LISTEN 192.168.30.135 3493

cat /etc/nut/upsd.users

[admin]
password = spaceballs
actions = SET
instcmds = ALL
[upsmon1]
password = spaceballs
upsmon master
[upsmon2]
password = spaceballs
upsmon slave

cat /etc/nut/upsmon.conf

MONITOR cyberpower1@localhost 1 upsmon1 spaceballs masterMINSUPPLIES 1SHUTDOWNCMD "/sbin/shutdown -h +0"
POLLFREQ 5
POLLFREQALERT 5
HOSTSYNC 15
DEADTIME 15
POWERDOWNFLAG /etc/killpower
NOTIFYCMD /etc/nut/notifycmd.sh
NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
NOTIFYFLAG LOWBATT SYSLOG+WALL+EXEC
NOTIFYFLAG FSD SYSLOG+WALL+EXEC
NOTIFYFLAG COMMOK SYSLOG+WALL+EXEC
NOTIFYFLAG COMMBAD SYSLOG+WALL+EXEC
NOTIFYFLAG SHUTDOWN SYSLOG+WALL+EXEC
NOTIFYFLAG REPLBATT SYSLOG+WALL+EXEC
NOTIFYFLAG NOCOMM SYSLOG+WALL+EXEC
NOTIFYFLAG NOPARENT SYSLOG+WALL
RBWARNTIME 43200
NOCOMMWARNTIME 300
FINALDELAY 5

the rest of files are default config settings.

Now test unplugging the UPS units from outlet, your Pi should send an email that looks like this

Subject: UPS POWER SUPPLY ALERT (Office cabinet): ONBATT

UPS: cyberpower1@localhost
Alert type: ONBATT

--

--