MQTT is the backbone protocol of most smart home and IoT setups. It is lightweight, reliable, and works on everything from a Raspberry Pi to an industrial sensor. By connecting OpenClaw to an MQTT broker, you turn a conversational AI agent into a natural language controller for every connected device in your home.
How MQTT Works (30-Second Version)
MQTT follows a publish/subscribe model[1]:
- Broker — central message server (like Mosquitto)
- Topics — hierarchical channels (e.g.,
home/living-room/light/state) - Publish — send a message to a topic
- Subscribe — listen for messages on a topic
Devices publish their state and subscribe to command topics. OpenClaw subscribes to state updates and publishes commands — acting as both a listener and controller.
Setting Up the MQTT Broker
Install Mosquitto
Mosquitto is the most widely used open-source MQTT broker[2].
On Ubuntu/Debian:
sudo apt install mosquitto mosquitto-clients
sudo systemctl enable mosquitto
sudo systemctl start mosquitto
On Docker:
services:
mosquitto:
image: eclipse-mosquitto:2
ports:
- "1883:1883"
volumes:
- ./mosquitto/config:/mosquitto/config
- mosquitto_data:/mosquitto/data
restart: unless-stopped
volumes:
mosquitto_data:
Configure Authentication
Never run an MQTT broker without authentication, even on a local network:
# Create password file
mosquitto_passwd -c /mosquitto/config/passwordfile openclaw
# mosquitto.conf
listener 1883
allow_anonymous false
password_file /mosquitto/config/passwordfile
Restart Mosquitto after changing the config.
Connecting OpenClaw to MQTT
Install the MQTT skill and configure the broker connection:
openclaw plugins install mqtt-control
openclaw config set mqtt.broker "mqtt://localhost:1883"
openclaw config set mqtt.username "openclaw"
openclaw config set mqtt.password "your-secure-password"
Restart OpenClaw to apply:
openclaw restart
Verify the Connection
openclaw mqtt status
You should see the broker connection status, subscribed topics, and recent messages.
Mapping Devices to Topics
Most smart devices follow a common topic structure. Tell OpenClaw about your devices so it can interpret natural language commands:
openclaw memory add "My MQTT device map:
- Living room light: topic home/living-room/light, payloads ON/OFF
- Bedroom light: topic home/bedroom/light, payloads ON/OFF
- Thermostat: topic home/thermostat/set, payload is temperature number
- Front door lock: topic home/front-door/lock, payloads LOCK/UNLOCK
- Motion sensor (living room): topic home/living-room/motion, reports DETECTED/CLEAR"
Now OpenClaw understands what "turn off the living room light" means at the MQTT level: publish OFF to home/living-room/light.
Example Automations
Basic Device Control
Once devices are mapped, natural language works immediately:
"Turn off all the lights" "Set the thermostat to 21 degrees" "Lock the front door" "Is the living room motion sensor showing anything?"
Conditional Automations
OpenClaw's reasoning ability goes beyond simple on/off:
"If the bedroom temperature goes above 26 degrees, turn on the AC and send me a message"
OpenClaw subscribes to the temperature topic and acts when the threshold is crossed.
"When the motion sensor detects movement after 11 PM, turn on the hallway light at 30% brightness for 2 minutes, then turn it off"
Scene Management
"Create a 'movie night' scene: living room light at 15%, turn on the TV (topic home/tv/power ON), set thermostat to 22"
Then later:
"Activate movie night"
OpenClaw remembers the scene definition and publishes to all the relevant topics.
Energy Monitoring
If your smart plugs report power consumption via MQTT:
"Track the energy usage on the office plug today. At the end of the day, tell me the total kWh"
OpenClaw subscribes to the power topic, accumulates readings, and reports the summary.
Home Assistant Integration via MQTT
Home Assistant and OpenClaw can share the same MQTT broker, creating a powerful combination[3].
Architecture
Devices → MQTT Broker ← Home Assistant (automations, dashboards)
← OpenClaw (natural language control)
Both Home Assistant and OpenClaw connect to Mosquitto. Home Assistant handles device discovery and complex automations. OpenClaw provides the natural language interface.
Setup
- In Home Assistant, enable the MQTT integration and point it to your Mosquitto broker.
- Configure OpenClaw to connect to the same broker.
- Home Assistant's MQTT auto-discovery publishes device metadata that OpenClaw can read.
Complementary Roles
| Task | Home Assistant | OpenClaw |
|---|---|---|
| Device discovery | Automatic (Zigbee2MQTT, Z-Wave) | Manual topic mapping |
| Dashboard | Web UI with graphs | Telegram conversation |
| Simple automations | YAML or visual editor | Natural language |
| Complex logic | Limited without scripting | Strong (AI reasoning) |
| Remote control | App or web | Telegram from anywhere |
Use Home Assistant for device management and dashboards. Use OpenClaw for intelligent, context-aware control through Telegram.
Example: OpenClaw + Home Assistant
Home Assistant detects that a window sensor opened (via Zigbee2MQTT). OpenClaw is subscribed to that topic:
OpenClaw: "The bedroom window just opened. The forecast shows rain in 2 hours. Want me to set a reminder to close it?"
This contextual awareness — combining sensor data with weather forecasts and personal schedules — is where OpenClaw adds value beyond Home Assistant's rule-based automations.
Security Considerations
Encrypt MQTT Traffic
Use TLS for MQTT connections, especially if the broker is accessible beyond your local network:
# mosquitto.conf
listener 8883
certfile /certs/server.crt
keyfile /certs/server.key
cafile /certs/ca.crt
Update OpenClaw to use the secure port:
openclaw config set mqtt.broker "mqtts://your-broker:8883"
Restrict Topic Access
Use Mosquitto's ACL (Access Control List) to limit which topics OpenClaw can publish to:
# acl_file
user openclaw
topic readwrite home/#
topic deny home/security/#
This prevents OpenClaw from accidentally disabling your security system.
Separate IoT Network
If possible, run your IoT devices on a separate VLAN. The MQTT broker bridges the networks — devices cannot directly access your main network, and your main network only communicates with devices through MQTT.
Audit Logging
Enable Mosquitto logging to track every command OpenClaw sends:
# mosquitto.conf
log_type all
log_dest file /mosquitto/log/mosquitto.log
Review the logs periodically to make sure OpenClaw is only sending expected commands.
Handling Unreliable Devices
IoT devices disconnect, lag, and occasionally misbehave. A few tips:
- Set MQTT QoS to 1 (at least once delivery) for important commands like locks and alarms.
- Use retained messages for state topics so OpenClaw knows the last known state even if a device is temporarily offline.
- Add timeouts — tell OpenClaw: "If a device doesn't acknowledge within 10 seconds, let me know it might be offline."
- Health checks — "Every morning, check if all devices responded in the last 24 hours. Report any that seem offline."
Getting Started
Self-Hosted
- Install Mosquitto on your server
- Install the MQTT skill on OpenClaw
- Configure authentication and device topics
- Start controlling devices via Telegram
Managed
On ClawTank, your OpenClaw instance can connect to any external MQTT broker — including one running on your home network via a VPN or Cloudflare Tunnel. You get the convenience of managed OpenClaw hosting with full control over your local IoT network.
The combination of MQTT's device interoperability and OpenClaw's natural language reasoning creates a smart home controller that actually understands what you mean — not just what you literally say.
