Package: tripplite
tripplitePython USB interface and command-line tool for TrippLite UPS battery backups.BackgroundTrippLite offersUI softwarefor monitoring its batteries. However, most of its batteries don't have
network access, and the existing TrippLite software requires a local install.I wanted to monitor the UPS from a remote headless Linux server, so I wrote
this tool.Supported HardwareThis has been exclusively tested on the TrippLite SMART1500LCD UPS. It will
likely work on similar firmware but there is a known communication issue with
some other TrippLite models (seenumat/tripplite#3).Uselsusbto check.09ae:2012should work, while09ae:3016may not.Installationapt install gcc libusb-1.0-0-dev libudev-devpip install trippliteConnect a USB cable from the UPS to your headless server, and you should be
ready to run. If you don't want to run as root, seeNote on Permissionsbelow.Command Line$ tripplite
{
    "config": {
        "frequency": 60,  # Hz
        "power": 1500,  # VA
        "voltage": 120  # V
    },
    "health": 100,  # %
    "input": {
        "frequency": 59.7,  # Hz
        "voltage": 117.2  # V
    },
    "output": {
        "power": 324,  # W
        "voltage": 117.2  # V
    },
    "status": {
        "ac present": true,
        "below remaining capacity": true,
        "charging": false,
        "discharging": false,
        "fully charged": true,
        "fully discharged": false,
        "needs replacement": false,
        "shutdown imminent": false
    },
    "time to empty": 1004  # s
}To use in shell scripts, parse the json output with something likejq. For example,tripplite | jq '.status."ac present"'will return whether or not the unit
detects AC power.PythonIf you'd like to link this to more complex behavior (e.g. data logging,
text alerts), consider using a Python script.fromtrippliteimportBatterywithBattery()asbattery:print(battery.get())Thestatevariable will contain an object with the same format as above. Usestate['status']['ac present']andstate['status']['shutdown imminent']for
alerts, and consider logging voltage, frequency, and power.If you are logging multiple batteries, you will need to handle each connection
separately.fromtrippliteimportBattery,battery_pathsforpathinbattery_paths:withBattery(path)asbattery:print(battery.get())These paths are unfortunately non-deterministic and will change on each
iteration.For long polling, you can improve stability by keeping connections open as long
as possible and reconnecting on error. For example:state=Nonedefread_batteries(check_period=5):"""Read battery and reopen in error. Use for long polling."""battery=Battery()battery.open()whileTrue:time.sleep(check_period)try:state=battery.get()exceptOSError:logging.exception(f"Could not read battery{battery}.")battery.close()battery.open()An example for multiple batteries can be found innumat/tripplite#6.Note on PermissionsTo read the TrippLite, you need access to the USB port. You have options:Run everything as rootAdd your user to thedialoutgroup to accessallserial portsCreate a group restricted to accessing TrippLite USB devices throughudevFor the last option, the rule looks like:echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="09ae", GROUP="tripplite"' > /etc/udev/rules.d/tripplite.rulesudevadm control --reload-rulesPrometheus ExporterThis package offers an extra install to include aPrometheus Exporterwhich allows for data collection into a prometheus time series database. Esentially it's a smallHTTPserver that allows
Prometheus toscrapegrabbing metrics at a configurable period.Installpip install tripplite[exporter]This adds theprometheus_clientdependency.You can then manually run thetriplite-exportercli or use thetripplite_exporter.servicesystemd unit file to have systemd run and supervise the process.Failure ModeThe script will try to close and reopen the USB serial connection to the device on anOSError. If an open fails,
the script will exit with the return code of 2.