📡

MQTT Control & Monitor

Verified

by OpenClaw Launch

Publish commands to and subscribe to any MQTT broker directly from chat to control and monitor IoT devices, smart plugs, sensors, Zigbee2MQTT, Tasmota/ESPHome firmware and Home Assistant MQTT. Ships a dependency-free pure-Python helper (no pip install needed) supporting plaintext, TLS and self-signed brokers with optional username/password auth and QoS.

mqttiotdevice-controlsensorssmart-home

MQTT Control & Monitor

You can publish commands to and read live messages from any MQTT broker — controlling and monitoring IoT devices, sensors, smart plugs, Zigbee2MQTT, Tasmota/ESPHome firmware, and Home Assistant's MQTT integration. This performs real publish/subscribe over the wire.

This skill ships a dependency-free helper script mqtt_cli.py (pure Python standard library — no pip install needed). Locate it once and reuse the path:

MQTT=$(ls ~/.openclaw/skills/mqtt-control/mqtt_cli.py /opt/data/skills/mqtt-control/mqtt_cli.py 2>/dev/null | head -1)
echo "$MQTT"

Setup (ask once, then remember for the session)

Ask the user for their broker details:

  • Host and port (default 1883 plaintext, 8883 for TLS)
  • Username and password if the broker requires them
  • Whether the broker uses TLS (and whether its certificate is self-signed)

Read messages from a topic (subscribe)

Read the next N retained/published messages on a topic, then return:

python3 "$MQTT" sub --host BROKER_HOST --port 1883 --topic 'home/+/temperature' --count 5 --timeout 15

Wildcards: + matches one level, # matches all remaining levels (e.g. home/#). Output is JSON: {"ok":true,"messages":[{"topic":"...","payload":"..."}]}.

With auth:

python3 "$MQTT" sub --host BROKER_HOST --port 1883 --user USER --password PASS --topic 'zigbee2mqtt/#' --count 3 --timeout 10

Send a command (publish)

python3 "$MQTT" pub --host BROKER_HOST --port 1883 --topic 'home/livingroom/light/set' --message 'ON' --qos 1

Common real-world examples:

  • Tasmota plug on/off: topic cmnd/tasmota_ABC/POWER, message ON or OFF
  • Zigbee2MQTT device set: topic zigbee2mqtt/kitchen_light/set, message {"state":"ON","brightness":120}
  • Home Assistant MQTT light: topic from the user's HA MQTT config

Use --retain to publish a retained message (new subscribers immediately get the last value).

TLS brokers

Add --tls. Use this form when the broker has a certificate from a public authority (Let's Encrypt, HiveMQ Cloud, EMQX Cloud):

python3 "$MQTT" pub --host BROKER_HOST --port 8883 --tls --user USER --password PASS \
  --topic 'home/garage/door/set' --message 'CLOSE' --qos 1

If the broker uses a self-signed certificate (common on self-hosted Mosquitto), also add --insecure — without it the connection fails with a certificate-verification error:

python3 "$MQTT" pub --host BROKER_HOST --port 8883 --tls --insecure --user USER --password PASS \
  --topic 'home/garage/door/set' --message 'CLOSE' --qos 1

Guidelines

  • Publishing a command physically actuates a device — confirm before anything safety-relevant (locks, garage doors, heaters).
  • When the user does not know the exact topic, subscribe to a broad wildcard (# or zigbee2mqtt/#) for a few seconds to discover live topics first.
  • A connection timeout usually means the broker is not reachable from the bot host — the user's broker must accept connections from the internet, or you both must be on the same network/VPN.
  • Payloads are sent and read as UTF-8 text; JSON payloads are passed through verbatim.