MQTT Entity helper library for Home Assistant
A Python helper library to manage Home Assistant entities over MQTT.
Updated for device based MQTT discovery.
Features:
- MQTT client based on paho-mqtt
- Retrieve MQTT service info from the Home Assistant Supervisor
- Manage MQTT discovery info (adding/removing entities)
- MQTTDevice class to manage devices
- Availability management (client-wide and optional per-device
availability_topics) - Manage entities per device
- Availability management (client-wide and optional per-device
- Home Assistant Entities modelled as dataclasses:
- Read-only: Sensor, BinarySensor
- Read & write: Select, Switch, Number, Text, Light
- MQTT device events
- Asyncio based
- Helpers for Home Assistant add-ons (optional)
- Add-on configuration modeled as dataclasses
- Load from environment variables, HA's options.yaml or options.json
- Load MQTT connection settings from the Supervisor
- Enable add-on logging (incl colors & debug by config)
- Add-on configuration modeled as dataclasses
Why?
This MQTT code was included in several of my home Assistant addons (SMA-EM / Sunsynk). It is easier to update a single library & add new features, like discovery removal.
Alternative options (not based on asyncio)
Credits
@Ivan-L contributed some of the writable entities to the Sunsynk addon project
Release
Semantic versioning is used for release.
To create a new release, include a commit with a :dolphin: emoji as a prefix in the commit message. This will trigger a release on the master branch.
# Patch
git commit -m ":dolphin: Release 0.0.x"
# Minor - any commit
Development
To run the tests, you need to have Python 3.12+ installed.
The --mqtt connects to a live Home Assistant instance using the MQTT broker.
uv run pytest --mqtt
Metadata
Release files for mqtt-entity 1.2.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mqtt_entity-1.2.7.tar.gz | 22.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mqtt_entity-1.2.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 48.2 kB
Release files / mqtt_entity-1.2.7.tar.gz
| Download URL | mqtt_entity-1.2.7.tar.gz |
|---|---|
| Size | 22.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ea4cb9903124e0bc89c235339ee3833f3f60fda21a4e6e62b13082b39f427ddb
|
|
BLAKE2b-256 checksum How to use checksums |
2456ed29e3d35ccf2e368f31e071b1c3821b92712dfa46fcf99a0ad032ff0802
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / mqtt_entity-1.2.7-py3-none-any.whl
| Download URL | mqtt_entity-1.2.7-py3-none-any.whl |
|---|---|
| Size | 25.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1dae618aee5288258bbd78fa63b50be2fc03098b656e316c44501a530b03de33
|
|
BLAKE2b-256 checksum How to use checksums |
1a4bc11f79f12ea3659ec2e34cb48459486ecebaa6156a7db94daf0ab9810a8e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|