Skip to main content

Framework for building easy Home Assistant devices

Project description

jhomeassistant

A Python library for Home Assistant MQTT device discovery based on jmqtt connections.

Installation

pip install jhomeassistant

Requirements

  • Python >=3.8
  • jmqtt
  • python-slugify

Quickstart

from jmqtt import MQTTBuilderV3
from jhomeassistant import HomeAssistantConnection, HomeAssistantDevice
from jhomeassistant.entities import HomeAssistantEntityBase
from jhomeassistant.types import Component

# 1) Build MQTT connection
connection = (
    MQTTBuilderV3(host="localhost", app_name="my-tool")
    .instance_id("main")
    .availability("my-tool/status")
    .fast_build()
)

# 2) Wrap it for Home Assistant discovery
ha = HomeAssistantConnection(connection)
ha.origin.name = "my-tool"

# 3) Define an entity by subclassing HomeAssistantEntityBase
class TemperatureEntity(HomeAssistantEntityBase):
    def __init__(self):
        super().__init__(Component.SENSOR, "Temperature")

entity = TemperatureEntity()
device = HomeAssistantDevice("Kitchen Sensor").add_entities(entity)

# 4) Register and run discovery + scheduler loop
ha.add_devices(device)
ha.run()

Core Concepts

HomeAssistantConnection

  • Holds a jmqtt connection (MQTTConnectionV3 or MQTTConnectionV5)
  • Builds and publishes Home Assistant device discovery payloads
  • Subscribes to homeassistant/status and dispatches birth/death hooks to entities

Main configuration:

  • discovery_prefix("homeassistant")
  • origin.name, origin.sw_version, origin.url
  • availability (connection-level availability inheritance)
  • qos, encoding (connection-level defaults inherited by devices)

HomeAssistantDevice

  • Represents one Home Assistant device block in discovery
  • Auto-detects runtime device facts using jmqtt.client_identity.facts
  • Derives stable identifiers for discovery and entity unique IDs
  • Supports prevent_device_merge=True to avoid connection-based merge identifiers

Common fields:

  • manufacturer, model, model_id
  • hw_version, sw_version
  • via_device, configuration_url
  • qos, encoding
  • availability

HomeAssistantEntityBase

  • Base class for entities that belong to a HomeAssistantDevice
  • Provides deterministic identifier and discovery payload base
  • Supports scheduled publisher functions via add_schedule(interval, function)
  • Lifecycle hooks:
    • home_assistant_birth(connection)
    • home_assistant_death(connection)

Discovery Output

HomeAssistantConnection.discovery_text() returns formatted discovery topics + payloads, useful for debugging and tests.

Notes

  • origin.name is required by device-based discovery payload validation.
  • If not set explicitly, device name is used as fallback.
  • Entity names should be unique within a device to avoid unique_id collisions.

License

MIT (see LICENSE).

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

jhomeassistant-0.1.1.tar.gz (27.7 kB view details)

Uploaded Source

Built Distribution

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

jhomeassistant-0.1.1-py3-none-any.whl (54.3 kB view details)

Uploaded Python 3

File details

Details for the file jhomeassistant-0.1.1.tar.gz.

File metadata

  • Download URL: jhomeassistant-0.1.1.tar.gz
  • Upload date:
  • Size: 27.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for jhomeassistant-0.1.1.tar.gz
Algorithm Hash digest
SHA256 855cd6327e84c36190e11b9d9f2c4b3edbb4e65d6a744a1d02564475c6ed0271
MD5 7502f43318eb8e1de997a7b2704afc92
BLAKE2b-256 836107bf6b81674bc3d8fafba1a047a4c79602be3403ba695df7161f4bbc16ff

See more details on using hashes here.

File details

Details for the file jhomeassistant-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: jhomeassistant-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 54.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for jhomeassistant-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8e48a0843c21a13b40caa84c6988bd340655a5c626300899bb8ddf57894fbb5d
MD5 dfee6471ab0b683fddd7080b706e0dcd
BLAKE2b-256 2594aeb1b0dfca0168e2c19f6b6a7b03d438a7d5d952ca8d0bc329eda2a53822

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