MQTT and Telemetry
MQTT is a publish/subscribe messaging system: devices publish small messages to named topics on a broker, and anything interested subscribes. It is the lingua franca of local home automation, and Tasmota is a model citizen of it. This chapter's message shapes were read from the functions that build them in the v16.0.0 source — not reconstructed from packet captures or other guides — because the formats are contracts your other software will depend on.
The topic pattern
By default a device uses its topic (a
name you choose, like hallway-plug) in a
three-part pattern:
cmnd/<topic>/…— commands to the device (cmnd/hallway-plug/Powerwith payloadON).stat/<topic>/…— results and status from the device, includingRESULT(the reply to a command) andSTATUS0and friends (the reply toStatus 0).tele/<topic>/…— telemetry: messages the device publishes on its own schedule, whether or not anyone asked.
The pattern is configurable (the full-topic
setting uses %prefix%/%topic%/), and
devices can also be grouped — a command to
a group topic reaches every member, which
is how "all downstairs lights" happens
without a hub scripting it.
STATE: the heartbeat
Every TelePeriod seconds (default 300)
the device publishes tele/<topic>/STATE,
assembled by a function the source calls
MqttShowState(). It is the device's
heartbeat and dashboard in one document:
current time, uptime as text and in
seconds, free heap, sleep mode, load
average, every relay's state ("POWER1":
"ON"), light state where present, and a
Wi-Fi block — access point, signal strength
in dBm and percent, channel, and the
network identity. If you are building
anything that watches Tasmota devices,
STATE is the message you build it on.
SENSOR: the measurements
When a device has sensors — or an energy
monitor — it publishes tele/<topic>/SENSOR
alongside STATE, built by
MqttPublishTeleSensor(), and only when
there is data to send. Readings appear
under the sensor's name, so a temperature
probe arrives as {"DS18B20":{"Temperature":
21.4,…}} and a multi-sensor device nests
several such objects in one message.
RESULT and LWT
Command replies on stat/<topic>/RESULT
are the same JSON the web console shows.
And MQTT's Last Will and Testament gives
you the device's obituary for free: the
broker publishes tele/<topic>/LWT with
Offline if the device vanishes, Online
when it (re)connects — the reliable way to
notice a dead device in a wall of data.
A worked minute
A plug named kettle-plug, switched on
from a hub, looks like this on the wire:
→ cmnd/kettle-plug/Power "ON"
← stat/kettle-plug/RESULT {"POWER":"ON"}
← tele/kettle-plug/STATE {"Time":…,"UptimeSec":…,"POWER":"ON","Wifi":{…}}
← tele/kettle-plug/SENSOR {"ENERGY":{"Power": … }} (energy plugs only)
Nothing in that exchange needs the internet, an account, or the vendor. A broker on a small home server (the MQTT guide in this series covers running one) and any dashboard or hub that speaks MQTT complete the system.