Skip to main content

MQTT Module

The MQTT Module publishes webhook payloads to MQTT brokers. Supports MQTT 3.1.1 and 5.0 protocols with TLS/SSL encryption.

Configuration

{
"mqtt_events": {
"data_type": "json",
"module": "mqtt",
"connection": "mqtt_local",
"module-config": {
"topic": "webhook/events",
"qos": 1,
"retained": false,
"format": "json",
"topic_prefix": "devices"
},
"authorization": "Bearer mqtt_secret"
}
}

Connection Configuration

In connections.json:

{
"mqtt_local": {
"type": "mqtt",
"host": "localhost",
"port": 1883,
"username": "user",
"password": "pass",
"client_id": "webhook-module",
"keepalive": 60,
"mqtt_version": "3.1.1"
}
}

TLS/SSL Configuration

{
"mqtt_secure": {
"type": "mqtt",
"host": "mqtt.example.com",
"port": 8883,
"username": "user",
"password": "pass",
"tls": true,
"tls_ca_cert_file": "/path/to/ca.crt",
"tls_cert_file": "/path/to/client.crt",
"tls_key_file": "/path/to/client.key",
"tls_insecure": false
}
}

Connection Options

OptionTypeDefaultDescription
hoststring"localhost"MQTT broker hostname
portinteger1883MQTT broker port
usernamestring-Authentication username
passwordstring-Authentication password
client_idstring"webhook-module"MQTT client identifier
keepaliveinteger60Connection keepalive in seconds
mqtt_versionstring"3.1.1"MQTT protocol version ("3.1.1" or "5.0")
tlsbooleanfalseEnable TLS/SSL
tls_ca_cert_filestring-CA certificate file path
tls_cert_filestring-Client certificate file path
tls_key_filestring-Client private key file path
tls_insecurebooleanfalseAllow self-signed certificates

Module Configuration Options

OptionTypeDefaultDescription
topicstringRequiredMQTT topic to publish to
qosinteger1Quality of Service level (0, 1, or 2)
retainedbooleanfalseWhether messages should be retained
formatstring"json"Message format: "json" or "raw"
topic_prefixstring-Prefix prepended to topic

Topic Validation

Topic names are validated for security:

  • Cannot contain wildcards (+ or #) when publishing
  • Cannot start with $ (reserved for system topics)
  • Cannot contain consecutive slashes (//)
  • Maximum 32KB in length

Special Features

Shelly Device Compatibility

Supports Shelly Gen2/Gen3 JSON format:

{
"shelly_webhook": {
"data_type": "json",
"module": "mqtt",
"connection": "mqtt_local",
"module-config": {
"topic": "shellies/device123/status",
"shelly_gen2_format": true,
"device_id": "device123",
"qos": 1
}
}
}

Sonoff/Tasmota Compatibility

Supports command (cmnd), status (stat), and telemetry (tele) topic formats:

{
"tasmota_webhook": {
"data_type": "json",
"module": "mqtt",
"connection": "mqtt_local",
"module-config": {
"topic": "tasmota/device",
"tasmota_format": true,
"tasmota_type": "cmnd",
"device_name": "switch1",
"command": "POWER",
"qos": 1
}
}
}

Features

  • MQTT 3.1.1 and 5.0 protocol support
  • TLS/SSL encryption with client certificates
  • QoS levels: 0, 1, 2
  • Retained messages
  • Topic prefix support
  • Shelly and Tasmota device format support
  • Topic name validation