How to Programmatically Get Remaining Power from Back UPS

command lineups

I just bought a Back-UPS.

So that if there is a power outage, this serves as some sort of a backup power.

I have set it up. It works, even when I plug it out.

But what I want to happen, is that the computer connected to it, will run maybe a cron job every ten minutes, to see how much battery is remaining, and if its below, say, 30%.
Then it implements a proper shutdown.

But I can't seem to find, how to determine programmatically, how much power is left on the ups.

Does anybody know how to get that information?

Best Answer

the upc is just plugged to the computer via electric plugin

You'll need to additionally plug it in to the computer via USB. There's a USB port somewhere on the UPS – hopefully standard Type-B these days, though APC has been known to use weird RJ45-ish (10P10C?) connectors for USB. Some other UPS types use a RS232 serial port.

Once the UPS shows up in lsusb (likely as some kind of serial or HID device), install some software that can talk to it. For APC specifically, apcupsd seems to be common; APC is also one of the many UPS types supported by nut (Network UPS Tools).

I've only ever used the latter software, but it has the upsc command to interrogate the UPS-monitor daemon about battery state (and many more parameters); I assume apcupsd has something similar, as that's kind of the whole point.

Most likely you won't even need a cronjob – the UPS monitoring software almost always has preemptive shutdown built-in.

Related Question