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 🐬 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.0
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.0.tar.gz | 21.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mqtt_entity-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 46.2 kB
Release files / mqtt_entity-1.2.0.tar.gz
| Download URL | mqtt_entity-1.2.0.tar.gz |
|---|---|
| Size | 21.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9926996514d710431308049db25521893e039294803228270936bff545e6f7e1
|
|
BLAKE2b-256 checksum How to use checksums |
7ca025a4f52438207764a827045795cf9246497e41dd3c7552e9b64895289e7d
|
| 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.0-py3-none-any.whl
| Download URL | mqtt_entity-1.2.0-py3-none-any.whl |
|---|---|
| Size | 24.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
77f670a790a8785ed6dbd16b90852d0e701a9f840bb4f0d10fe0871e71a24563
|
|
BLAKE2b-256 checksum How to use checksums |
244df269f8a77be50c85eda8b8e2e855be7c47f9ba7fb029eda0323b2e43738f
|
| 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}
|