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.0.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.0-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_ppc_smgw-0.1.0.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":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for py_ppc_smgw-0.1.0.tar.gz
Algorithm Hash digest
SHA256 40bc4d6391dd4ddbb9650427025d58cafd092118573f1c22eba122d8db44270d
MD5 8048618c1b5a80ab55368c2343b9195f
BLAKE2b-256 a48e3baecd3358bf4d6b2e5c6ba72bbd5e0be13ce65bcf4d47fec556d381b0a6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_ppc_smgw-0.1.0-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":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for py_ppc_smgw-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c7571138224a0c70ea22b2001511963b77e1f7a14995b47fa78cbfdf5fe5a717
MD5 79d5931a6062d3c7122ff8c7de4c8fa7
BLAKE2b-256 6259093e60737677af04f1d9908065e6b1a4f7ea55f1013614e6253b327733c9

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