$cd ../integrations/
🔌 IoT IntegrationPRO15 min setup

AI for IoT: MQTT Pub/Sub

/** Enable OpenClaw to listen to thousands of sensory data streams and flip physical switches in the real world using the lightweight MQTT protocol. */

intelligent_iot.log

Sentient Logic for Hardware

Instead of writing fragile, hardcoded rules in Node-RED or Home Assistant, OpenClaw provides a direct Bridge to your MQTT broker. By pushing high-frequency telemetry states to the LLM and granting publish rights, it becomes a sentient logic engine. It doesn't just 'run a script'; it infers intent based on sensor context—like dimming lights when a lux sensor drops and a person is detected, without explicit IF/THEN blocks.

broker.sh

1. Broker Setup (Mosquitto/EMQX)

We assume you have a broker running locally. For optimal performance, ensure your broker is accessible on the same VPC or subnet as OpenClaw.

# Mosquitto Docker launch docker run -d -p 1883:1883 eclipse-mosquitto
mcp_bridge.json

2. The MCP-to-MQTT Bridge

OpenClaw uses a universal bridge that translates MQTT messages into MCP resources. You don't need to write Python boilerplate; just declare your broker credentials in your configuration.

"command": "npx", "args": ["@clawdhub/mcp-mqtt-bridge"]
workflow.md

3. IoT Workflow: Sense & Act

Broadcasting your entire sensor tree can overwhelm context windows. We recommend using specific 'Exposed Topics' to keep the agent focused on relevant telemetry.

  • [1]mqtt_subscribe(topic): Read real-time payloads from any subscribed path.
  • [2]mqtt_publish(topic, payload): Execute physical actions by sending commands to actuators.
prompts_library.log

4. Practical Automation Examples

Sensory Intelligence
  • "Check the living room CO2 levels on home/sensors/air/co2."
  • "Is the garden soil moisture below 20% on home/garden/soil/1?"
Hardware Actuation
  • "Open the window if CO2 > 1000ppm by publishing 'OPEN' to home/actuators/window/cmd."
  • "Trigger the irrigation system on home/garden/pump/set."

🛡️ Safety & Edge Intelligence

CRITICAL: Language models can hallucinate. Never grant mqtt_publish access to life-critical infrastructure or high-heat appliances without physical, hard-wired failsafes. Use specific Topic ACLs (Access Control Lists) in your Mosquitto configuration to restrict OpenClaw's reach to non-critical devices.

❓ FAQ

Q1. Which MQTT brokers are supported?

Any standard MQTT 3.1.1/5.0 broker: Mosquitto, HiveMQ, EMQX, AWS IoT Core, etc.

Q2. Can it control devices?

Yes. OpenClaw can publish messages to MQTT topics to control lights, switches, and any MQTT-enabled device.
← Back to Integrations