IoT Automation

Tasmota MQTT Setup: Configure Host, Topic and Full Topic and Control a Smart Plug

Set up Tasmota's MQTT host, client, topic and full topic from the web UI or console, then switch a smart plug and read its telemetry through broker.connectmq.com.

Smart plug running Tasmota firmware sending tasmota mqtt messages to a broker
Run this on your own MQTT brokerGet a private, managed MQTT broker on the Free plan and start from ready-made code samples.
Try it free Code samples No card required

Tasmota MQTT support turns a cheap ESP8266 or ESP32 smart plug into a device you can switch and monitor from any script, dashboard or home automation system. In this tutorial you will configure the MQTT host, client ID, topic and full topic, then control a plug and read its energy telemetry through the public test broker at broker.connectmq.com.

How Tasmota Uses MQTT

Tasmota is open-source firmware for ESP-based devices. Out of the box it offers a web UI, but its real power is MQTT: every command you can type into the console can also be sent as an MQTT message, and every state change and sensor reading is published back. That makes a Tasmota plug a first-class citizen in Node-RED, Home Assistant, openHAB or your own code.

Tasmota builds every topic from three parts:

  • Prefix - cmnd for commands you send, stat for responses and state changes, tele for periodic telemetry and availability.
  • Topic - a short, unique device name such as plug1.
  • Full topic - a template that combines them, by default %prefix%/%topic%/.

With the default full topic, sending a command to cmnd/plug1/POWER makes the device answer on stat/plug1/RESULT and stat/plug1/POWER, while telemetry goes to tele/plug1/STATE and tele/plug1/SENSOR. The Tasmota MQTT commands cheat sheet lists the most useful commands in detail.

What You Need

  • A device already running Tasmota (version 13 or newer recommended) and joined to your Wi-Fi.
  • The device's IP address, so you can open its web UI.
  • A computer with mosquitto_pub and mosquitto_sub, or any MQTT client such as the ConnectMQ web client in the portal.

Step 1: Choose Unique Names

The free public MQTT broker at broker.connectmq.com is shared by everyone, and anything published there can be read by anyone. Before configuring Tasmota, pick:

  • a random ID, for example t7x2pk,
  • a client ID such as tasmota-t7x2pk,
  • a topic such as plug1,
  • a full topic that keeps your messages under your own prefix: connectmq/demo/t7x2pk/%prefix%/%topic%/.

The resulting topics are six levels deep (connectmq/demo/t7x2pk/cmnd/plug1/POWER), within the public broker's eight-level limit.

Step 2: Configure Tasmota MQTT in the Web UI

Open the device's IP address in a browser and go to Configuration then Configure MQTT. Fill in:

Field Value for the public test Value for production
Host broker.connectmq.com your broker host
Port 1883 1883 or 8883 with a TLS build
Client tasmota-t7x2pk YOUR_CLIENT_ID
User leave empty YOUR_USERNAME
Password leave empty YOUR_PASSWORD
Topic plug1 plug1
Full Topic connectmq/demo/t7x2pk/%prefix%/%topic%/ home/%prefix%/%topic%/

Click Save. Tasmota restarts and connects. If the Other configuration page shows the MQTT checkbox unticked, enable it; MQTT is on by default in standard builds, but some templates disable it.

Step 3: Or Configure Tasmota MQTT from the Console

The console (Main Menu then Console) is faster and scriptable. Backlog runs several commands in one go, and the device restarts once at the end:

Backlog MqttHost broker.connectmq.com; MqttPort 1883; MqttClient tasmota-t7x2pk; MqttUser 0; MqttPassword 0; Topic plug1; FullTopic connectmq/demo/t7x2pk/%prefix%/%topic%/

MqttUser 0 and MqttPassword 0 clear the default DVES_USER / DVES_PASS values so the device connects anonymously. After the restart, the console log should show a line like MQT: Connected followed by the LWT message Online.

Step 4: Watch the Device

Subscribe to everything under your prefix:

mosquitto_sub -h broker.connectmq.com -p 1883 -i watch-t7x2pk \
  -t 'connectmq/demo/t7x2pk/#' -v

Within a few seconds you will see something like:

connectmq/demo/t7x2pk/tele/plug1/LWT Online
connectmq/demo/t7x2pk/cmnd/plug1/POWER (null)
connectmq/demo/t7x2pk/tele/plug1/INFO1 {"Info1":{"Module":"Generic","Version":"14.2.0(release-tasmota)",...}}
connectmq/demo/t7x2pk/tele/plug1/STATE {"Time":"2026-10-16T10:12:03","Uptime":"0T00:00:15","POWER":"OFF",...}

The LWT topic is retained and is also the device's Last Will, so it flips to Offline when the plug loses power or Wi-Fi. That is the topic to watch for availability.

Step 5: Control the Smart Plug over MQTT

Send commands to the cmnd prefix:

# Turn on
mosquitto_pub -h broker.connectmq.com -p 1883 -i send-t7x2pk \
  -t 'connectmq/demo/t7x2pk/cmnd/plug1/POWER' -m 'ON'

# Toggle
mosquitto_pub -h broker.connectmq.com -p 1883 -i send-t7x2pk \
  -t 'connectmq/demo/t7x2pk/cmnd/plug1/POWER' -m 'TOGGLE'

# Query the current state (empty payload)
mosquitto_pub -h broker.connectmq.com -p 1883 -i send-t7x2pk \
  -t 'connectmq/demo/t7x2pk/cmnd/plug1/POWER' -n

Each one produces stat/plug1/RESULT with {"POWER":"ON"} and stat/plug1/POWER with ON. Plugs with energy monitoring also publish tele/plug1/SENSOR with voltage, current and power, by default every 300 seconds. To make that faster during testing:

mosquitto_pub -h broker.connectmq.com -p 1883 -i send-t7x2pk \
  -t 'connectmq/demo/t7x2pk/cmnd/plug1/TelePeriod' -m '30'

TelePeriod accepts 10 to 3600 seconds. Keep it modest on the public broker; 10 messages per second per client is the limit there, and a plug every 30 seconds is nowhere near it.

If a plug should come back in a known state after a power cut, set PowerOnState as well: PowerOnState 0 keeps it off, 1 turns it on, and the default 3 restores the last saved state. Combined with retained state topics, that makes the plug's behaviour predictable for every dashboard.

Reading Tasmota MQTT Data in Code

Here is a small Python listener (paho-mqtt 2.x) that prints power readings and availability:

import json
import paho.mqtt.client as mqtt

PREFIX = "connectmq/demo/t7x2pk"

def on_connect(client, userdata, flags, reason_code, properties):
    client.subscribe(f"{PREFIX}/tele/plug1/SENSOR")
    client.subscribe(f"{PREFIX}/tele/plug1/LWT")
    client.subscribe(f"{PREFIX}/stat/plug1/POWER")

def on_message(client, userdata, msg):
    text = msg.payload.decode()
    if msg.topic.endswith("/SENSOR"):
        energy = json.loads(text).get("ENERGY", {})
        print("power W:", energy.get("Power"), "today kWh:", energy.get("Today"))
    else:
        print(msg.topic, text)

client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, client_id="py-t7x2pk")
client.on_connect = on_connect
client.on_message = on_message
client.connect("broker.connectmq.com", 1883, keepalive=60)
client.loop_forever()

Moving from the Public Broker to Production

The public broker is for experiments. Anyone could switch your plug if they guessed the topic, so a plug that powers a heater or a server must never stay there. For the permanent setup:

  1. Create a private broker in the ConnectMQ portal and copy the generated username, password and client ID.
  2. Set them with Backlog MqttHost <host>; MqttUser YOUR_USERNAME; MqttPassword YOUR_PASSWORD; MqttClient YOUR_CLIENT_ID; FullTopic home/%prefix%/%topic%/.
  3. Use TLS if your build supports it. ESP32 tasmota32 builds do; most ESP8266 builds do not. The Tasmota MQTT TLS guide walks through the details.
  4. Give every device its own credentials and client ID, because the broker accepts only one session per client ID.

A hosted MQTT broker removes the need to keep a Mosquitto box running at home, and lets you reach the plug from outside without port forwarding. For more smart-home building blocks, see the smart plug MQTT guide and the IoT automation overview.

Troubleshooting Tasmota MQTT

Symptom Likely cause Fix
Console shows MQT: Connect failed ... rc -2 Host unreachable or wrong port Check MqttHost, DNS and port
rc 5 (not authorised) Wrong user/password or client ID Re-enter credentials, check MqttClient
Connects, then drops every few seconds Duplicate client ID Give each device and tool a unique ID
No messages under your prefix Full topic typo Run FullTopic alone to print the current value
Commands ignored Sent to stat or tele instead of cmnd Commands always go to the cmnd prefix

The Tasmota project documents every command and setting on its official site at tasmota.github.io.

Control Tasmota Devices with ConnectMQ

Create a free Serverless broker at app.connectmq.com with no credit card, paste the credentials into the Configure MQTT page, and use the portal's in-browser client and live topic explorer to switch your plugs. ConnectMQ supports MQTT 3.1.1 and 5.0, so Tasmota connects without any special settings.

Frequently Asked Questions

What is the difference between Topic and Full Topic in Tasmota?

Topic is the short device name, such as plug1. Full Topic is the template that builds the complete topic from the prefix and the topic, for example home/%prefix%/%topic%/.

Why does Tasmota restart after I change MQTT settings?

Tasmota applies MQTT host, port, credential and topic changes by restarting. Using Backlog groups several changes into a single restart.

How do I query a Tasmota device's state without changing it?

Publish an empty payload to the command topic, for example cmnd/plug1/POWER. The device replies on stat/plug1/RESULT with its current state.

Can I control many Tasmota devices with one command?

Yes. Every device also listens on a group topic, tasmotas by default, so a message to cmnd/tasmotas/POWER reaches all of them. Change it with GroupTopic if you share a broker.

Related articles

Zigbee2MQTT Setup Guide: From Coordinator to Dashboard

Install Zigbee2MQTT with Docker, configure the coordinator and MQTT connection, pair and rename devices, control them over MQTT and view their states on a dashboard, testing first on a free public broker.

7 min read

All articles →

Your private MQTT broker is a few clicks away

Create an account, get your broker credentials and connect your first device — no servers to install, patch or scale.