Tutorials

Tasmota MQTT Setup: Topics, Commands and Telemetry

Set up MQTT on Tasmota: broker, FullTopic and Topic, the cmnd/stat/tele structure, POWER commands, TelePeriod telemetry, LWT and testing with the online client.

Updated · 9 min read

Tasmota MQTT Setup: Topics, Commands and Telemetry

Tasmota turns cheap ESP8266 and ESP32 smart plugs, relays and sensors into well-behaved MQTT devices. Point it at a broker, give it a topic name, and it accepts commands on cmnd/<topic>/…, reports results on stat/<topic>/… and sends periodic telemetry on tele/<topic>/…. Once you understand those three prefixes, you can control any Tasmota device from any MQTT client.

This guide configures the broker connection, explains Topic and FullTopic, walks through the commands and telemetry you will use daily, and tests everything from the browser before you wire it into Home Assistant or Node-RED.

Configure the broker

Open the device's web UI and go to Configuration → Configure MQTT:

FieldValueNotes
Hostbroker.connectmq.comHostname or IP of your broker
Port18838883 only on TLS-enabled builds (see below)
Clienttasmota-plug1Must be unique per device; default DVES_%06X uses the chip ID
User / Passwordyour broker credentialsLeave empty only on brokers without authentication
Topictestmqtt-plug1The device's short name
Full Topictestmqtt/tasmota/%prefix%/%topic%/The template for every topic

Saving restarts the device. You can do the same from the Console in one line with Backlog, which is handy when you configure many devices:

Tasmota console
Backlog MqttHost broker.connectmq.com; MqttPort 1883; MqttUser username; MqttPassword password; MqttClient tasmota-plug1; Topic testmqtt-plug1; FullTopic testmqtt/tasmota/%prefix%/%topic%/

Make sure MQTT itself is enabled (Configuration → Configure Other → MQTT enable, or SetOption3 1). After the restart the console should print:

Console output
MQT: Attempting connection...
MQT: Connected

If you see MQT: Connect failed to broker.connectmq.com:1883, rc -2. Retry in 10 sec instead, the device could not open a TCP connection; rc 4 or rc 5 means the credentials were rejected. The Tasmota not connecting guide covers every case.

Topic and FullTopic

Tasmota builds every MQTT topic from the FullTopic template. Three tokens are replaced at runtime:

  • %prefix% becomes cmnd, stat or tele.
  • %topic% becomes the device's Topic (testmqtt-plug1).
  • %hostname% and %id% are also available if you prefer names derived from the chip.

With the default FullTopic %prefix%/%topic%/, a plug named kitchen uses cmnd/kitchen/POWER. On a shared test broker that is far too generic: your cmnd/kitchen/POWER would collide with anyone else's. The FullTopic above prefixes everything with testmqtt/tasmota/, which gives you a private namespace and makes subscriptions easy:

PurposeTopic with our FullTopic
Send a commandtestmqtt/tasmota/cmnd/testmqtt-plug1/POWER
Command resulttestmqtt/tasmota/stat/testmqtt-plug1/RESULT
Current power statetestmqtt/tasmota/stat/testmqtt-plug1/POWER
Periodic statetestmqtt/tasmota/tele/testmqtt-plug1/STATE
Sensor readingstestmqtt/tasmota/tele/testmqtt-plug1/SENSOR
Online / Offline (LWT)testmqtt/tasmota/tele/testmqtt-plug1/LWT

For a larger installation, pick a scheme by location or function and stick to it; smart home topic design has patterns that scale.

Commands: cmnd and stat

Any console command can be sent over MQTT. The command name is the last topic level and the argument is the payload:

Control a relay with mosquitto_pub
# Switch on
mosquitto_pub -h broker.connectmq.com -u "$MQTT_USER" -P "$MQTT_PASS" \
  -t testmqtt/tasmota/cmnd/testmqtt-plug1/POWER -m ON

# Toggle
mosquitto_pub -h broker.connectmq.com -u "$MQTT_USER" -P "$MQTT_PASS" \
  -t testmqtt/tasmota/cmnd/testmqtt-plug1/POWER -m TOGGLE

# Query the state: an empty payload asks without changing anything
mosquitto_pub -h broker.connectmq.com -u "$MQTT_USER" -P "$MQTT_PASS" \
  -t testmqtt/tasmota/cmnd/testmqtt-plug1/POWER -n

The device answers on two topics: stat/testmqtt-plug1/RESULT with JSON such as {"POWER":"ON"}, and stat/testmqtt-plug1/POWER with the plain value ON. Devices with several relays use POWER1, POWER2, and so on.

Other commands you will use often:

CommandPayloadEffect
Status0Full status dump, answered as several stat/.../STATUS* messages
Status6MQTT configuration only, handy for checking FullTopic and client ID
TelePeriod60Send telemetry every 60 seconds (10–3600)
Dimmer0–100Brightness on dimmable lights
Restart1Reboot the device
Backlogcmd1 arg; cmd2 argRun several commands in sequence

You can also send Backlog over MQTT, which makes remote reconfiguration of many devices a one-line script. For more terminal patterns, see mosquitto_pub and mosquitto_sub examples.

Telemetry: tele

Every TelePeriod seconds (300 by default) Tasmota publishes two messages:

tele/testmqtt-plug1/STATE
{"Time":"2026-10-17T10:15:00","Uptime":"0T02:14:31","Heap":25,"POWER":"ON","Wifi":{"SSId":"home","RSSI":72,"Signal":-64}}
tele/testmqtt-plug1/SENSOR (plug with energy monitoring)
{"Time":"2026-10-17T10:15:00","ENERGY":{"Total":3.214,"Yesterday":0.412,"Today":0.183,"Power":46,"Voltage":231,"Current":0.214}}

The exact fields depend on the device template and attached sensors. tele/.../LWT is special: Tasmota publishes Online retained after connecting and registers Offline as its Last Will, so subscribers always know whether the device is reachable.

If you need values faster than TelePeriod allows, use a rule to publish on change. Rules run on the device itself:

Publish power changes immediately
Rule1 ON Power1#State DO Publish testmqtt/tasmota/events/testmqtt-plug1 {"power":%value%} ENDON
Rule1 1

Test everything from the browser

  1. Open the online MQTT client and connect to broker.connectmq.com on port 8084 with path /mqtt.
  2. Subscribe to testmqtt/tasmota/#. You should immediately receive the retained tele/testmqtt-plug1/LWT = Online.
  3. Publish TOGGLE to testmqtt/tasmota/cmnd/testmqtt-plug1/POWER. The relay clicks and stat/.../RESULT and stat/.../POWER arrive within a fraction of a second.
  4. Publish 10 to testmqtt/tasmota/cmnd/testmqtt-plug1/TelePeriod and watch tele/.../STATE arrive every ten seconds. Set it back to a sensible value afterwards.
  5. Unplug the device. After the keep-alive timeout the broker publishes LWT = Offline.

Watch your Tasmota device in the online client

When a subscription shows nothing, check the filter against a real topic with the topic matcher. A missing trailing segment or the wrong prefix order in FullTopic is the usual culprit.

Retained messages and power state

Tasmota does not retain its stat messages by default. If a dashboard needs the current state right after it subscribes, either query it (empty payload to cmnd/.../POWER) or enable PowerRetain 1 so stat/.../POWER is retained.

Never publish commands with the retain flag. A retained ON on cmnd/.../POWER is redelivered every time the device reconnects, and the relay switches on by itself after every power cut or Wi-Fi drop. If that happens, clear it by publishing an empty retained message to the same topic:

Clear a retained command
mosquitto_pub -h broker.connectmq.com -u "$MQTT_USER" -P "$MQTT_PASS" \
  -t testmqtt/tasmota/cmnd/testmqtt-plug1/POWER -r -n

More on how retention works in MQTT retained messages.

TLS and Home Assistant

TLS depends on the firmware build. Many ESP32 builds include MQTT TLS support, while most ESP8266 builds need a custom compile with USE_MQTT_TLS. On a TLS-capable build, set MqttPort 8883 and SetOption103 1, then check the Tasmota TLS documentation for how your build validates the broker's certificate. On plain builds, keep port 1883 and use a trusted local network.

Home Assistant uses the Tasmota integration, which reads Tasmota's own discovery messages (enabled by default with SetOption19 0). Point Home Assistant's MQTT integration at the same broker and the devices appear automatically. The Home Assistant side is covered in Home Assistant MQTT.

Tasmota's MQTT model is simple once the prefixes click: commands go in on cmnd, answers come out on stat, and telemetry arrives on tele every TelePeriod. Give each device a unique client ID and a FullTopic that keeps your devices in their own namespace, verify command, telemetry and LWT from the online client, and every automation you build on top will behave predictably.

Frequently asked questions

What is the difference between Topic and FullTopic in Tasmota?

Topic is the device's short name, such as kitchen-plug. FullTopic is the template that builds every MQTT topic from it, by default %prefix%/%topic%/, where %prefix% becomes cmnd, stat or tele. Change Topic to rename a device; change FullTopic to move all devices under a common namespace.

How often does Tasmota send telemetry?

Every TelePeriod seconds, 300 by default. Set it with the TelePeriod command, for example TelePeriod 60. Sensor values go to tele/<topic>/SENSOR and device state to tele/<topic>/STATE.

Why does my Tasmota relay switch on by itself after a reboot?

Usually a retained message on a cmnd topic: the broker redelivers it every time the device reconnects. Clear it by publishing an empty retained message to that topic, and do not publish commands with the retain flag.