Setup UPS with Intelligent Power Loss Recovery

What is the problem?

Is there a way to setup OctoPrint to monitor a UPS and essentially save the current progress when the UPS falls below a certain percent or remaining runtime?

I'd like to connect a UPS and have it where OctoPrint continues as usual until the UPS hits 50% or 5 mins remaining. At this point, OctoPrint would finish the current layer, then preform some preset gcode that would move the extruder away from the print and up a little bit, turn off heaters and wait until the extruder falls below 50 degs. Then OctoPrint would safely shut down the RPi.

When the power comes back on, I can turn on the printer again (RPi boots automatically), run some custom gcode to get ready to finish print (homing since mine is a Delta printer, heat up everything again, ensure its set to absolute positioning), then begin printing the next layer again.

The benefit of this method is that it stops the print at the end of a layer, giving the best possible chance of having a successful recovery.

I have looked at available plugins, but the only thing I can find is a plugin that simply displays the UPS status in the main bar.

Systeminfo Bundle (161.4 KB)

Additional information about your setup

Rasberry Pi 4
OctoPrint v1.6.1
OctoPi 0.18.0
FLSun Q5 printer with a SKR Turbo v1.4 board and a BTT TFT43 screen
Marlin bugfix-2.0.x updated as of Wed Sep 15, 2021 (try to update weekly)

The UPS plugin allows you to configure pausing based on a threshold and perform specific gcode actions in your pause/resume scripts. No feature or plans to add a feature to finish the layer though because not every layer can be completed within battery limits.

Would that pausing survive the UPS powering off? Or would the print still be lost if the outage lasted too long?

If OctoPrint remains running, then the pause would still be there. But that's unlikely, so as soon as the Pi turns off the pause state is lost (& therefore the print).