← Back to Blog

How to Run an AI IoT & MQTT Agent with OE Runtime

Subscribe to sensor feeds and publish commands to IoT devices via MQTT. OE Runtime lets you run a local AI agent that monitors device data, evaluates thresholds, and publishes automated responses — no IoT platform subscription required.

📡
Step 1
Read Sensor Data
Subscribe to the sensor topic and read the latest 5 messages with device ID, value, unit, and timestamp.
Step 2
Evaluate & Publish Command
Analyse readings against thresholds and publish the appropriate control command as a JSON payload.
Step 3
Report
Summarise sensor readings, threshold breaches, commands published, and current system status.

What You Need


Create the Project Folder

Create a folder called iot-messaging/ and add these two files:

iot-messaging/
├── SKILL.md         # the portable skill (agentskills.io)
├── agent.yaml       # wires SKILL.md to your connector
└── oe-config.json  # LLM key + connector credentials

The Skill Files

Create SKILL.md inside an iot-messaging/ directory. This is the portable skill — it follows the agentskills.io format and runs unchanged on Claude, Cursor, Windsurf, or OE Runtime:

---
name: iot-messaging
description: Publish commands and read sensor data via MQTT
license: Apache-2.0
metadata:
  author: Open Enthrium
  version: "1.0"
---

You are an IoT agent. Subscribe to sensor data feeds and publish commands to devices via MQTT.
Format all messages as JSON. Always read current state before publishing any commands.
Complete all steps fully before writing your report.

## Step 1: Read Sensor Data
Subscribe to the sensor data topic and read the latest 5 messages.
Extract: device ID, sensor type, value, unit, and timestamp for each message.

## Step 2: Evaluate and Publish Command
Analyze the sensor readings:
- If any temperature reading exceeds 30°C, publish a cooling command to the control topic
- If any humidity reading exceeds 80%, publish a ventilation command
- Otherwise publish a status check ping to the control topic
All commands must be JSON with fields: action, device_id, timestamp, triggered_by.

## Step 3: Report
Summarize IoT activity:
- Sensor readings received (device, value, unit)
- Any threshold breaches detected
- Commands published (topic, payload)
- Current system status (normal / alert)

Create agent.yaml in the same directory to wire the skill to your connector:

name: IoT Agent
description: Publish commands and read sensor data via MQTT
connectors:
  - connection_name: MQTT Broker
    connection_type: mqtt
skills:
  - path: ./
    trigger_type: auto

The Config File

Create oe-config.json in the same directory:

{
  "llm": {
    "provider": "openai",
    "model": "gpt-4o",
    "apiKey": "YOUR_OPENAI_API_KEY"
  },
  "server": {
    "enabled": false,
    "port": 3333,
    "apiKey": "your-secret-api-key"
  },
  "connectors": [
    {
      "connection_name": "MQTT Broker",
      "connection_type": "mqtt",
      "broker": "mqtt://localhost:1883",
      "clientId": "oe-runtime",
      "topic": "devices/#",
      "username": "YOUR_MQTT_USER",
      "password": "YOUR_MQTT_PASSWORD"
    }
  ]
}

Replace the broker URL with your MQTT broker address. This works with any MQTT broker including Mosquitto, HiveMQ, AWS IoT Core, and Azure IoT Hub. Remove username/password fields if your broker does not require authentication.

Download OE Runtime

OE Runtime — Direct Downloads

Run the Agent

From the parent folder containing your skill directory:

MethodBest forDownload
1 npx recommended No install needed — always runs the latest version —
2 Windows .exe Download once, run offline on Windows ⊞ Windows (.exe)
3 macOS binary Download once, run offline on Mac  macOS
4 Linux binary Server deployments, cron jobs, Docker 🐧 Linux
5 API Server integration Call from any app, webhook, or automation pipeline 📮 Postman Collection

1 npx recommended

npx -y @openenthrium/oe-runtime@latest ./iot-messaging

2 Windows

oe-runtime-win.exe ./iot-messaging

3 macOS

chmod +x oe-runtime-macos
./oe-runtime-macos ./iot-messaging

First run blocked? System Settings → Privacy & Security → Allow Anyway.

4 Linux

chmod +x oe-runtime-linux
./oe-runtime-linux ./iot-messaging

5 API Server integration

Add a "server" block to oe-config.json, then start with --serve:

{
  "llm": { ... },
  "server": { "enabled": true, "port": 3333, "apiKey": "your-secret-key" },
  "connectors": [ ... ]
}
npx -y @openenthrium/oe-runtime@latest --serve --config oe-config.json

Run with inline YAML:

curl -X POST http://localhost:3333/run \
  -H "Content-Type: application/json" \
  -H "X-API-Key: your-secret-key" \
  -d '{"yaml": "...", "params": {}}'

Or run from a file on the server:

curl -X POST http://localhost:3333/run-file \
  -H "Content-Type: application/json" \
  -H "X-API-Key: your-secret-key" \
  -d '{"file": "/path/to/agent.yaml", "params": {}}'

Use Cases

Build your own agents with OE Runtime

Download OE Runtime and run any AI agent locally or as a server — no cloud required.

Get OE Runtime →
Series OE Runtime Agent Guides — 21 Connectors
Series overview →