Skip to main content

pyhems

Python Version License

ECHONET Lite library for Home Energy Management System (HEMS).

🇯🇵 日本語ドキュメント

Features

  • ECHONET Lite frame encoding/decoding
  • UDP multicast device discovery
  • Async runtime client with event subscription
  • Device state management with DeviceManager
  • Adaptive poll scheduler for non-notifying properties via PropertyPoller
  • Entity definitions based on MRA data
  • Full type hints (py.typed)

Requirements

  • Python 3.14+
  • bidict>=0.23.0

License

MIT License

Installation

pip install pyhems

Quick Start

import asyncio
from pyhems import EOJ, HemsClient, HemsFrameEvent, HemsInstanceListEvent

async def main():
    client = HemsClient(interface="0.0.0.0")
    await client.start()

    def on_event(event):
        if isinstance(event, HemsInstanceListEvent):
            print(f"Node: {event.node_id}, Instances: {event.instances}")
        elif isinstance(event, HemsFrameEvent):
            print(f"Frame from {event.node_id}: {event.frame}")

    unsubscribe = client.subscribe(on_event)
    await client.probe_initial_nodes()
    client.start_periodic_discovery()

    # Read properties from a discovered device
    # node_id = "fe..."  # obtained from HemsInstanceListEvent
    # props = await client.get(node_id, EOJ(0x013001), [0x80, 0xB3])

    # Write a property (example: power ON)
    # await client.set_property(node_id, EOJ(0x013001), 0x80, b"\x30")

    await asyncio.sleep(60)
    unsubscribe()
    await client.stop()

asyncio.run(main())

Runtime API Overview

  • HemsClient.start() / HemsClient.stop(): Start and stop UDP transport.
  • HemsClient.subscribe(callback): Subscribe to runtime events.
  • HemsClient.probe_initial_nodes(): Trigger the initial multicast node discovery using the identification number and self-node instance list.
  • HemsClient.probe_nodes(): Trigger recurring multicast node discovery using only the self-node instance list.
  • HemsClient.start_periodic_discovery(): Start recurring discovery immediately.
  • HemsClient.get(node_id, deoj, epcs): Read property values.
  • HemsClient.set_property(node_id, deoj, epc, edt): Write a single property.
  • HemsClient.set_properties(node_id, deoj, properties): Write multiple properties.

Adaptive Property Polling

PropertyPoller uses an adaptive scheduler designed for mixed ECHONET Lite devices:

  • TID-correlated in-flight tracking avoids request pileups on slow devices.
  • Poll cadence is adjusted from latency EWMA and failure backoff, starting from the base interval.
  • Instantaneous-value EPCs can be scheduled on a separate fast lane (fast_poll_epcs).
  • When devices truncate large responses, batch size is learned (observed_batch_capacity) and reused.
  • Poll targets can be narrowed dynamically through DeviceManager.subscribe_epcs(...).

Definitions

from pyhems import DeviceClass, REGISTRY

print(REGISTRY.version, REGISTRY.mra_version)

# Mapping: class_code -> tuple[EntityDefinition, ...]
ac_entities = REGISTRY.entities.get(DeviceClass.HOME_AIR_CONDITIONER, ())
for entity in ac_entities[:3]:
    print(entity.epc, entity.name_en)

DeviceClass is an IntEnum generated from the MRA shortName values. Custom device classes defined in scripts/custom_definitions.yaml are included too.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhems-0.8.9.tar.gz (147.1 kB view details)

Uploaded Source

Built Distribution

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

pyhems-0.8.9-py3-none-any.whl (116.5 kB view details)

Uploaded Python 3

File details

Details for the file pyhems-0.8.9.tar.gz.

File metadata

  • Download URL: pyhems-0.8.9.tar.gz
  • Upload date:
  • Size: 147.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pyhems-0.8.9.tar.gz
Algorithm Hash digest
SHA256 91bf37f1eed990b19843b2ebe4c15f10331c3bc7756cc9d0afca9522107a8d4f
MD5 fd9ffa1624215ac42f196dec74b2c42d
BLAKE2b-256 ebb7c076602c2292962429a6e627841837f43a65fbe88ffe78b7b5807105af7c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhems-0.8.9.tar.gz:

Publisher: release.yml on sayurin/pyhems

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

File details

Details for the file pyhems-0.8.9-py3-none-any.whl.

File metadata

  • Download URL: pyhems-0.8.9-py3-none-any.whl
  • Upload date:
  • Size: 116.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pyhems-0.8.9-py3-none-any.whl
Algorithm Hash digest
SHA256 eacf4be9f5d474974ac1e3639ace712bbbfba67c1cb9dfffcce0e082d1bcdf5b
MD5 c9f745b135414df52b4c551d62d53868
BLAKE2b-256 4e1f160cd9f4fd16482404e3a92f6fdbe67f9964e6786e57952bb34878b8e111

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhems-0.8.9-py3-none-any.whl:

Publisher: release.yml on sayurin/pyhems

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

Release history Release notifications | RSS feed

This release

0.8.9 This release

2 files

0.8.8

2 files

0.8.7

2 files

0.8.6

2 files

0.8.5

2 files

0.8.4

2 files

0.8.3

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.1

2 files

0.7.0

2 files

0.6.0

2 files

0.5.6

2 files

0.5.5

2 files

0.5.4

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

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