...
Just my blog

Blog about everything, mostly about tech stuff I made. Here is the list of stuff I'm using at my blog. Feel free to ask me about implementations.

Soft I recommend
Py lib I recommend

I'm using these libraries so you can ask me about them.

Installing NUT - Network Ups Tool

Install and use Network Ups Tool - an open source Uninterruptible Power Supply software

I'll describe a full path on how to install and use NUT.
My implementation is using Raspberry Pi 5 and a TP-Link router attached to 800W UPS.
RPi will be a brain unit which will send notifications to email and make a voice notification about power outages and battery levels.
 
My current surge and power loss protection scheme is the following:
  • UPS with connected devices:
    • LG TV
    • Soundbar
    • NUC as a media centre (with NUT monitor for Windows)
    • RPi5 as brain unit with NUT, Pi-Hole and DHCP.
    • TP-Link Router.

In case of a power-loss event, PRi will notify me via email, NUC will power off on its own, TV can be powered off manually.

Powered-off TV and soundbar are neglectable in total power usage on battery, so I have about 1,5 to 2 hours of running Raspberry 5 and TP-Link to keep my internet on.

Now to the setup.
 
I'll share all the topics I used before:
 
Docs:
 

Overall update

Current NUT version 2.8.0 had a bug where CPU usage goes up to 100% on battery power, the fix is at the master branch.
Better install NUT from sources to get this and other fixes: ADD HERE A LINK TO SOURCES INSTALL DOC
 

Regular installation and setup

Install from system repos:

sudo apt install nut
 
Connect UPS via USB and check the devices list:
 
~ $ lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 109: ID 0d9f:0004 Powercom Co., Ltd HID UPS Battery
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 

Add UPS to config

sudo vi /etc/nut/ups.conf
 
Use 0d9f:0004 as vendorid\productid
 
Read about overriding options above on the web.
[Powercom800W]
    driver = usbhid-ups
    desc = "Powercom Co 800W"
    port = auto
    vendorid = 0d9f
    productid = 0004
    pollfreq = 60
    pollinterval = 10
    ignorelb
    override.battery.date = 2024/01/25
    override.battery.date.maintenance = 2026/01/25
    override.ups.delay.start = 0
    override.battery.charge.low = 5
    override.battery.charge.warning = 15
    override.battery.runtime.low = 60
    override.ups.beeper.status = disabled
 

Make accessible

sudo vi /etc/nut/upsd.conf
# add
LISTEN 0.0.0.0 3493
 

Setup user

User: upsmon
 
sudo vi /etc/nut/upsd.users
 
Add
[upsmon]
    password = <PASSWORD>
    upsmon primary

More users

[admin]
    password = adminpass
    actions = SET
    actions = FSD
    instcmds = ALL
    upsmon master

[monmaster]
    password = masterpass
    upsmon master

[monslave]
    password = slavepass
    upsmon slave
 

Configure monitoring

sudo vi /etc/nut/upsmon.conf
 
Possible options to look at
 
POLLFREQ 30

DEADTIME 120
 
Add your UPS for internal monitoring
 
MONITOR Powercom800W@localhost 1 monmaster PASSWORD master
 

Run as server

sudo vi /etc/nut/nut.conf
 
Change to

MODE=netserver
 

Restart and check

sudo systemctl restart nut-server && sudo systemctl restart nut-monitor
upsc Powercom800W@localhost
 

Install WEB Gui

sudo apt install nut-cgi
sudo vi /etc/nut/hosts.conf
MONITOR Powercom800W@localhost "Powercom800W_Raspb"

I'm using lighttpd

This is because I have a Pi-Hole installed already.
Install modules:
sudo apt install nut-cgi -y sudo lighttpd-enable-mod cgi sudo service lighttpd force-reload
 

Check CGI

sudo vi /etc/lighttpd/conf-enabled/10-cgi.conf
 
server.modules += ( "mod_cgi" )

$HTTP["url"] =~ "^/cgi-bin/" {
        cgi.assign = ( "" => "" )
        alias.url += ( "/cgi-bin/" => "/usr/lib/cgi-bin/" )
}
 

Create a new HTTP conf for NUT

sudo vi /etc/lighttpd/conf-enabled/nut-ups.conf
General HTTPD conf should include files: line: 48 include "/etc/lighttpd/conf-enabled/*.conf"
Pi-Hole will overwrite the general config file do not change anything there.
Conf content working fine for me for all three pages for my UPS, but index.html is not working at the main www dir, and it does not matter.

 

# Work with both, inxed and CGI
server.modules += (
    "mod_auth",
    "mod_cgi",
    "mod_expire",
    "mod_rewrite",
    "mod_fastcgi",
    "mod_setenv",
    "mod_status"
)
# Work CGI, doesnt work idex
$HTTP["url"] =~ "/nut/" {
    cgi.assign = ( "" => "" )
    alias.url += ( "/nut/cgi-bin" => "/usr/lib/cgi-bin/nut" )
    alias.url += ( "/cgi-bin/nut" => "/usr/lib/cgi-bin/nut" )
}
# Static HTML
$HTTP["url"] =~ "/nut-web/" { alias.url += ( "/nut-web" => "/usr/share/nut/www" ) }

Optional CGI executable flag

sudo vi /etc/nut/upsset.conf

 Uncomment:

###
I_HAVE_SECURED_MY_CGI_DIRECTORY
###

Restart

sudo systemctl restart lighttpd.service
 
See those pages
  • http://YOUR_PI_HOST/cgi-bin/nut/upsstats.cgi?host=Powercom800W@localhost&treemode
  • http://YOUR_PI_HOST/cgi-bin/nut/upsstats.cgi
  • http://YOUR_PI_HOST/cgi-bin/nut/upsstats.cgi?host=Powercom800W@localhost

 

Next: Notifications and emails.