← Back to blog

Teaching a Dumb UPS to Speak NUT: Reverse-Engineering USB HID With an ESP32

Brandon Schaefer··Updated November 24, 2026·5 min read·

My NUT setup already watched one UPS over the network. The other one only talks USB, and NUT's own driver doesn't get along with it - so I reverse-engineered its protocol and taught an ESP32 to pretend to be a NUT server.

Table of contents

I already monitor the UPS protecting the core of the homelab the normal way: it's SNMP-attached, NUT's upsd watches it over the network, and Home Assistant reads the result like any other sensor. That's the easy case. The UPS I actually wanted to add next wasn't on the network at all - it only exposes a USB port, and it isn't one of the models NUT's own usbhid-ups driver gets along with cleanly. I had three real options: buy a UPS NUT already likes, run a USB cable to whatever box I wanted to treat as the bridge and leave it permanently plugged in just to forward one device's status, or actually find out what the UPS was saying over USB and build something small enough to live next to it. I took the third one, mostly because it sounded more interesting than the other two, and because I didn't want a spare computer parked next to a power strip forever just to translate one protocol into another.

Reading the UPS's mind before writing a line of firmware

A USB UPS that isn't officially supported doesn't mean its protocol is secret - it means nobody's written down a clean map of it. USB HID devices describe themselves in Report IDs, and this APC unit exposes battery charge, input voltage, load percentage, and online/on-battery status as HID Feature reports, each with its own ID and its own scale factor. The honest way to find out what each one means is to capture the raw bytes and cross-reference them against something that already knows how to decode them. I ran USBPcap to capture every control transfer on the wire, and in parallel ran NUT's own usbhid-ups driver against the same UPS in debug mode, which prints exactly which Report ID it just read and what value it decoded from it. Lining the two logs up side by side turned "unknown byte soup" into an actual field map: this Report ID is battery charge, scaled by this factor; this one is input voltage; this one is status, encoded as a bitmask.

Not every field came out clean. One - load percentage - never showed up in a capture I could be fully sure of, so I inferred its scale factor by pattern-matching against the other confirmed percent-fields instead of reading it off a verified raw sample. I wrote that down as a known risk before touching a soldering iron: if it was wrong, the number would be obviously, comically wrong - something like 2700% instead of 27% - not subtly off in a way that's hard to catch.

Why an ESP32 instead of a bridge script

Once I had the field map, the actual bridge code could have lived almost anywhere - a Python script on a Linux box, a cron job, whatever. I specifically didn't want it running on a general-purpose machine, because the whole point was to stop needing one sitting next to this particular UPS. An ESP32-S3 can act as a USB host, has enough horsepower to poll a HID device and run a small TCP server, and costs a lot less than the UPS's own replacement battery. If it works, it just sits there indefinitely, sipping a few watts, with nothing else to maintain.

The firmware uses ESP-IDF's native usb_host driver rather than its higher-level HID class driver, because the HID class driver's job is normal human-interface devices - keyboards, mice - and it abstracts away exactly the kind of raw GET_REPORT(Feature, reportID) control transfer this UPS's protocol depends on. Going one layer lower meant more code to write, but direct control over the exact transfers the field map called for.

The one real hardware surprise: USB host mode means the ESP32 has to supply 5V (VBUS) to the UPS's USB port, not just receive data from it - and plenty of ESP32-S3 dev boards are wired for device mode only, expecting to be the one that's powered. Not every board advertising "USB-OTG" actually sources power on that port; worth confirming before ordering one, not after.

Making it look like a NUT server, not a translator

The easy way to get this data into Home Assistant would have been MQTT, or a REST endpoint and a custom integration. I did neither, because NUT already has a wire protocol - plain text, over port 3493 - that every NUT client already speaks: upsc, upsmon, and Home Assistant's own built-in NUT integration. So instead of inventing a new protocol and a new way for Home Assistant to understand it, the firmware just speaks NUT's actual protocol directly: it polls the UPS over USB, and answers queries exactly the way a real upsd would. Point Home Assistant's existing NUT integration at the board's address and port, and it has no idea it isn't talking to a real UPS server - which is exactly the point.

It's read-only for now, deliberately. NUT's protocol also supports writes - toggling the beeper, kicking off a self-test, setting a shutdown delay - and none of those are implemented yet. A UPS is the thing standing between a power blip and actual data loss; it's not where I want to find out my write-path logic has a bug.

First flash

The firmware compiled clean well before any of this touched real hardware - zero warnings on a real ESP-IDF toolchain. But a clean compile proves nothing about whether the field map is actually right, and the one field flagged as a guess - load percentage - was the first thing checked the moment it booted against the real UPS. It came back as a normal, boring percentage, not triple digits. Sometimes the inferred guess is just correct.

Home Assistant's NUT integration found it immediately once pointed at it, and now there are plain sensor entities - battery charge, input voltage, load, and online/on-battery status - sitting right alongside the other UPS's, updating continuously. Right now it's reporting a full charge, a light load, and "online" - exactly as boring as a UPS should be on a good day, which is the entire goal.

What's next

Staying read-only for now feels like the right default, not a missing feature. If Home Assistant ever needs to trigger a scheduled self-test or react to a real shutdown-delay signal, that's a deliberate follow-up, not an afterthought - and it can wait until the read-only side has proven itself over more than a few days of uptime.