HP T700h UPS has a serial port. I’m using a USB to RS232 cable/dongle that comes up as /dev/ttyUSB0.

First install nut.

Next, enable standalone mode in /etc/nut/nut.conf

MODE=standalone

Define the UPS. I’ve called it “hp” but you can give any name you like in /etc/nut/nut.conf

[hp]
driver = bcmxcp
desc = "HP T700"
port = /dev/ttyUSB0

Add nut user to the dialout group:

sudo usermod -a -G dialout nut

Restart nut and start the driver service.

sudo /etc/init.d/nut-server restart
sudo upsdrvctl start

Hopefully no errors so far and you get a message about attempting to autodect baud rate and then “Connected to UPS on /dev/ttyUSB0 with baud rate 9600”.

Now you should be able to read out raw data from the ups with the command:

upsc hp

General NUT Config

To get to the web interface, try visiting:

http://<hostname>/cgi-bin/nut/upsstats.cgi

You’ll probably get a “Forbidden” / 403 error.

sudo apt install apache2 nut-cgi
sudo a2enmod cgi
sudo systemctl restart apache2

Configure /etc/nut/hosts.conf

MONITOR hp@localhost "IT Cupboard"

If you’re only running your this on a PI on your local network, behind a router / firewall without direct access from the internet, then go ahead and edit /etc/nut/upsset.conf

I_HAVE_SECURED_MY_CGI_DIRECTORY

You can now visit your UPS webpage at http://<hostname>/cgi-bin/nut/upsstats.cgi

Configure something to happen when the power goes out

Edit /etc/nut/upsmon.conf

NOTIFYCMD "/usr/local/bin/nut-notify.sh"

#APPEND:
MONITOR hp@localhost 1 monitor <password> master

Edit /etc/nut/upsd.users

[monitor]
password = <password>
upsmon master

Create your notification script.

I’m using Prowl to send push alerts and also sending an email.

Another great way is to email through pushover.

Here’s my /usr/local/bin/nut-notify.sh

#!/bin/bash
#Notify about UPS events

VOLTAGE=$(/bin/upsc hp@localhost | grep input)
echo "$@ $VOLTAGE" | mail  -r "Location name <from email>" -s "[Location] UPS Notice" <my email address>

curl -m 4 --data "apikey=<API KEY FOR PROWL>&application=Location_nut-notify&event=$NOTIFYTYPE&description=UPS%20notify%20$NOTIFYTYPE" https://api.prowlapp.compublicapi/add

Don’t forget to:

sudo chmod +x /usr/local/bin/nut-notify.sh

Adding SNMP Support

I also added SNMP to NUT so that the UPS details can be monitored over SNMP by services like Munin and Observium.

To do this, past the following block into the end of an already configured and functioning /etc/snmp/snmpd.conf

We need to ignore the SSL warning and return just the value when asked by SNMP via CLI argument. Therefore, I’ve cerated a /usr/local/bin/ups-status.sh

#!/bin/bash

# read value
VALUE=$(/bin/upsc hp@localhost $1 2>&1 | /bin/grep -v '^Init SSL')
# return vaue
echo ${VALUE}

To add the necessary entries to /etc/snmp/snmpd.conf, simply run:

upsc hp@localhost | sed 's/^\(.*\): .*$/extend \1 \/usr\/local\/bin\/ups-status.sh \1/' >> /etc/snmp/snmpd.conf

Add execute permissions and restart snmpd.

sudo chmod /usr/local/bin/ups-status.sh
sudo systemctl restart snmpd

You can walk the values at this OID: .1.3.6.1.4.1.8072.1.3.2.3.1.2

Adding to munin

The following can be added to an already configured munin-node to get some UPS stats graphed:

sudo su
cd /etc/munin/plugins
ln -s /usr/share/munin/plugins/nut_misc nut_misc
ln -s /usr/share/munin/plugins/nutups_ nutups_hp_charge
ln -s /usr/share/munin/plugins/nutups_ nutups_hp_current
ln -s /usr/share/munin/plugins/nutups_ nutups_hp_freq
ln -s /usr/share/munin/plugins/nutups_ nutups_hp_voltages
ln -s /usr/share/munin/plugins/nut_volts nut_volts

And also create file at /etc/munin/plugin-conf.d/nut

[nut*]
env.upsname hp@127.0.0.1

References

https://docs.technotim.live/posts/NUT-server-guide/

https://www.reddit.com/r/homelab/comments/5ssb5h/ups_server_on_raspberry_pi/