rpi-bad-power-ng
Next-generation, zero-dependency Python library to detect Raspberry Pi bad power supply (under-voltage) and firmware throttling directly from Linux sysfs.
rpi-bad-power-ng is an actively maintained, independent continuation of shenxn/rpi-bad-power. It keeps the rpi_bad_power Python package name and full API compatibility as a 100% drop-in replacement for Home Assistant Core's built-in Raspberry Pi Power Supply Checker (rpi_power) integration.
Highlights
- Zero third-party runtime dependencies — pure Python standard library (
>=3.12), PEP 561 typed (py.typed). - 100% Home Assistant
rpi_powercompatible — preservesnew_under_voltage(),UnderVoltage.get(), and all legacy constants/classes. - Hardened sysfs discovery & error handling — safely skips unreadable/hotplugged
hwmon*entries, verifiesin0_lcrit_alarmreadability, strips whitespace cleanly, and raises structuredRpiBadPowerError(subclass ofOSError). - Event-driven kernel push (
sysfs_notify) —UnderVoltageNew.async_watch()monitorsin0_lcrit_alarmvia LinuxPOLLPRI | POLLERRso transient voltage sags are caught immediately instead of missed between 30-second polls. - Full
get_throttledbitmask telemetry — decode active and sticky under-voltage, frequency-capping, throttling, and soft temperature flags viaThrottledStatus/get_throttled_status().
Installation
uv add rpi-bad-power-ng
Or with pip:
pip install rpi-bad-power-ng
Compatibility
Requires Linux kernel 4.14+ on Raspberry Pi hardware (including Home Assistant OS and read-only Docker containers, without vcgencmd or root privileges):
- Linux 4.19+ (through Raspberry Pi 5):
raspberrypi-hwmonvia/sys/class/hwmon/hwmon*/in0_lcrit_alarm(raspberrypi/linux#2706) — supports both synchronous polling and real-timesysfs_notifypush watching. - Linux 4.14–4.19 (legacy):
/sys/devices/platform/soc/soc:firmware/get_throttled(raspberrypi/linux#2397).
Usage
Synchronous polling (Home Assistant drop-in API)
from rpi_bad_power import RpiBadPowerError, new_under_voltage
under_voltage = new_under_voltage()
if under_voltage is None:
print("System not supported.")
else:
try:
if under_voltage.get():
print("Under-voltage detected!")
else:
print("Voltage is normal.")
except RpiBadPowerError as err:
print(f"Failed to read power status: {err}")
Real-time async push notifications (sysfs_notify)
import asyncio
from rpi_bad_power import new_under_voltage
async def main() -> None:
under_voltage = new_under_voltage()
if under_voltage is None:
print("System not supported.")
return
if under_voltage.supports_push:
async with under_voltage.async_watch() as watcher:
async for is_under_voltage in watcher:
print(f"Under-voltage state: {is_under_voltage}")
else:
print(f"Legacy fallback (polling only): {under_voltage.get()}")
asyncio.run(main())
Full get_throttled bitmask decoding
from rpi_bad_power import ThrottledStatus, get_throttled_status
status = get_throttled_status()
if status is not None:
print(f"Active issues: {status.any_active}, occurred: {status.any_occurred}")
print(f"Under-voltage active={status.under_voltage}, throttled={status.throttled}")
# Or parse a raw hexadecimal bitmask directly (e.g. from vcgencmd get_throttled):
decoded = ThrottledStatus.from_hex("0x50005")
assert decoded.under_voltage and decoded.throttled_occurred
Development
uv sync --all-groups
uv run ruff check .
uv run ruff format --check .
uv run mypy rpi_bad_power tests
uv run pytest
Credits
- Originally created by @shenxn in
shenxn/rpi-bad-power. - Early implementation inspired by
custom-components/sensor.rpi_powermaintained by @swetoast. - Maintained as
rpi-bad-power-ngby @marcomsousa under the MIT License.
Metadata
Release files for rpi-bad-power-ng 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rpi_bad_power_ng-0.2.0.tar.gz | 57.9 kB | With provenance | Details for rpi_bad_power_ng-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rpi_bad_power_ng-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for rpi_bad_power_ng-0.2.0-py3-none-any.whl |
Total release size: 70.1 kB
Release files / rpi_bad_power_ng-0.2.0.tar.gz
| Download URL | rpi_bad_power_ng-0.2.0.tar.gz |
|---|---|
| Size | 57.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
25bc8f2c7cb65bafebfc4630f7a1141c10bf11039b4d12323c10f56758a3c619
|
|
BLAKE2b-256 checksum How to use checksums |
dc310fb067093dd5940ca8c49121352cfc64db96cdcf173c077b75e63b815813
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logRelease files / rpi_bad_power_ng-0.2.0-py3-none-any.whl
| Download URL | rpi_bad_power_ng-0.2.0-py3-none-any.whl |
|---|---|
| Size | 12.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fb896645e5c0b2584be3f9c80a8a79111a6e2a29e0f9b49ae20114d126815e63
|
|
BLAKE2b-256 checksum How to use checksums |
1a30750ed2f2b5e150c5c075d0e4bf2f7c9364136fed8ef2e4344457e95e4321
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logSecurity for rpi-bad-power-ng 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for rpi_bad_power_ng-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.