Skip to main content

ha-mqtt-models-pydantic

Typed Pydantic v2 models for Home Assistant MQTT discovery payloads.

This library validates Home Assistant MQTT discovery payloads as plain Python data, without depending on Home Assistant itself. It is useful when you want to inspect, validate, transform, or generate discovery payloads before publishing them to MQTT.

What It Includes

  • Pydantic models for Home Assistant MQTT discovery components
  • Helpers to parse raw discovery payloads into the right model
  • Support for Home Assistant discovery abbreviations such as stat_t, cmd_t, and dev
  • Dedicated light parsing for basic, json, and template schemas
  • Dedicated infrared parsing for emitter and receiver schemas
  • Typed shared models for entity metadata, device info, and origin info

Installation

From PyPI:

pip install ha-mqtt-models-pydantic

With uv:

uv add ha-mqtt-models-pydantic

Quick Start

from ha_mqtt_models_pydantic import parse_component_payload

payload = {
    "dev_cla": "temperature",
    "name": "Living Room Temperature",
    "stat_t": "homeassistant/sensor/living_room_temperature/state",
    "unit_of_meas": "°C",
    "val_tpl": "{{ value_json.temperature }}",
    "def_ent_id": "sensor.living_room_temperature",
    "dev": {
        "ids": ["living_room_sensor_01"],
        "name": "Living Room Sensor",
    },
}

sensor = parse_component_payload("sensor", payload)

print(sensor.name)
print(sensor.state_topic)
print(sensor.device.identifiers)

parse_component_payload() expands Home Assistant abbreviations before validation, so both abbreviated and expanded payloads are accepted.

When the component name is a string literal, type checkers infer the concrete model: parse_component_payload("sensor", ...) is typed as Sensor. light and infrared return a union of their schema models, and a non-literal str returns the ComponentModel union.

Main APIs

Parse a component payload

from ha_mqtt_models_pydantic import parse_component_payload

switch = parse_component_payload(
    "switch",
    {
        "cmd_t": "devices/lamp/set",
        "stat_t": "devices/lamp/state",
        "pl_on": "ON",
        "pl_off": "OFF",
        "uniq_id": "lamp_switch_01",
    },
)

Parse a light payload

from ha_mqtt_models_pydantic import parse_light_payload

light = parse_light_payload(
    {
        "schema": "json",
        "cmd_t": "devices/light/set",
        "stat_t": "devices/light/state",
        "name": "Desk Light",
    }
)

Parse an infrared payload

from ha_mqtt_models_pydantic import parse_infrared_payload

emitter = parse_infrared_payload(
    {
        "schema": "emitter",
        "cmd_t": "devices/ir_blaster/send",
        "name": "IR Blaster",
    }
)

Infrared payloads have no default schema, so schema must be emitter or receiver.

Parse a device discovery payload

from ha_mqtt_models_pydantic import parse_device_discovery_payload

device_payload = parse_device_discovery_payload(
    {
        "dev": {"ids": ["device_01"], "name": "Example Device"},
        "o": {"name": "example-generator"},
        "cmps": {
            "temperature": {
                "p": "sensor",
                "dev_cla": "temperature",
                "stat_t": "devices/example/temperature",
                "unit_of_meas": "°C",
            }
        },
    }
)

Supported Components

  • alarm_control_panel
  • binary_sensor
  • button
  • camera
  • climate
  • cover
  • date
  • datetime
  • device_automation
  • device_tracker
  • event
  • fan
  • humidifier
  • image
  • infrared
  • lawn_mower
  • light
  • lock
  • notify
  • number
  • scene
  • select
  • sensor
  • siren
  • switch
  • tag
  • text
  • time
  • update
  • vacuum
  • valve
  • water_heater

Notes

  • The import package is ha_mqtt_models_pydantic.
  • The PyPI distribution name is ha-mqtt-models-pydantic.
  • The library targets Python 3.11+.
  • The package is marked as typed with py.typed.
  • The models match the MQTT discovery schemas of Home Assistant core 2026.10.4 (master), exposed as HA_CORE_VERSION.

Development

Install development dependencies:

uv sync --dev

Run checks:

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

Releasing

  1. Bump the version with uv version <new-version> and merge it to main.
  2. Publish a GitHub release whose tag is v<new-version>.

The publish workflow refuses tags that do not match the pyproject.toml version, runs the CI checks, then uploads to PyPI.

License

MIT

Metadata

Release files for ha-mqtt-models-pydantic 1.1.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 ha-mqtt-models-pydantic 1.1.0
File Size Uploaded Provenance Actions
ha_mqtt_models_pydantic-1.1.0.tar.gz 31.9 kB With provenance Details for ha_mqtt_models_pydantic-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ha-mqtt-models-pydantic 1.1.0
File Interpreter ABI Platform Actions
ha_mqtt_models_pydantic-1.1.0-py3-none-any.whl Python 3 none any Details for ha_mqtt_models_pydantic-1.1.0-py3-none-any.whl

Total release size: 76.8 kB

Release files / ha_mqtt_models_pydantic-1.1.0.tar.gz

Download URL ha_mqtt_models_pydantic-1.1.0.tar.gz
Size 31.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3d7789a030b72c243a9b702ee12146d1b65be2775352d5ec5003140f8834e120
BLAKE2b-256 checksum
How to use checksums
99ea85230f9faf8a977af10bbe33139bbf08a29cf9889ea043b976792589e689
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 Oct 30, 2026.

Transparency log

Release files / ha_mqtt_models_pydantic-1.1.0-py3-none-any.whl

Download URL ha_mqtt_models_pydantic-1.1.0-py3-none-any.whl
Size 44.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
94d2ae89c7a1871d51e182a61070c1d2f807d2c753195621fcafbdeabf3eb53b
BLAKE2b-256 checksum
How to use checksums
cd075127e2b5753ca8ffe9056177679c2b007b046f38ad47db49db9b2ac2772f
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 Oct 30, 2026.

Transparency log

Security for ha-mqtt-models-pydantic 1.1.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 ha_mqtt_models_pydantic-1.1.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 Oct 30, 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