This workflow corresponds to n8n.io template #15566 — we link there as the canonical source.
This workflow follows the Agent → Chat Trigger 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 →
{
"id": "OKiZOZQKpySBPNRa",
"name": "Control SwitchBot devices with AI via chat",
"tags": [],
"nodes": [
{
"id": "f3e5e3a9-2fa2-4ab8-b5aa-e04e07c45f61",
"name": "Get Auth",
"type": "n8n-nodes-base.code",
"position": [
736,
464
],
"parameters": {
"jsCode": "const crypto = require('crypto');\n\nconst token = `${$input.first().json.token}`;\nconst secret = `${$input.first().json.secret}`;\nconst t = Date.now();\nconst nonce = \"123456789\";\nconst data = token + t + nonce;\nconst sign = crypto\n .createHmac('sha256', secret)\n .update(data)\n .digest('base64');\nreturn {\n 'Authorization': token,\n 'sign': sign,\n 'nonce': nonce,\n 't': t\n};\n"
},
"typeVersion": 2
},
{
"id": "5ffce505-435b-4fb2-b191-cc6f81344ff7",
"name": "When chat message received",
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"position": [
0,
464
],
"parameters": {
"options": {}
},
"typeVersion": 1.4
},
{
"id": "d89512f8-c931-4a16-801b-0d5a87c92230",
"name": "OpenRouter Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
"position": [
1424,
704
],
"parameters": {
"model": "openai/gpt-oss-120b:free",
"options": {}
},
"credentials": {
"openRouterApi": {
"name": "<your credential>"
}
},
"typeVersion": 1
},
{
"id": "489fa754-1ad9-40f8-b3e3-3468725269b7",
"name": "Set Credentials",
"type": "n8n-nodes-base.set",
"position": [
320,
464
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "716b1818-dafb-414b-b6b9-d7e95144110b",
"name": "token",
"type": "string",
"value": ""
},
{
"id": "b1e1d8fb-e6c9-4c8e-8dd3-1733ad6bbab5",
"name": "secret",
"type": "string",
"value": ""
}
]
}
},
"typeVersion": 3.4
},
{
"id": "693a6b03-4af0-4cf7-82e4-a5f065c5cfbf",
"name": "Get Device List",
"type": "n8n-nodes-base.httpRequest",
"position": [
1120,
464
],
"parameters": {
"url": "=https://api.switch-bot.com/v1.1/devices",
"options": {},
"jsonHeaders": "={\n \"Authorization\": \"{{ $json.Authorization }}\",\n \"sign\": \"{{ $json.sign }}\",\n \"nonce\": \"{{ $json.nonce }}\",\n \"t\": {{ $json.t }}\n}",
"sendHeaders": true,
"specifyHeaders": "json"
},
"typeVersion": 4.4
},
{
"id": "b3282d1d-09cf-49ea-a5a3-c3291c0d02ad",
"name": "Generate API Request with AI",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
1424,
464
],
"parameters": {
"text": "=You are a SwitchBot device manager.\nBased on the user's request, generate the URL and request body for the SwitchBot API command.\n\nReturn *only* a JSON object with the following structure \u2014 no markdown, no labels, no explanation:\n{\n \"url\": (the URL you generate),\n \"body\": (the request body you generate)\n}\n\nHere are the devices the user owns:\n|field|value|\n|-|-|\n|deviceList|{{ JSON.stringify($json.body.deviceList) }}|\n|infraredRemoteList|{{ $json.body.infraredRemoteList }}|\n\nThe user's request is:\n'{{ $('When chat message received').item.json.chatInput }}'",
"options": {
"systemMessage": "=Always refer to the official SwitchBot API documentation when generating your output. The URL and request body must follow the spec exactly.\n\nDevices can be either `IR = true` or `IR = false`.\nFor `IR = true` devices, refer to the 'Command set for virtual infrared remote devices' section.\n\nAPI docs: https://github.com/OpenWonderLabs/SwitchBotAPI#send-device-control-commands"
},
"promptType": "define"
},
"typeVersion": 3.1
},
{
"id": "73e32520-3377-45df-a6f1-d0914588c7a2",
"name": "Send Device Command",
"type": "n8n-nodes-base.httpRequest",
"position": [
1792,
464
],
"parameters": {
"url": "={{JSON.parse($json.output).url}}",
"method": "POST",
"options": {},
"jsonBody": "={{ JSON.parse($json.output).body }}",
"sendBody": true,
"jsonHeaders": "={\n \"Authorization\": \"{{ $('Get Auth').item.json.Authorization }}\",\n \"sign\": \"{{ $('Get Auth').item.json.sign }}\",\n \"nonce\": \"{{ $('Get Auth').item.json.nonce }}\",\n \"t\": {{ $('Get Auth').item.json.t }},\n \"Content-Type\":\"application/json; charset=utf8\"\n}",
"sendHeaders": true,
"specifyBody": "json",
"specifyHeaders": "json"
},
"typeVersion": 4.4
},
{
"id": "7fe198e8-eff9-421b-b96c-546ae5e04f2b",
"name": "Workflow Overview",
"type": "n8n-nodes-base.stickyNote",
"position": [
0,
0
],
"parameters": {
"width": 660,
"height": 420,
"content": "## Control SwitchBot Devices with AI via Chat\n\n**What this workflow does:**\nThis workflow lets you control your SwitchBot smart home devices using natural language chat. Tell the AI what you want to do (e.g. \"turn off the living room light\"), and it will look up your devices, generate the correct SwitchBot API command, and send it automatically.\n\n**Workflow steps:**\n1. **When chat message received** \u2014 triggered by a user message in the n8n chat interface\n2. **Set Credentials** \u2014 stores your SwitchBot API token and secret\n3. **Get Auth** \u2014 generates a signed authentication header using HMAC-SHA256\n4. **Get Device List** \u2014 fetches all registered devices from the SwitchBot API\n5. **Generate API Request with AI** \u2014 the AI reads the device list and user request, then generates the correct API URL and body\n6. **Send Device Command** \u2014 sends the POST request to SwitchBot to execute the command\n\n**Requirements:**\n- SwitchBot account with API token and secret\n- OpenRouter API credentials (or swap for any compatible LLM)"
},
"typeVersion": 1
},
{
"id": "6ee3a2e7-5d69-47a4-8e32-a6f6e2a0c34c",
"name": "Note: Set Credentials",
"type": "n8n-nodes-base.stickyNote",
"position": [
224,
640
],
"parameters": {
"color": 4,
"width": 300,
"height": 192,
"content": "**Set Credentials**\n\u2699\ufe0f Enter your SwitchBot credentials here:\n- `token`: Your SwitchBot API token\n- `secret`: Your SwitchBot API secret\n\nFind these in the SwitchBot app under **Profile \u2192 Preferences \u2192 App Version** (tap 10 times to reveal)."
},
"typeVersion": 1
},
{
"id": "26d2d38c-bf16-43ca-960e-f9eeaa49fcfe",
"name": "Note: Get Auth",
"type": "n8n-nodes-base.stickyNote",
"position": [
656,
640
],
"parameters": {
"color": 7,
"width": 260,
"height": 120,
"content": "**Get Auth**\nGenerates a signed HMAC-SHA256 authentication header required by the SwitchBot API v1.1. No changes needed here."
},
"typeVersion": 1
},
{
"id": "a607405b-27e9-46c4-ac84-56e83f0d1cb1",
"name": "Note: AI Agent",
"type": "n8n-nodes-base.stickyNote",
"position": [
1392,
240
],
"parameters": {
"color": 7,
"width": 300,
"height": 188,
"content": "**Generate API Request with AI**\nThe AI reads the full device list and the user's chat message, then generates the correct SwitchBot API endpoint and request body.\n\nPowered by OpenRouter \u2014 swap the model in the **OpenRouter Chat Model** node if needed."
},
"typeVersion": 1
}
],
"active": false,
"settings": {
"binaryMode": "separate",
"executionOrder": "v1"
},
"versionId": "35edeb12-ece0-4fd0-ad02-bf007ea36139",
"connections": {
"Get Auth": {
"main": [
[
{
"node": "Get Device List",
"type": "main",
"index": 0
}
]
]
},
"Get Device List": {
"main": [
[
{
"node": "Generate API Request with AI",
"type": "main",
"index": 0
}
]
]
},
"Set Credentials": {
"main": [
[
{
"node": "Get Auth",
"type": "main",
"index": 0
}
]
]
},
"OpenRouter Chat Model": {
"ai_languageModel": [
[
{
"node": "Generate API Request with AI",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"When chat message received": {
"main": [
[
{
"node": "Set Credentials",
"type": "main",
"index": 0
}
]
]
},
"Generate API Request with AI": {
"main": [
[
{
"node": "Send Device Command",
"type": "main",
"index": 0
}
]
]
}
}
}
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.
openRouterApi
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
What this workflow does: This workflow lets you control your SwitchBot smart home devices using natural language chat. Tell the AI what you want to do (e.g. "turn off the living room light"), and it will look up your devices, generate the correct SwitchBot API command, and send…
Source: https://n8n.io/workflows/15566/ — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
This comprehensive workflow automates the complete financial document processing pipeline using AI. Upload invoices via chat, drop expense receipts into a folder, or add bank statements - the system a
Turn any YouTube channel into a searchable knowledge base. The AI agent understands relationships between videos, topics, tools, and concepts - enabling powerful queries like "Which videos talk about
⚠️ Important: This workflow uses community nodes (JsonCut, Blotato) and requires a self-hosted n8n instance.
[](https://youtu.be/D11S0s3PDNc)
This n8n template demonstrates a simple AI Agent that can: Scrape information from a provided listing link. Answer questions about a specific property using the scraped information. Use SerpAPI* to fi