AutomationFlowsAI & RAG › MQTT-Triggered AI Agent with Gemini

MQTT-Triggered AI Agent with Gemini

Original n8n title: Flow

Flow. Uses agent, lmChatGoogleGemini, memoryBufferWindow, mqttTool. Event-driven trigger; 14 nodes.

Event trigger★★★★☆ complexityAI-powered14 nodesAgentGoogle Gemini ChatMemory Buffer WindowMqtt ToolMqtt TriggerMy Sql ToolMySQLTelegram Trigger
AI & RAG Trigger: Event Nodes: 14 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow follows the Agent → Google Gemini Chat recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "schemaVersion": 1,
  "trigger": {
    "id": "t_cron_weekly",
    "type": "cron",
    "graphCoordinates": {
      "x": 0,
      "y": 0
    },
    "appEvent": "cron.tick",
    "options": {
      "schedule": "0 6 * * MON",
      "enabled": true
    }
  },
  "nodes": [
    {
      "id": "n_cron_weekly",
      "name": "Every Monday",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 6 * * MON"
            }
          ]
        }
      }
    },
    {
      "id": "n_adp_fetch",
      "name": "Fetch ADP Earnings",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        240,
        0
      ],
      "parameters": {
        "method": "GET",
        "url": "={{ $vars.ADP_API_BASE }}/payroll/v1/workers/earnings?from={{ $vars.WEEK_START }}&to={{ $vars.WEEK_END }}",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "oAuth2Api"
      },
      "credentials": {
        "oAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "id": "n_split",
      "name": "One Per Employee",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 2,
      "position": [
        480,
        0
      ],
      "parameters": {
        "batchSize": 1
      }
    },
    {
      "id": "n_extract",
      "name": "Extract Fields",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        720,
        0
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "associateOID",
              "value": "={{ $json.associateOID }}"
            },
            {
              "name": "grossPay",
              "value": "={{ $json.earnings.gross }}"
            },
            {
              "name": "netPay",
              "value": "={{ $json.earnings.net }}"
            },
            {
              "name": "weekEnding",
              "value": "={{ $json.payPeriod.endDate }}"
            }
          ]
        }
      }
    },
    {
      "id": "n_mongo_upsert",
      "name": "Upsert in Mongo",
      "type": "n8n-nodes-base.mongoDb",
      "typeVersion": 1,
      "position": [
        960,
        -100
      ],
      "parameters": {
        "operation": "update",
        "collection": "adp_earnings",
        "updateKey": "associateOID",
        "upsert": true
      },
      "credentials": {
        "mongoDb": {
          "name": "<your credential>"
        }
      }
    },
    {
      "id": "n_airtable_upsert",
      "name": "Upsert in Airtable",
      "type": "n8n-nodes-base.airtable",
      "typeVersion": 1,
      "position": [
        960,
        100
      ],
      "parameters": {
        "operation": "upsert",
        "application": "={{ $vars.AIRTABLE_BASE_ID }}",
        "table": "Payroll",
        "matchingColumns": "associateOID"
      },
      "credentials": {
        "airtableApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "n_cron_weekly": {
      "main": [
        [
          {
            "node": "n_adp_fetch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "n_adp_fetch": {
      "main": [
        [
          {
            "node": "n_split",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "n_split": {
      "main": [
        [
          {
            "node": "n_extract",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "n_extract": {
      "main": [
        [
          {
            "node": "n_mongo_upsert",
            "type": "main",
            "index": 0
          },
          {
            "node": "n_airtable_upsert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "groups": [
    {
      "id": "g_main",
      "title": "Main",
      "graphCoordinates": {
        "x": 0,
        "y": 0
      },
      "blockIds": [
        "n_cron_weekly",
        "n_adp_fetch",
        "n_split",
        "n_extract",
        "n_mongo_upsert",
        "n_airtable_upsert"
      ]
    }
  ],
  "variables": [
    {
      "id": "v_adp",
      "name": "ADP_API_BASE",
      "defaultValue": "https://api.adp.com"
    },
    {
      "id": "v_ws",
      "name": "WEEK_START",
      "defaultValue": ""
    },
    {
      "id": "v_we",
      "name": "WEEK_END",
      "defaultValue": ""
    },
    {
      "id": "v_air",
      "name": "AIRTABLE_BASE_ID",
      "defaultValue": ""
    }
  ],
  "events": [],
  "settings": {
    "executionOrder": "v1"
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

How this works

This workflow enables real-time, intelligent responses to IoT device events by leveraging an AI agent powered by Google Gemini, ensuring seamless interaction between your sensors and a MySQL database for data-driven decisions. It's ideal for developers or teams managing smart home systems, industrial monitoring, or any setup where MQTT messages trigger automated analysis and actions. The key step involves the AI agent processing incoming MQTT payloads with contextual memory, querying the database schema to fetch relevant insights before generating tailored outputs.

Use this workflow when you need event-driven automation that combines IoT triggers with AI reasoning for dynamic database interactions, such as alerting on anomaly detection in sensor data. Avoid it for simple, rule-based tasks without AI involvement, or if your setup lacks MQTT infrastructure. Common variations include swapping Gemini for another LLM or adding email notifications for critical alerts.

About this workflow

Flow. Uses agent, lmChatGoogleGemini, memoryBufferWindow, mqttTool. Event-driven trigger; 14 nodes.

Source: https://github.com/Laznology/smart-garden/blob/5bd8b501abf7fd1a85c222087b561cade0aa8bdd/n8n/flow.json — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

Arvifund - Supabase (Fixed v6). Uses httpRequest, telegram, supabase, telegramTrigger. Event-driven trigger; 92 nodes.

HTTP Request, Telegram, Supabase +8
AI & RAG

Arvifund - Supabase (Fixed v5). Uses httpRequest, telegram, googleSheets, telegramTrigger. Event-driven trigger; 91 nodes.

HTTP Request, Telegram, Google Sheets +9
AI & RAG

Arvifund - Supabase. Uses httpRequest, telegram, googleSheets, telegramTrigger. Event-driven trigger; 90 nodes.

HTTP Request, Telegram, Google Sheets +8
AI & RAG

Arvifund - Supabase (Fixed v2). Uses httpRequest, telegram, googleSheets, telegramTrigger. Event-driven trigger; 90 nodes.

HTTP Request, Telegram, Google Sheets +9
AI & RAG

Arvifund - Supabase (Fixed v4). Uses httpRequest, telegram, googleSheets, telegramTrigger. Event-driven trigger; 90 nodes.

HTTP Request, Telegram, Google Sheets +9