System power control CLI with relay support
Project description
powerctl
Systemwide power control CLI for small devices. It currently supports Raspberry Pi GPIO relays and generic shell-command transport from a config file.
Requirement
NormalPyRunnerfrom PyPI is used for all shell command execution.- Package: https://pypi.org/project/NormalPyRunner/
System-wide install from source
On modern Debian/Ubuntu (PEP 668), install system-wide with:
sudo python3 -m pip install --break-system-packages .
Helper script (same result):
sudo ./install.sh
Verify:
powerctl list
Reinstall after source updates:
sudo python3 -m pip install --break-system-packages --force-reinstall .
Raspberry Pi GPIO backend
If you use relay control via GPIO, install a GPIO Python package:
sudo apt update
sudo apt install -y python3-rpi.gpio
On newer Raspberry Pi OS images (Bookworm), the compatibility package may be used:
sudo apt install -y python3-rpi-lgpio
Optional: allow non-root GPIO access, then re-login:
sudo usermod -aG gpio "$USER"
Config file
Default lookup order:
POWERCTL_CONFIGenvironment variable/etc/powerctl/config.json/etc/powerctl/relay.json/etc/relay.json/etc/relayctl/relay.json
Install a system config:
sudo mkdir -p /etc/powerctl
sudo cp powerctl.sample.json /etc/powerctl/config.json
Schema:
- Top-level key is
devices(dictionary). - Each key in
devicesis the device name. - Each device value is a dictionary with optional
info. - Optional
hashcan be provided and used as an alternative identifier in CLI. - Duplicate hashes are rejected with an explicit config error.
- Relay transport is defined as
relaydictionary with keys:gpio(BCM GPIO number)invert(boolean inversion flag)
- Shell transport is defined as
shelldictionary with keys:on(shell command to power on)off(shell command to power off)status(optional shell command to query status)sudo(optional, defaultfalse)
- Arduino transport is defined as
arduinodictionary and supports two forms:- Direct serial (preferred):
port(e.g./dev/ttyUSB0)baud(default9600)channel(channel/index argument)format(optional command template, default"{channel} {op}")on/off(optional tokens, defaulton/off)status_op(optional serial status token)newline(optional, append\nwhen true)pre_delay/post_delay/timeout(optional serial timing)
- Direct commands:
on_command/off_command(full command lines)
- Sender script compatibility:
send+channel(+ optionalon/off)
- Optional:
status_command(status query command)sudo(defaultfalse)
- Direct serial (preferred):
CLI
Mirror of relayctl behavior:
powerctl list
powerctl status
powerctl status <device-name-or-hash>
powerctl start <device-name-or-hash>
powerctl stop <device-name-or-hash>
powerctl restart <device-name-or-hash>
powerctl --no-wait start <device-name-or-hash>
Compatibility aliases are still accepted:
on/off/reset and 1/0.
You can also provide a custom config path:
powerctl --config ./my-devices.json list
Notes on hardware availability
- The CLI always installs, even on hosts without GPIO hardware.
- Relay control requires
RPi.GPIO. - Shell control runs configured command strings via
pyrunner(optionally with sudo). - Arduino control runs configured sender/direct commands via
pyrunner. - If hardware/tooling is unavailable,
powerctl liststill works and reports backend availability.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file powerctl_inthemoon-0.1.1.tar.gz.
File metadata
- Download URL: powerctl_inthemoon-0.1.1.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f860239e968cb32dd3338c153b5948dec631ebc6d5d8129ef4c449065348607
|
|
| MD5 |
1fb814e2f3a8dc5ed93896bd81ea3e7d
|
|
| BLAKE2b-256 |
e9314081a7d7908080b4f80dc41ffcf99bb79031885515d9cc7c95ed5c0cf2ad
|
File details
Details for the file powerctl_inthemoon-0.1.1-py3-none-any.whl.
File metadata
- Download URL: powerctl_inthemoon-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5edeafa0a7f59bad59bbad9d34f735b1b43a65eaeffae3d97ba2ba189b98b35
|
|
| MD5 |
ae589628bcf9e31a1bd92d9124d5b4ce
|
|
| BLAKE2b-256 |
a2e8bea1bed45792ba78de92dcc2fdf472edb5e806b1895b6a2f6c58a0a525c2
|