When I read the article from Brandon Lee about the top 10 automation scripts for every home lab and came across point 9 about a ‘UPS-triggered graceful shutdown script’, I thought what a great idea! Yet how about using apcupsd since I have an APC UPS.
And how about making the script fit an unlimited number of Proxmox hosts that would be spaced out based on the % of the remaining battery throughout the discharging process? And what if the power comes back on during the process, could we not automated an automated power on? Or is that overly ambitious? Let’s dive and see 😇
What are the goals
This guide will walk you through a complete, end-to-end solution for automating your APC UPS with a Raspberry Pi. We’ll go far beyond a simple shutdown script. You will learn how to build a robust system that:
- Monitors your UPS and triggers shutdowns at dynamic battery levels.
- Gracefully shuts down multiple Proxmox hosts in a staggered, controlled-chaos-free order.
- Sends rich, detailed HTML email alerts.
- Pushes the UPS status to Uptime Kuma for proactive monitoring.
- Automatically wakes your hosts with Wake-on-LAN when the power is restored.
- Manages all your custom scripts professionally using a GitOps workflow, the same method used by modern DevOps teams.
This is the ultimate “set-it-and-forget-it” power management solution for your homelab.
Pre-requisites:
- 1 or more Proxmox hosts
- A Raspberry Pi (RPi) – ideally v4+ or any other Linux-based device (Debian / Ubuntu flavors). In my case, the RPi serves the purposes of acting as the Proxmox Backup Server (PBS), which is not an obstacle, nor does it play any role in this tutorial.
- APC UPS unit that you connect via USB to your RPI
- A free mailbox to use SMTP to send emails from
Install required software
- Firstly, once you have connected your UPS, check that the RPi can see it:
lsusb
- Install the APC driver
sudo apt update sudo apt install apcupsd -y
Now let’s head over to configuring the apcupsd service and email alerting!
