Skip to main content

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

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:

  1. POWERCTL_CONFIG environment variable
  2. /etc/powerctl/config.json
  3. /etc/powerctl/relay.json
  4. /etc/relay.json
  5. /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 devices is the device name.
  • Each device value is a dictionary with optional info.
  • Optional hash can be provided and used as an alternative identifier in CLI.
  • Duplicate hashes are rejected with an explicit config error.
  • Relay transport is defined as relay dictionary with keys:
    • gpio (BCM GPIO number)
    • invert (boolean inversion flag)
  • Shell transport is defined as shell dictionary with keys:
    • on (shell command to power on)
    • off (shell command to power off)
    • status (optional shell command to query status)
    • sudo (optional, default false)
  • Arduino transport is defined as arduino dictionary and supports two forms:
    • Direct serial (preferred):
      • port (e.g. /dev/ttyUSB0)
      • baud (default 9600)
      • channel (channel/index argument)
      • format (optional command template, default "{channel} {op}")
      • on / off (optional tokens, default on / off)
      • status_op (optional serial status token)
      • newline (optional, append \n when true)
      • pre_delay / post_delay / timeout (optional serial timing)
    • Direct commands:
      • on_command / off_command (full command lines)
    • Sender script compatibility:
      • send + channel (+ optional on/off)
    • Optional:
      • status_command (status query command)
      • sudo (default false)

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 list still works and reports backend availability.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

powerctl_inthemoon-0.1.1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

powerctl_inthemoon-0.1.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

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

Hashes for powerctl_inthemoon-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0f860239e968cb32dd3338c153b5948dec631ebc6d5d8129ef4c449065348607
MD5 1fb814e2f3a8dc5ed93896bd81ea3e7d
BLAKE2b-256 e9314081a7d7908080b4f80dc41ffcf99bb79031885515d9cc7c95ed5c0cf2ad

See more details on using hashes here.

File details

Details for the file powerctl_inthemoon-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for powerctl_inthemoon-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f5edeafa0a7f59bad59bbad9d34f735b1b43a65eaeffae3d97ba2ba189b98b35
MD5 ae589628bcf9e31a1bd92d9124d5b4ce
BLAKE2b-256 a2e8bea1bed45792ba78de92dcc2fdf472edb5e806b1895b6a2f6c58a0a525c2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page