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")

    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.start()

    # 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 and wait for Set_Res/SetC_SNA
    # result = 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. Starting also sends the initial discovery probe and starts recurring discovery after 30 seconds.
  • 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 and wait for the acknowledged result.
  • HemsClient.set_properties(node_id, deoj, properties): Write multiple properties and wait for the acknowledged result. The returned SetRequestResult separates accepted, rejected, and unanswered EPCs. This low-level client API does not update a DeviceManager cache.
  • DeviceManager.set_properties(node_id, deoj, properties): Write through the runtime client and update cached values for accepted EPCs. Fires on_device_updated only when cached values change.
  • DeviceManager.async_start() / DeviceManager.async_stop(): Subscribe to runtime events and process device events in arrival order.

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.

Metadata

Release files for pyhems 0.8.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyhems 0.8.14
File Size Uploaded Provenance Actions
pyhems-0.8.14.tar.gz 157.7 kB With provenance Details for pyhems-0.8.14.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyhems 0.8.14
File Interpreter ABI Platform Actions
pyhems-0.8.14-py3-none-any.whl Python 3 none any Details for pyhems-0.8.14-py3-none-any.whl

Total release size: 280.2 kB

Release files / pyhems-0.8.14.tar.gz

Download URL pyhems-0.8.14.tar.gz
Size 157.7 kB
Tags Source
SHA-256 checksum
How to use checksums
006730c9188d7f996b7f7ca68903f3c7cd855d4837c6c2326f93581f7555145b
BLAKE2b-256 checksum
How to use checksums
9a226551acbd650f64876d49ab097c70fc140659467ef7e34a674080bd632e4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Oct 3, 2026.

Transparency log

Release files / pyhems-0.8.14-py3-none-any.whl

Download URL pyhems-0.8.14-py3-none-any.whl
Size 122.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bcb4db3f03f459505ecd215b94ecd0b5575b218158a5d41774d272723f931f80
BLAKE2b-256 checksum
How to use checksums
085d9c67cbffe8ad5770e787205b594fa46bb39b363afecc07cf45e731156528
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Oct 3, 2026.

Transparency log

Security for pyhems 0.8.14

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 pyhems-0.8.14.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 Oct 3, 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.8.14 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