Nut-ups: Difference between revisions

From Alpine Linux
No edit summary
No edit summary
Line 86: Line 86:


Thee are the vendor and product IDs found in the '''dmesg''' output above. The rest of the line tells udev what permissions and group ownership to use. It should be the same regardless of the UPS make and model, but the ''idVendor'' and ''idProduct'' will be unique to your UPS.
Thee are the vendor and product IDs found in the '''dmesg''' output above. The rest of the line tells udev what permissions and group ownership to use. It should be the same regardless of the UPS make and model, but the ''idVendor'' and ''idProduct'' will be unique to your UPS.
{{ note|There is also a file '''/lib/udev/rules.d/62-nut-usbups.rules''' that has information for all of the UPS models NUT knows about. You may be able to simply copy this rather than constructing your own rules from the information in the '''dmesg''' output. }}

Revision as of 00:46, 10 October 2024

[WORK IN PROGRESS]

Installing and Configuring Network UPS Tools (NUT)

This wiki page shows how to install and configure the NUT package to monitor and report the statistics for a USB attached Uninterruptible Power Supply (UPS). The UPS model used in the examples is an APC SmartUPS 1000, but any UPS on the list of compatible models should work.

The end goal is to make the UPS status available over the network so it can be monitored and used to trigger actions in a home automation system like Home Assistant.

Determining Your UPS USB Parameters

The first step is to plug in the USB cable between your UPS and your Alpine host to see how it appears to the system. This is done with the dmesg command. See the example below.

 alpine:/# dmesg
 [400269.428612] usb 1-3: new low-speed USB device number 3 using xhci_hcd
 [400269.580728] usb 1-3: New USB device found, idVendor=051d, idProduct=0002, bcdDevice= 0.06
 [400269.580751] usb 1-3: New USB device strings: Mfr=3, Product=1, SerialNumber=2
 [400269.580759] usb 1-3: Product: Smart-UPS 1000 FW:600.3.D USB FW:1.4
 [400269.580765] usb 1-3: Manufacturer: American Power Conversion
 [400269.580771] usb 1-3: SerialNumber: AS0235210142
 [400269.687883] usbcore: registered new interface driver usbhid
 [400269.687894] usbhid: USB HID core driver
 [400269.698356] hid-generic 0003:051D:0002.0001: hiddev96,hidraw0: USB HID v1.10 Device [American Power Conversion Smart-UPS 1000 FW:600.3.D USB FW:1.4] on usb-0000:00:15.0-3/input0

From this output, we can see a Smart-UPS 1000 has been detected. We can also see two important parameters: idVendor=051d and idProduct=0002

These will be used later in the udev rules, so keep them handy.

Installing and Configuring NUT

The first step is to add the alpine package. After that, we'll rename three default configuration files and replace them with the parameters needed for our example USB attached APC Smart-UPS.

 alpine:/# apk update && apk add nut
 
 alpine:/# mv /etc/nut/nut.conf /etc/nut/nut.conf~
 
 alpine:/# cat <<EOF >/etc/nut/nut.conf
 MODE=netserver
 EOF
 
 alpine:/# mv /etc/nut/ups.conf /etc/nut/ups.conf~
 
 alpine:/# cat <<EOF >/etc/nut/ups.conf
 [SmartUPS_1000]
     driver = usbhid-ups
     port = auto
 EOF
 
 alpine:/# mv upsd.conf upsd.conf~
 alpine:/# cat <<EOF >upsd.conf
 LISTEN 0.0.0.0 3493
 EOF

The first command should be familiar. It updates the Alpine package manager database and installs the nut package. All of the configuration files delivered with the package will be in the /etc/nut subdirectory.

The next several commands will create a backup copy of the original configuration file and then write a new file with only the configuration parameters needed.

The line written to nut.conf instructs NUT to make the UPS status available on the network.

The lines in ups.conf define the name (in square brackets), the driver used to communicate with the UPS and the port. For USB attached UPSs, it's almost always going to be a driver of usbhid-ups and a port of auto. All USB attached UPSs should act the same.

Finally, the line in upsd.conf is there to tell NUT it should make the UPS info available on all network interfaces. The default is localhost only, which is not very useful. You can also enter the network address of a specific interface if 0.0.0.0 (all interfaces) is not appropriate for your situation.

Configuring udev Rules

If you were to try starting the nut-upsd service at this point, it would complain loudly about permissions. See the example below.

 libusb1: Could not open any HID devices: insufficient permissions on everything
 No matching HID UPS found
 upsnotify: failed to notify about state 4: no notification tech defined, will not spam more about it
 Driver failed to start (exit status=1)

This is due to the USB device having the wrong permissions.

Below is an example of how to configure udev for the USB attached Smart-UPS 1000.

 alpine:/# cd /etc/udev/rules.d
 
 cat <<EOF >62-nut-usbups.rules
 ATTR{idVendor}=="051d", ATTR{idProduct}=="0002", MODE="664", GROUP="nut"
 EOF
 
 alpine:/# udevadm control --reload-rules

Take a look at the line that starts with ATTR{idVendor}=="051d", ATTR{idProduct}=="0002"

Thee are the vendor and product IDs found in the dmesg output above. The rest of the line tells udev what permissions and group ownership to use. It should be the same regardless of the UPS make and model, but the idVendor and idProduct will be unique to your UPS.

Note: There is also a file /lib/udev/rules.d/62-nut-usbups.rules that has information for all of the UPS models NUT knows about. You may be able to simply copy this rather than constructing your own rules from the information in the dmesg output.