Monitor CyberPower UPS devices with Raspberry Pi

CyberPower UPS device
optional Remote Management card

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.

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,

root@mrxpi:~# apt-get update && apt-get install nut nut-client nut-server
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
root@mrxpi:~# mkdir /var/run/nut
root@mrxpi:~# chown nut:nut /var/run/nut
[cyberpower1]
driver = usbhid-ups
port = auto
desc = "CyberPower OR2200LCDRTXL2U-TOP"
[cyberpower2]
driver = usbhid-ups
port = auto
desc = "CyberPower OR2200LCDRTXL2U-BOTTOM"
systemctl restart nut-client.service
root@mrxpi:~# upsdrvctl stop
root@mrxpi:~# upsdrvctl start
root@mrxpi ~# upsc cyberpower1@localhost
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
root@mrxpi ~# upsc cyberpower2@localhost

Configure NUT-Server and NUT-monitor

edit the NUT server file

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
MONITOR cyberpower1@<IP of Rasp PI> 1 upsmaster myPass123 master
MONITOR cyberpower2@<IP of Rasp PI> upsremote myPass123 slave
MONITOR cyberpower1@localhost “CyberPower OR2200LCDRTXL2U-TOP”
MONITOR cyberpower2@localhost “CyberPower OR2200LCDRTXL2U-BOTTOM”
which upsmon
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
systemctl enable nut-monitor
MODE=netclient
sudo chown root:nut /etc/nut/*
sudo chmod 640 /etc/nut/*
systemctl nut-server restart
systemctl nut-client restart
upslog -s cyberpower1@localhost -l -
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,

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
# install mailutils
apt-get install mailutils

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

Configure Monitoring Alerts

add Alerting conditions

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
#!/bin/bashTO='user@email.com'printf "Subject: UPS POWER SUPPLY ALERT: $NOTIFYTYPE\n\nUPS: $UPSNAME\r\nAlert type: $NOTIFYTYPE" | | mail -s "subject" $TO
sudo chown root:nut /etc/nut/*
sudo chmod 755 /etc/nut/notifycmd.sh
systemctl restart nut-server
systemctl restart nut-client
MONITOR cyberpower1@localhost "CyberPower OR2200LCDRTXL2U-TOP"
MONITOR cyberpower2@localhost "CyberPower OR2200LCDRTXL2U-BOTTOM"
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
MODE=netserver
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
LISTEN 127.0.0.1 3493
LISTEN 192.168.30.135 3493
[admin]
password = spaceballs
actions = SET
instcmds = ALL
[upsmon1]
password = spaceballs
upsmon master
[upsmon2]
password = spaceballs
upsmon slave
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
Subject: UPS POWER SUPPLY ALERT (Office cabinet): ONBATT

UPS: cyberpower1@localhost
Alert type: ONBATT

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store