Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

powerDown

powerDown is a Raspberry Pi systemd service that watches a UPS power-loss signal on a GPIO pin and shuts the Pi down if power is not restored within a configured grace period.

By default, the script watches BCM GPIO 24. When that pin falls low, it waits 12 seconds, runs sync, waits another 3 seconds for disk flushes, then schedules a normal OS shutdown.

Hardware Assumption

The UPS signal should be connected so that BCM GPIO 24 goes low when mains power is lost.

If your UPS uses another GPIO pin or you need a longer grace period, edit these constants in powerDown.py before installing:

PIN = 24
POWER_OUTAGE = 12
FLUSH_TO_DISK = 3
SHUTDOWN_TIME = "+1"

SHUTDOWN_TIME uses the normal shutdown time syntax. +1 schedules shutdown in one minute, which gives other services time to see the systemd scheduled shutdown state and close files cleanly. Pi Controller v1.2.3 watches for that scheduled shutdown and publishes a Watchkeeper power intent for Signal K apps.

Install From Git

On a fresh Raspberry Pi, install Git first:

sudo apt update
sudo apt install -y git

Clone this repository:

git clone https://github.com/mcdonaldajr/powerDown.git
cd powerDown

Install the GPIO Python package and set up the service:

sudo apt install -y python3-rpi.gpio
sudo ./install.sh

The installer copies the script to /home/pi/powerDown, installs the systemd unit at /etc/systemd/system/powerDown.service, enables it, and starts it.

To install somewhere else:

sudo INSTALL_DIR=/opt/powerDown ./install.sh

Manage The Service

Check whether the service is running:

sudo systemctl status powerDown.service

View logs:

sudo journalctl -u powerDown.service -f

Restart after editing:

sudo ./install.sh

Stop or disable the service:

sudo systemctl stop powerDown.service
sudo systemctl disable powerDown.service

Files

  • powerDown.py - GPIO monitor and shutdown logic.
  • powerDown.service - systemd service template used by the installer.
  • install.sh - installer for Raspberry Pi OS.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages