Skip to main content

Python API for PPC Smart Meter Gateways (SMGW)

Project description

py-ppc-smgw

Async Python client for PPC Smart Meter Gateways (BSI TR-03109 / German Smart Meter Gateway, PPC vendor implementation).

Talks to the consumer-facing HAN-API of a PPC SMGW: Digest authentication, meter readings, firmware versions, historic export, reboot.

Status: alpha. Used as the upstream client for the ha-ppc-smgw Home Assistant integration. API surface is stable for the implemented methods, but not yet 1.0.

Installation

pip install py-ppc-smgw

Or with uv:

uv add py-ppc-smgw

Requires Python 3.13+.

Quick start

import asyncio
import logging

import httpx

from py_ppc_smgw import PPCSMGWClient


async def main() -> None:
    logger = logging.getLogger("py-ppc-smgw")

    async with httpx.AsyncClient(verify=False) as http:
        async with PPCSMGWClient(
            host="https://192.0.2.1",
            username="user",
            password="secret",
            httpx_client=http,
            logger=logger,
        ) as client:
            # Firmware versions
            for fw in await client.get_firmware_versions():
                print(f"{fw.component}: {fw.version}")

            # Meter readings (current values)
            meters = await client.get_meters()
            readings = await client.get_meter_reading(meters[0])
            for obis, reading in readings.items():
                print(f"{obis}: {reading.value} @ {reading.timestamp}")


asyncio.run(main())

The client is an async context manager — __aenter__ calls login() and __aexit__ calls logout(). The PPC SMGW only allows a single concurrent session per user, so always logging out is important.

Implemented API surface

Method Purpose
login() / logout() Session lifecycle (also handled by async with)
get_meters() List installed meters
get_meter_reading(meter) Current OBIS readings for a meter
export_meter_values(meter, from, to) Historic interval values
get_firmware_versions() swversions action
selftest() / reboot() Reboot the gateway via self-test

Stubbed (raise NotImplementedError):

  • get_tariff_profiles()tariffform endpoint, planned
  • export_log_data(from, to) — log export, planned

Notes on gateway behaviour

  • Digest authentication with a fresh nonce per session. Stale nonces cached across HA-style 15-minute polls cause silent 200-but-empty responses on PPC firmware — the client always creates a fresh httpx.DigestAuth on every login().
  • Timestamps are local time, not UTC. The gateway returns naive datetimes in its own local zone. The library does not attach timezone info — consumers must localize at the boundary if needed.
  • Single session per user. Always log out (use async with and you get this for free).
  • Polling rate: 15-minute intervals are safe. Faster polling has been observed to crash the gateway (CGI process exhaustion, requires manual restart by the metering operator).

Development

git clone https://github.com/jannickfahlbusch/py-ppc-smgw
cd py-ppc-smgw
uv sync
uv run pytest
uv run ruff check py_ppc_smgw/ tests/
uv run mypy py_ppc_smgw/

License

Apache License 2.0 — see LICENSE.

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

py_ppc_smgw-0.1.2.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

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

py_ppc_smgw-0.1.2-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file py_ppc_smgw-0.1.2.tar.gz.

File metadata

  • Download URL: py_ppc_smgw-0.1.2.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for py_ppc_smgw-0.1.2.tar.gz
Algorithm Hash digest
SHA256 76df653cc18eea0518002518e0bda13012b287535de8305bbe4ad1c978131574
MD5 6eaa48fa2d8751689fcf7079b3fae15a
BLAKE2b-256 ba934608bdb37e2652a387769e422d22e8bb9e779eb374cecb5e6bb619180850

See more details on using hashes here.

File details

Details for the file py_ppc_smgw-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: py_ppc_smgw-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for py_ppc_smgw-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8f90e7d079a7d6e489bd716d3129f9e033054eb770b063ad33245c2fcdf92009
MD5 8a077d5ace504af3fccc92bc9fa7cc4a
BLAKE2b-256 385a014ae5fd342c8b7ebf161b5184efcf62a62e22455efe46a3478e46170b10

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