KaZa Home automation

Home automation

MQTT integration

MQTT

Package kaza-mqtt, module org.kazoe.mqtt. MQTT 3.1.1 client over TCP or TLS, built on Eclipse Paho. Typical uses: zigbee2mqtt, Tasmota, Shelly, ESPHome, Home Assistant as a bridge.

import org.kazoe.mqtt 1.0

MqttClient

One broker connection. It starts as soon as hostname and clientId are set; changing a property reconnects.

Property Description
hostname host, host:port, [ipv6]:port (default port 1883, 8883 with TLS)
clientId Required
login, password Sent only when both are set
tls Encrypt the connection (default off)
caFile CA (PEM) for the broker; empty = system store
certFile, keyFile Client certificate for brokers that require one
tlsVerify Verify certificate and host name (default on)
subscribeQos 0 to 2 (default 1)
connected Read only
  • The first connection is retried every 5 s, then Paho reconnects and re-subscribes automatically.
  • publish(topic, message, qos, retain) queues up to 1000 messages while disconnected and sends them in order on reconnection.

Subscribers

Type Value
MqttTopic A KaZa object (value, name, unit). Payload may be plain number, true/false, or JSON with a value field. topic accepts + and # wildcards
MqttJson The payload parsed as a JSON object/array
MqttQuery A map from a key=value&key2=value2 payload

Overlapping subscriptions are merged: only filters not covered by another are subscribed, and each message is delivered once to every matching subscriber.

Example

MqttClient {
    id: broker
    hostname: "192.168.1.10"
    clientId: "kaza"
    login: "kaza"
    password: "secret"
    tls: true
    caFile: "/etc/kaza/mqtt-ca.pem"
}

MqttTopic {
    server: broker
    topic: "zigbee2mqtt/salon/temperature"
    name: "sensor.lounge.temperature"
    unit: "°C"
}

MqttJson {
    server: broker
    topic: "zigbee2mqtt/salon"
    onValueChanged: console.log(value.temperature)
}

Security

Without tls: true, login and password travel in clear text. The broker certificate must match hostname.