Auto Shutdown on External Power Loss

I’m looking to simply initiate a “safe” shutdown of the rPi (3B+) on the event that external power is lost. I have been looking through docs and see ways to schedule events, but i don’t see any way to “react” to events such as a switch from external to battery power from the hat. Is there something existing that can accommodate this? (i imagine it is a common use case) Otherwise, is there any pin or “signal” i can monitor when the hat switches from external to battery power?

Hi @pfemiani,
This event is not yet available but we will consider this for the upcoming features.

You can use the get_working_mode function in the Python API for this.