Skip to main content

Async Python library for communicating with EARN-E P1 energy meters via UDP

Project description

earn-e-p1

Async Python library for communicating with EARN-E P1 energy meters via UDP.

The EARN-E P1 meter reads a smart meter's P1 port and broadcasts real-time energy data via UDP on the local network. This library listens for those broadcasts and provides parsed device data.

Installation

pip install earn-e-p1

Usage

Persistent listener

For long-running applications (e.g., Home Assistant integrations) that need continuous updates:

import asyncio
from earn_e_p1 import EarnEP1Listener, EarnEP1Device

def on_update(device: EarnEP1Device, raw: dict) -> None:
    print(f"Power: {device.data.get('power_delivered')} kW")
    print(f"Serial: {device.serial}")

async def main() -> None:
    listener = EarnEP1Listener()
    listener.register("192.168.1.100", callback=on_update)
    await listener.start()

    try:
        await asyncio.sleep(3600)  # listen for 1 hour
    finally:
        await listener.stop()

asyncio.run(main())

The listener supports multiple devices — call register() for each device IP. Packets are demultiplexed by source IP and each device maintains its own merged state.

Discover devices

Find EARN-E devices on the network:

from earn_e_p1 import discover

devices = await discover(timeout=10)
for device in devices:
    print(f"Found {device.host} (serial: {device.serial})")

Validate a specific host

Check if a specific IP is an EARN-E device:

from earn_e_p1 import validate

device = await validate("192.168.1.100", timeout=10)
if device:
    print(f"Confirmed: {device.serial}")

Discover/validate while a listener is running

If a listener is already active, use the instance methods to avoid port conflicts:

# Discover using the active socket
devices = await listener.discover(timeout=10)

# Validate using the active socket
device = await listener.validate("192.168.1.100", timeout=10)

Data Model

The callback receives two arguments:

  • device (EarnEP1Device) — accumulated device state with merged data from all packets
  • raw (dict) — the raw packet as received
@dataclass
class EarnEP1Device:
    host: str                          # Device IP address
    serial: str | None = None          # Serial number (set once from first full telegram)
    model: str | None = None           # Device model
    sw_version: str | None = None      # Firmware version
    data: dict[str, Any] = field(...)  # Merged sensor data from all packets

The device sends two types of UDP broadcasts:

Type Keys Frequency
Realtime power_delivered, power_returned, voltage_l1, current_l1 ~1s
Full telegram energy_delivered_tariff1/2, energy_returned_tariff1/2, gas_delivered, wifiRSSI, serial, model, swVersion ~10s

The library merges all packets into device.data, so it always contains the latest value for every key.

License

MIT

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

earn_e_p1-0.1.0.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

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

earn_e_p1-0.1.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: earn_e_p1-0.1.0.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for earn_e_p1-0.1.0.tar.gz
Algorithm Hash digest
SHA256 382cb80ae8c45661b91254e2ff6549446992b53b69832f2290f26a502bc45a93
MD5 d1c3ea865fd7391875d70d25da296c9c
BLAKE2b-256 db81c0a59cf4b160672f361c4be526108594ab49ae680b3e2e5410b79550a7e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for earn_e_p1-0.1.0.tar.gz:

Publisher: publish.yml on Miggets7/earn-e-p1

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: earn_e_p1-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for earn_e_p1-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 40709b3b759730c3877eb76618888eaead65559c2a7491704dbc150284c4f7a7
MD5 f5470a68a108b95986d933af4f6e1a30
BLAKE2b-256 176d451a048e6d57b612150f9298b4e903b29283476c7a99dc7a0a8c288c5295

See more details on using hashes here.

Provenance

The following attestation bundles were made for earn_e_p1-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Miggets7/earn-e-p1

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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