# Auto Shutdown on External Power Loss

**URL:** <https://community.sixfab.com/t/auto-shutdown-on-external-power-loss/555>\
**Category:** Sixfab Power HAT & Software\
**Created:** [July 21, 2020, 5:38pm UTC](https://community.sixfab.com/t/auto-shutdown-on-external-power-loss/555 "2020-07-21T17:38:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pfemiani](https://community.sixfab.com/user_avatar/community.sixfab.com/pfemiani/32/331_2.png) [@pfemiani](https://community.sixfab.com/u/pfemiani)\
**Post date:** [July 21, 2020, 5:38pm UTC](https://community.sixfab.com/t/auto-shutdown-on-external-power-loss/555/1 "2020-07-21T17:38:25Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ensar](https://community.sixfab.com/user_avatar/community.sixfab.com/ensar/32/8_2.png) [@ensar](https://community.sixfab.com/u/ensar)\
**Post date:** [July 28, 2020, 4:24pm UTC](https://community.sixfab.com/t/auto-shutdown-on-external-power-loss/555/2 "2020-07-28T16:24:19Z")

</div>

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

> [@pfemiani](#):
>
> Otherwise, is there any pin or “signal” i can monitor when the hat switches from external to battery power?

You can use the [get\_working\_mode](https://htmlpreview.github.io/?https://raw.githubusercontent.com/sixfab/sixfab-power-python-api/master/docs/power_api.html#power_api.power_api.SixfabPower.get_working_mode) function in the Python API for this.

---

<div class="post-metadata">

**Author:** ![shawnj007](https://community.sixfab.com/user_avatar/community.sixfab.com/shawnj007/32/982_2.png) [@shawnj007](https://community.sixfab.com/u/shawnj007)\
**Post date:** [November 15, 2020, 6:33pm UTC](https://community.sixfab.com/t/auto-shutdown-on-external-power-loss/555/3 "2020-11-15T18:33:07Z")

</div>

Hi @ensar and @pfemiani,

get\_working\_mode is ok, but under high power usage (while plugged in), the system will still report this condition as BATTERY\_POWERED. It is appropriate to double check the output of api.get\_input\_power() to verify that power has _actually_ been removed.

Something like:  
if api.get\_working\_mode() == Definition.BATTERY\_POWERED and api.get\_input\_power() \<= 1.:  
(… create and schedule hard shutdown event)  
api.hard\_power\_off()

I run this as part of a 'watch python3 … ’ command so that it is done every 2 seconds (by default). Works great! Check out my other post for a hardware boot work around, if you need that too.

S
