Automatically turn a power outlet off and on again when a health check fails.
- .NET 7 runtime or later
- Kasa smart outlet, such as the EP10 or KP125
Pre-built executables are provided for Windows (x64) and Linux (x64 and ARM).
Tested on a Raspberry Pi 2 Model B running Raspbian 11 Bullseye.
- Download the Linux ARM build from the latest release.
- Unzip and move the executable.
unzip PowerCycler-linux-arm.zip sudo mv PowerCycler /usr/local/bin/ sudo chmod +x /usr/local/bin/PowerCycler
- Move the configuration file.
sudo mv powercycler.json /usr/local/etc/
- Install the systemd service unit file.
sudo mv powercycler.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable powercycler.service
- Download the Windows build from the latest release.
- Unzip it to a folder such as
C:\Program Files\PowerCycler\
. - Open PowerShell elevated and run
New-Service -Name "PowerCycler" -DisplayName "PowerCycler" -Description "Turn it off and on again." -BinaryPathName "C:\Program Files\PowerCycler\PowerCycler.exe" -DependsOn Tcpip
Edit the powercycler.json
configuration file.
All fields are required.
Field | Example value | Description |
---|---|---|
healthCheckUrl |
https://aldaviva.com or tcp://aldaviva.com:22 |
The URL of the process being monitored to check and see if it's healthy. For http and https schemes, it sends a GET request and requires a status code in [200, 300). Redirections are not followed.For the tcp scheme, it opens a socket connection to the URL's hostname and port. |
healthCheckTimeoutSec |
5 |
How long, in seconds, the process being monitored has to send a health check response before that check fails. Should be shorter than healthCheckFrequencySec . |
healthCheckFrequencySec |
60 |
How often, in seconds, to send health check requests. |
outletHostname |
bragi.outlets.aldaviva.com or 192.168.1.100 |
The FQDN or IP address of a Kasa smart outlet to turn off and on when the process is deemed to be offline and must be restarted. |
minOfflineDurationBeforeRestartSec |
600 |
How long, in seconds, to go without any successful health check responses before the outlet is power cycled. Should be longer than healthCheckFrequencySec . |
resumeHealthCheckAfterRestartSec |
300 |
How long, in seconds, to wait after power cycling before checking health again. Should be longer than it takes your process to become healthy after a reboot. |
Logging.LogLevel.Default |
Information |
Minimum severity of log events to emit. Values are Trace , Debug , Information , Warning , Error , Critical , and None .View logs using sudo journalctl -u powercycler on Linux or Event Viewer on Windows. |
With the above example values, this service will send an HTTP GET request to https://aldaviva.com
every 60 seconds.
- If it has returned at least one 200 OK response in the last 600 seconds, this service will do nothing.
- Otherwise, if it has done nothing in the past 600 seconds but return errors (such as 400, 500, or 503) or take more than 5 seconds to respond, then this service will turn off the outlet at 192.168.1.100, wait 2 seconds, and then turn the outlet back on again. This service will then wait 300 seconds before finally starting the health check loop again.
sudo systemctl start powercycler.service
Start-Service PowerCycler