My Pi is powered from the PSU of the printer, with a step-down convertor. Flipping the printer switch means power-off from the Octoprint server as well.
I was looking for a safe and convenient way to accomplish power-off. We have plugins that use Tasmota / ESPhome Sonoff plugs to shutdown the Printer/Octoprint safely. I went a different route: I built all the logic straight into the ESP8266 in the plug!
This means that no plugins, special GCODE or configuration is needed in Octoprint. The plug monitors print state, temperature and initiates a shutdown of Octoprint with delayed power-off, when you press the plug button, or when you tell it to do so after a print.
Becuase it is not a plugin, I called it a "plugout"... So OctoPlugout was born.
It is described here: https://github.com/ruedli/OctoPlugout