Skip to main content

rpi-bad-power-ng

CI Python 3.12+ License: MIT

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_power compatible — preserves new_under_voltage(), UnderVoltage.get(), and all legacy constants/classes.
  • Hardened sysfs discovery & error handling — safely skips unreadable/hotplugged hwmon* entries, verifies in0_lcrit_alarm readability, strips whitespace cleanly, and raises structured RpiBadPowerError (subclass of OSError).
  • Event-driven kernel push (sysfs_notify) — UnderVoltageNew.async_watch() monitors in0_lcrit_alarm via Linux POLLPRI | POLLERR so transient voltage sags are caught immediately instead of missed between 30-second polls.
  • Full get_throttled bitmask telemetry — decode active and sticky under-voltage, frequency-capping, throttling, and soft temperature flags via ThrottledStatus / 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-hwmon via /sys/class/hwmon/hwmon*/in0_lcrit_alarm (raspberrypi/linux#2706) — supports both synchronous polling and real-time sysfs_notify push 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

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)

Source distribution for rpi-bad-power-ng 0.2.0
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)

Table of built distributions (wheels) for rpi-bad-power-ng 0.2.0
File Interpreter ABI Platform Actions
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 log

Release 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 log

Security 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.

Select from 2 files

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 log

A 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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page