Real-time IoT anomaly detection with MQTT, GPT-4o-mini AI, and multi-channel alerts
Ready for 3.0What this workflow does
This AI workflow has 17 nodes and runs on MQTT events (plus 1 other trigger). Along the way it connects MQTT, Postgres, OpenAI Chat Model and Slack.
How it runs
Trigger: On MQTT events (plus 1 other trigger).
- Workflow Configuration (Edit Fields (Set)): sets 5 fields: anomalyThreshold, dashboardApiUrl, slackChannel…
- Fetch Historical Data for Retraining (Postgres): run a query
- Edge Preprocessing & Validation (Code): runs custom JavaScript code
- Retrain ML Model via API (HTTP Request): calls an HTTP API (POST)
- Normalize Sensor Data (Edit Fields (Set)): sets 7 fields: sensor_id, timestamp, value…
- Store Raw Data in Time-Series DB (Postgres): uses Postgres
- Aggregate: combines items into one
- Statistical Anomaly Detection (Code): runs custom JavaScript code
- AI Anomaly Detection Agent (AI Agent): runs an AI agent, with model: OpenAI Chat Model
- Check for Anomalies (If): checks a condition and branches into true / false
…plus 4 more steps. See the full node list below.
Services it uses
Before you upgrade to n8n 3.0
Nothing in this workflow is removed in n8n 3.0, so it should import and run after the upgrade.
Nodes used (12)
- MQTT Trigger
n8n-nodes-base.mqttTrigger - Edit Fields (Set)
n8n-nodes-base.set - Code
n8n-nodes-base.code - Postgres
n8n-nodes-base.postgres - Aggregate
n8n-nodes-base.aggregate - AI Agent
@n8n/n8n-nodes-langchain.agent - OpenAI Chat Model
@n8n/n8n-nodes-langchain.lmChatOpenAi - If
n8n-nodes-base.if - HTTP Request
n8n-nodes-base.httpRequest - Slack
n8n-nodes-base.slack - Send Email
n8n-nodes-base.emailSend - Schedule Trigger
n8n-nodes-base.scheduleTrigger
From the author
How It Works MQTT ingests real-time sensor data from connected devices. The workflow normalizes the values and trains or retrains machine learning models on a defined schedule. An AI agent detects anomalies, validates the results for accuracy, and ensures…