bench notes

Clean shutdowns for a Pi on a cheap UPS

The little line-interactive UPS under the desk has a USB port that shows up as a HID device. NUT's usbhid-ups driver talks to it fine, which means the Pi that runs Home Assistant can shut itself down before the battery gives out instead of corrupting another SD card.

Driver

# /etc/nut/ups.conf
[desk]
  driver = usbhid-ups
  port = auto
  pollinterval = 15

After upsdrvctl start, upsc desk should print battery charge and runtime. Mine reports runtime in seconds and it is optimistic by about a third, so I don't trust it for the shutdown decision.

Shutdown rule

Instead of the default low-battery flag I use upssched to start a five-minute timer when the UPS goes on battery and cancel it if power comes back. Short flickers are ignored; a real outage shuts the Pi down with plenty of margin.

AT ONBATT * START-TIMER onbatt 300
AT ONLINE  * CANCEL-TIMER onbatt

Tested by pulling the plug three times. Two clean shutdowns, and one where I had forgotten to enable nut-monitor. Now enabled.