Skip to main content

openems-client

Async Python client for OpenEMS and FENECON FEMS energy management systems.

It talks to an OpenEMS edge, an OpenEMS backend or the FENECON portal over the JSON-RPC websocket API, reads the edge configuration (components and channels), and keeps a live object model of the edge that is updated by currentData push messages. Writing component properties uses JSON-RPC or the REST API.

This library mainly serves the Home Assistant OpenEMS integration, but it does not depend on Home Assistant.

Installation

pip install openems-client

Requires Python 3.14 or newer.

Usage

import asyncio

from openems_client.const import CONN_TYPE_DIRECT_EDGE
from openems_client.connection import OpenEMSConfigReader, OpenEMSWebSocketConnection
from openems_client.openems import OpenEMSBackend


async def main() -> None:
    connection = OpenEMSWebSocketConnection(
        {
            "type": CONN_TYPE_DIRECT_EDGE,
            "host": "192.168.1.10",
            "url": None,
            "username": "guest",
            "password": "user",
        }
    )
    await connection.connect_to_server()
    login_response = await connection.login_to_server()

    reader = OpenEMSConfigReader(connection)
    edges = await reader.read_edges()
    edge_id = edges["edges"][0]["id"]
    reader.set_edge_id(edge_id)
    components = await reader.read_edge_components()

    multi_edge = OpenEMSConfigReader.parse_login_response(login_response)
    backend = OpenEMSBackend(connection, edge_id, multi_edge, components)
    # start() starts the background tasks, stop() closes the connection and ends them
    backend.start()
    ...
    await backend.stop()


asyncio.run(main())

An existing aiohttp.ClientSession can be passed with OpenEMSWebSocketConnection(conn_props, session=session). It is used for all websocket and REST requests and is not closed by the library. Without it, the connection creates its own session and closes it in stop().

Errors

Requests to the backend raise the exceptions of openems_client.exceptions:

  • OpenEMSConnectionError: the backend cannot be reached or does not respond in time.
  • OpenEMSAuthError: the backend rejects the login.
  • OpenEMSError: the base class of both, also raised when the backend rejects a request.

REST writes (channel.write_via_rest) raise these exceptions as well. With update_cycle > 0 the call returns after the first write and repeats the write in the background; errors of the repeated writes are logged.

Availability

edge.available and channel.available are True while the edge is connected and sends channel data. On a connection loss the values are cleared, the channels become unavailable and the library reconnects in the background. They are available again with the first channel data after the reconnect. Listeners of the channels are called on every change of the availability.

Channels

Each component sorts its channels by kind (openems_client.model.ChannelKind): read-only values are SENSOR, ENUM_SENSOR or BINARY_SENSOR, writable properties are NUMBER, SELECT, SWITCH or TIME. Channels without a known representation, eg string properties without options, are skipped.

from openems_client.model import ChannelKind
from openems_client.openems import OpenEMSNumberProperty

component = backend.the_edge.components["ctrlEvcs0"]
for channel in component.channels_of(ChannelKind.SENSOR):
    print(channel.key, channel.unit, channel.quantity, channel.cumulative)
for number in component.channels_of(ChannelKind.NUMBER, OpenEMSNumberProperty):
    print(number.key, number.lower_limit, number.upper_limit, number.step)

Every channel provides:

Attribute Meaning
unique_id <hostname>/<edge id>/<component>/<channel>
key snake_case channel name without the _Property prefix, eg charge_mode
unit normalised unit, eg Wh for Wh_Σ, °C for C; None without unit
quantity openems_client.model.Quantity, eg ENERGY, STATE_OF_CHARGE
cumulative the value is a counter which only increases (_Σ units)
primary one of the main channels of the component (config/primary_channels.json)
severity level of state channels which signal a problem
option_keys snake_case keys of the options of ENUM_SENSOR and SELECT channels
value current value; the option key for enums, a bool for binary sensors and switches
available the edge is connected and sends channel data
add_listener(cb) call cb on value and availability changes, subscribes the channel at the edge

Writable channels accept new values with await channel.update_value(value), SELECT channels take an option key.

Components provide unique_id ("<hostname> <component>"), alias, factory_id and has_primary_channels.

Derived channels

Values that OpenEMS does not provide directly are calculated from other channels of a component, eg the cell voltage differences of batteries. They are SENSOR channels of the component (definitions in openems.DERIVED_CHANNELS). Placeholders in id create one channel per match; placeholders that only occur in a source turn it into a list of values. Further definitions can be applied with component.create_derived_channels(...):

from openems_client.openems import DerivedChannelDefinition

CELL_VOLTAGE_DIFFERENCE = DerivedChannelDefinition(
    id="Tower{tId}Module{mId}CellVoltageDifference",
    sources={"cells": "Tower{tId}Module{mId}Cell{cId}Voltage"},
    value_fn=lambda v: max(v["cells"]) - min(v["cells"]),
    unit="mV",
)

component = backend.the_edge.components["battery0"]
for channel in component.create_derived_channels([CELL_VOLTAGE_DIFFERENCE]):
    channel.add_listener(lambda: print(channel.name, channel.value))

Connection types

Constant Target Default URL
CONN_TYPE_DIRECT_EDGE OpenEMS edge ws://<host>:8085/
CONN_TYPE_LOCAL_FEMS Local FEMS UI websocket ws://<host>:80/websocket
CONN_TYPE_LOCAL_OPENEMS Local OpenEMS backend ws://<host>:8082/
CONN_TYPE_WEB_FENECON FENECON portal wss://portal.fenecon.de/openems-backend-ui2
CONN_TYPE_CUSTOM_URL Any websocket URL as given in url

Development

uv sync
uv run ruff format --check .
uv run ruff check .
uv run mypy
uv run pytest

License

Apache License 2.0, see LICENSE.

Metadata

Release files for openems-client 0.8.0

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

Source distribution (sdist)

Source distribution for openems-client 0.8.0
File Size Uploaded Provenance Actions
openems_client-0.8.0.tar.gz 118.2 kB With provenance Details for openems_client-0.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for openems-client 0.8.0
File Interpreter ABI Platform Actions
openems_client-0.8.0-py3-none-any.whl Python 3 none any Details for openems_client-0.8.0-py3-none-any.whl

Total release size: 151.3 kB

Release files / openems_client-0.8.0.tar.gz

Download URL openems_client-0.8.0.tar.gz
Size 118.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2f636dcf03f033bd5d4d014c77103fa1b165cc124de8e8d39b6c6a87aac0a399
BLAKE2b-256 checksum
How to use checksums
10831f07413dc905420b706e8bf080821bcee6aca50813817683bfaa485df498
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 21, 2026.

Transparency log

Release files / openems_client-0.8.0-py3-none-any.whl

Download URL openems_client-0.8.0-py3-none-any.whl
Size 33.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d07bb145019b075cd9b82333fc313db37b5b16ce1ea0bdba57d79089b7d81212
BLAKE2b-256 checksum
How to use checksums
e0f0585a0dc19edca7cb5f35f77fac41a030ca67bf49234e8b537afa044e0751
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 21, 2026.

Transparency log

Security for openems-client 0.8.0

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 openems_client-0.8.0.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 Nov 21, 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.

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