Skip to main content

MQTT client supporting Home Assistant MQTT entity auto-discovery

Project description

MQTT Entity helper library for Home Assistant

Workflow Status codecov

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

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

Project details


Download files

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

Source Distribution

mqtt_entity-1.1.7.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

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

mqtt_entity-1.1.7-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

File details

Details for the file mqtt_entity-1.1.7.tar.gz.

File metadata

  • Download URL: mqtt_entity-1.1.7.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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}

File hashes

Hashes for mqtt_entity-1.1.7.tar.gz
Algorithm Hash digest
SHA256 d256c4fe67845bb501507d7557d16b41affb53ab20ba259bb966387787f69bb9
MD5 c56d418150458ede9c9531a3342ab9ff
BLAKE2b-256 2acd30e510b2819355ffbd7c792e5f96ade3d34c7e175d03253c4f27d5d2b8d1

See more details on using hashes here.

File details

Details for the file mqtt_entity-1.1.7-py3-none-any.whl.

File metadata

  • Download URL: mqtt_entity-1.1.7-py3-none-any.whl
  • Upload date:
  • Size: 20.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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}

File hashes

Hashes for mqtt_entity-1.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 11754de07fe21f969d30bbecf4fa0194e9ca9260a46c9fdc95897403f900118c
MD5 cdcf71493200f4e67b408f5fec85fa03
BLAKE2b-256 e3def45f13f8830ecab72f35eaa5e762b517ca936d6bc1bfa768f573fad2dd41

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page