使用说明
更聪明的东西
统一智能家居控制平台 一个双模服务器,提供人工智能助手的模型上下文协议(MCP)集成和Alexa自定义技能支持,并具有强大的跨平台设备管理统一功能系统。
🎯 什么是更聪明的东西?
更聪明的东西 是一个全面的智能家居集成服务器,将人工智能助理和语音助理与您的家庭自动化设备连接起来。它提供:
- 🤖 MCP服务器 Claude AI和其他LLM助理
- 🗣️ Alexa自定义技能 用于自然语言语音控制
- 🔄 统一能力体系 规范SmartThings、Tuya和Lutron设备
- 🛡️ 类型安全架构 使用TypeScript严格模式和品牌类型
- ⚡ 生产准备就绪 具有自动重试、结构化日志记录和全面测试功能
使用案例:
- 使用自然语言通过Claude Desktop控制您的智能家居
- 在人工智能的帮助下构建自定义自动化工作流程
- 通过Alexa进行语音控制,配备对话式人工智能(LLM驱动的响应)
- 通过单一界面跨多个平台(SmartThings、Tuya、Lutron)管理设备
- 使用类型安全、文档齐全的API开发智能家居应用程序
🔌 支持的集成
智能家居平台
- SmartThings -主要平台,原生支持184+种设备类型
- 台湾路昌 -通过SmartThings集成提供优质照明和电动遮阳控制(安装指南)
- 杰出的 -智能家居控制面板,通过SmartThings集成集成开关、调光器和摄像头(安装指南)
- 图雅 -广泛的智能家居设备,96%的功能覆盖率
设备支持
MCP SmartThings仪表板支持:
- 照明 -开关、调光器、彩色灯泡(RGB/RGBW)、色温控制
- 遮阳帘和百叶窗 -带位置控制的电动窗帘(Lutron Serena、Sivoia QS)
- 气候 -恒温器、温度传感器、湿度传感器
- 安全 -锁、接触传感器、运动传感器、摄像头
- 能量 -智能插头、电表、能源监测
- 多组面板 -卓越的控制面板(2、3和4组配置)
- 场景与自动化 -跨平台场景执行和调度
集成功能
- 通过SmartThings Hub -Lutron和Brilliant设备通过SmartThings集成(不需要额外的API)
- 统一控制 -所有设备都显示在一个仪表板上,无论制造商如何
- 跨平台自动化 -创建跨多个平台的自动化
- 实时状态 -所有集成平台上的实时设备状态更新
注: Lutron和Brilliant需要各自的桥接器/面板,并通过SmartThings移动应用程序进行集成。有关详细说明,请参阅单独的设置指南。
✨ 特性
🤖 MCP服务器功能
- 设备发现和控制 -列出、查询和控制所有SmartThings设备
- 场景管理 -执行和管理SmartThings场景
- 房间组织 -按房间/位置过滤设备和场景
- 实时状态 -获取当前设备状态和传感器读数
- 多个传输 -支持stdio(CLI)和HTTP/SSE(web)
- MCP协议1.22.0 -完全符合最新的MCP规范
🗣️ Alexa集成
- 自定义技能支持 -LLM支持的自然语言语音控制
- 对话式AI -通过ChatOrchestrator进行上下文感知响应
- MCP工具执行 -Alexa请求在引擎盖下执行MCP工具
- 轻松设置 -使用ngrok快速部署以进行开发/测试
🔄 统一能力体系
Smarter Things的核心是 平台无关能力抽象 该标准化了跨多个智能家居平台的设备控制:
主要特点:
- 31统一功能 -11控制+15传感器+5复合功能
- 3平台支持 -SmartThings(100%)、Tuya(96%)、Lutron(19%)
- 自动值转换 -亮度、颜色和格式规范化
- 运行时检测 -类型安全功能查询和特征检测
- 双向映射 -无缝平台↔ 统一格式翻译
- 基于事件的架构 -支持实时设备事件
平台覆盖范围:
| 平台 | 功能 | 覆盖范围 | 显著功能 |
|---|---|---|---|
| SmartThings | 31/31 | 100% | 完整的智能家居自动化生态系统 |
| 图雅 | 30/31 | 96% | 设备可用性广(缺少OCCUPANCY_SENSOR) |
| 台湾路昌 | 6/31 | 19% | 高级照明和遮阳专家 |
示例用法:
import { DeviceCapability, hasCapability } from './types/unified-device.js';
// Check if device supports dimming (works across all platforms)
if (hasCapability(device, DeviceCapability.DIMMER)) {
// Set brightness to 50% - automatically converts to platform format
// Tuya: 500 (0-1000 scale)
// SmartThings: 50 (0-100 scale)
// Lutron: 50.00 (precision format)
await device.capabilities.dimmer.commands.setLevel(50);
}
🛡️ 开发者体验
- TypeScript 5.6+ -严格模式,品牌类型,域名安全
- 综合测试 -单元、集成和E2E测试套件
- 丰富的文档 -广泛的指南、API参考资料和示例
- 开发者工具 -交互式REPL、MCP检查器、shell助手
- 结构化日志记录 -Winston使用JSON格式进行生产监控
- 错误处理 -具有自动重试和指数回退的弹性
🏗️ 架构概述
系统架构
┌─────────────────────────────────────────────────────────────┐
│ Client Layer │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Claude AI │ │ Alexa Skill │ │ Custom Apps │ │
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
└─────────┼──────────────────┼──────────────────┼─────────────┘
│ │ │
│ MCP Protocol │ Custom Skill │ HTTP/SSE
│ │ API │
┌─────────▼──────────────────▼──────────────────▼─────────────┐
│ MCP SmartThings Server │
│ ┌────────────────────────────────────────────────────────┐ │
│ │ MCP Tools & Endpoints │ │
│ │ • Device Control • Scene Management • Status Query │ │
│ └────────────────────────────────────────────────────────┘ │
│ ┌────────────────────────────────────────────────────────┐ │
│ │ Layer 2: Unified Capabilities │ │
│ │ • Type-Safe Interfaces • Value Conversion │ │
│ │ • Runtime Detection • Event Handling │ │
│ └────────────────────────────────────────────────────────┘ │
│ ┌────────────────────────────────────────────────────────┐ │
│ │ Layer 1: Platform Adapters │ │
│ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │
│ │ │ SmartThings │ │ Tuya │ │ Lutron │ │ │
│ │ │ Adapter │ │ Adapter │ │ Adapter │ │ │
│ │ └──────────────┘ └──────────────┘ └──────────────┘ │ │
│ └────────────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────────────────────────────────────────────────┐
│ Smart Home Platforms │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ SmartThings │ │ Tuya Cloud │ │Lutron Caséta │ │
│ │ API │ │ API │ │ API │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────┘
第2层抽象:统一功能
这 第2层抽象 为设备控制提供了一个平台无关的接口:
核心组件:
- 能力定义 -31个标准化功能(开关、调光器、恒温器等)
- 值转换器 -亮度、温度、颜色格式的自动归一化
- 类型系统 -带有品牌类型的TypeScript接口,用于编译时安全
- 运行时检测 -
hasCapability()安全特征查询函数
值转换示例:
// Brightness (Dimmer capability)
SmartThings: 0-100 → Unified: 0-100 → Tuya: 0-1000
SmartThings: 75 → Unified: 75 → Tuya: 750
// Color Temperature (Color Temperature capability)
SmartThings: 2700K → Unified: 2700K → Tuya: 370 mireds
Tuya: 370 mireds → Unified: 2700K → SmartThings: 2700K
// Temperature (Temperature Measurement capability)
SmartThings: 72°F → Unified: 22.2°C → Tuya: 22.2°C
平台注册表:
这 PlatformRegistry 管理多个平台适配器,并根据设备上下文将请求路由到适当的平台。
📋 先决条件
- Node.js 18.0.0或更高
- pnpm 9.0.0或更高版本(推荐使用包管理器)
- SmartThings帐户 至少配置了一个设备
- SmartThings个人访问令牌(PAT) -API身份验证需要
- OpenRouter API密钥 (可选)-用于聊天机器人界面
- ngrok账户 (可选)-用于Alexa自定义技能开发
🚀 入门指南
快速安装(推荐)
最快的入门方法是使用自动安装命令:
# 1. Install globally
npm install -g @bobmatnyc/mcp-smarterthings
# 2. Auto-detect and install for your agentic systems
mcp-smartthings install
# 3. Configure your SmartThings token
mcp-smartthings config
这将自动:
- 检测已安装的代理系统(Claude Desktop、Claude Code、Codex、Gemini CLI、Auggie)
- 将MCP服务器配置添加到每个系统
- 保留现有的MCP服务器(非破坏性)
- 设置正确的包路径
支持的系统:
- ✅ 克劳德桌面(macOS/Windows)
- ✅ 克劳德代码(CLI)
- ✅ Codex(带TOML配置的CLI)
- ✅ 双子座命令行界面
- ✅ 奥吉
看 安装指南 有关详细说明和选项。
手动安装(开发)
对于开发或手动设置:
1.克隆和安装
# Clone the repository
git clone https://github.com/bobmatnyc/smarterthings
cd smarterthings
# Install dependencies
pnpm install
2.获取SmartThings个人访问令牌(PAT)
- 首选 SmartThings个人访问令牌
- 点击“生成新令牌”
- 输入令牌名称(例如“MCP服务器”)
- 选择以下范围:
r:devices:*(读取设备)x:devices:*(在设备上执行命令)r:scenes:*(阅读场景)x:scenes:*(执行场景)r:locations:*(读取位置/房间)
- 点击“生成令牌”
- 立即复制令牌 (您将无法再看到它)
3.配置
创建 .env 项目根目录中的文件:
cp .env.example .env
编辑 .env 并添加您的SmartThings PAT:
SMARTTHINGS_PAT=your_personal_access_token_here
MCP_SERVER_NAME=smartthings-mcp
MCP_SERVER_VERSION=1.0.0
MCP_SERVER_PORT=3000
NODE_ENV=development
LOG_LEVEL=info
TRANSPORT_MODE=stdio
4.建造
pnpm build
5.运行开发环境
推荐:全栈开发(后端+前端Web UI)
# Start both backend (port 5182) and frontend (port 5181)
./scripts/dev-start.sh
# Or use npm/pnpm script
pnpm start:dev
这将:
- ✅ 在端口5182上启动后端MCP服务器
- ✅ 在端口5181上启动前端web UI
- ✅ 为API调用配置代理
- ✅ 显示组合日志
- ✅ 代码更改时自动重新加载
接入点:
- 前端Web UI:http://localhost:5181
- 后端API:http://localhost:5182/api
- 后端健康:http://localhost:5182/health
单个服务器启动:
仅后端(端口5182):
pnpm dev
仅限前端(端口5181):
pnpm dev:web
生产方式:
npm start
端口配置:
端口被锁定以确保一致性:
- 后端: 5182 (配置于
.env.local和src/config/environment.ts) - 前端: 5181 (配置于
web/vite.config.ts)
看 docs/PORT配置.md 详情或 docs/QUICK-START.md 以供快速参考。
🎮 使用模式
模式1:Claude桌面的MCP服务器
将Claude Desktop配置为使用Smarter Things作为MCP服务器:
添加到您的Claude桌面配置 (~/Library/Application Support/Claude/claude_desktop_config.json 在macOS上):
{
"mcpServers": {
"smartthings": {
"command": "node",
"args": ["/absolute/path/to/smarterthings/dist/index.js"],
"env": {
"SMARTTHINGS_PAT": "your_smartthings_token_here"
}
}
}
}
与克劳德的对话示例:
You: Turn on the living room lights
Claude: I'll turn on the living room lights for you.
[Uses turn_on_device tool]
✓ Living room lights are now on.
You: What devices are in my bedroom?
Claude: Let me check your bedroom devices.
[Uses list_devices_by_room tool]
Found 3 devices in your bedroom:
- Bedroom Light (dimmable)
- Ceiling Fan
- Temperature Sensor
模式1.5:直接模式API(进程内)
对于需要直接调用MCP工具而无需协议开销的TypeScript应用程序:
import { createToolExecutor, isSuccess } from '@bobmatnyc/mcp-smarterthings/direct';
import { ServiceContainer } from '@bobmatnyc/mcp-smarterthings/services';
import { SmartThingsService } from '@bobmatnyc/mcp-smarterthings/smartthings';
// Initialize services
const smartThingsService = new SmartThingsService({
token: process.env.SMARTTHINGS_TOKEN!,
});
const container = new ServiceContainer(smartThingsService);
await container.initialize();
// Create Direct Mode executor
const executor = createToolExecutor(container);
// Type-safe API calls
const result = await executor.turnOnDevice('device-uuid' as DeviceId);
if (isSuccess(result)) {
console.log('Device turned on successfully');
}
// List devices with filters
const devices = await executor.listDevices({ capability: 'switch' });
// Create automation
const automation = await executor.createAutomation({
name: 'Motion Lights',
locationId: 'location-uuid',
template: 'motion_lights',
trigger: { deviceId: 'sensor-uuid', capability: 'motionSensor', ... },
action: { deviceId: 'light-uuid', capability: 'switch', command: 'on' },
});
// Cleanup
await container.dispose();
主要特点:
- 类型安全:完全支持TypeScript,带有品牌类型和类型推理
- 零开销:比MCP协议模式快5-10%(无JSON编组)
- 29 API方法:所有MCP工具均以打字方式提供
- 错误处理:
DirectResult<T>显式错误处理的判别联合 - 同样的逻辑:重用所有MCP处理程序(零重复、零破坏性更改)
看 直接模式API文档 完整的指南。
模式2:Alexa自定义技能
运行Alexa服务器以启用语音控制:
# Start Alexa server
pnpm alexa-server
# In another terminal, expose via ngrok
ngrok http 3000
配置Alexa开发者控制台:
- 创建新的自定义技能
- 将端点URL设置为您的ngrok URL+
/alexa - 使用提供的意图模式
- 使用Alexa应用程序或设备进行测试
语音命令示例:
"Alexa, ask SmartThings to turn on the living room lights"
"Alexa, ask SmartThings what's the temperature in the bedroom"
"Alexa, ask SmartThings to dim the kitchen lights to 30 percent"
看 Alexa快速入门指南 详细设置。
模式3:交互式聊天机器人(开发)
运行内置聊天机器人进行测试:
# Start chatbot (requires OPENROUTER_API_KEY in .env.local)
pnpm chat
配置 (.env.local):
SMARTTHINGS_PAT=your_smartthings_token_here
OPENROUTER_API_KEY=sk-or-v1-your_openrouter_key_here
示例会话:
You: Turn on the living room lights
Bot: I'll turn on the living room lights for you.
✓ Device turned on successfully.
You: What's the temperature in the bedroom?
Bot: The bedroom temperature sensor reads 72°F (22°C).
🔧 可用的MCP工具
设备控制
turn_on_device
打开SmartThings设备(需要开关功能)。
输入:
{
"deviceId": "device-uuid-here"
}
输出:
Device {deviceId} turned on successfully
turn_off_device
关闭SmartThings设备(需要开关功能)。
输入:
{
"deviceId": "device-uuid-here"
}
输出:
Device {deviceId} turned off successfully
get_device_status
获取SmartThings设备的当前状态和状态。
输入:
{
"deviceId": "device-uuid-here"
}
输出:
Device: Living Room Light
Label: Main Light
Switch State: on
Type: LIGHT
设备发现
list_devices
列出使用配置的令牌可访问的所有SmartThings设备。可选择按房间名称过滤。
输入:
{
"roomName": "Living Room" // Optional
}
输出:
Found 5 device(s):
- Living Room Light (abc-123-...)
Type: LIGHT
Room: Living Room
Capabilities: switch, switchLevel
- Kitchen Switch (def-456-...)
Type: SWITCH
Room: Kitchen
Capabilities: switch
list_devices_by_room
列出特定房间中的所有SmartThings设备。
输入:
{
"roomName": "Living Room" // Required
}
get_device_capabilities
获取特定SmartThings设备支持的功能。
输入:
{
"deviceId": "device-uuid-here"
}
输出:
Device: Living Room Light
Capabilities (3):
- switch
- switchLevel
- colorControl
list_rooms
列出所有SmartThings房间/位置及其设备数量。
输入:
{}
输出:
Found 3 room(s):
- Living Room (room-uuid-1)
Location: location-uuid
Devices: 5
- Bedroom (room-uuid-2)
Location: location-uuid
Devices: 3
场景管理
list_scenes
列出使用配置的令牌可访问的所有SmartThings场景。可选择按房间名称过滤。
输入:
{
"roomName": "Living Room" // Optional
}
输出:
Found 2 scene(s) in location for room "Living Room":
- Movie Night 🎬 (scene-uuid-1)
Last Executed: 11/24/2025, 8:30:00 PM
- Good Morning ☀️ (scene-uuid-2)
Last Executed: 11/25/2025, 7:00:00 AM
list_scenes_by_room
列出特定房间的所有SmartThings场景。
输入:
{
"roomName": "Living Room" // Required
}
execute_scene
按ID或名称执行SmartThings场景。
输入(按UUID):
{
"sceneId": "scene-uuid-here"
}
输入(按名称):
{
"sceneName": "Movie Night" // Case-insensitive
}
输出:
Scene "Movie Night" executed successfully.
Scene ID: scene-uuid-here
🧪 测试
该项目提供了全面的测试工具:
1.MCP检查员(推荐)
用于测试MCP工具的可视化GUI:
pnpm build
pnpm test:inspector
开放时间: http://localhost:6274 与:
- 测试工具的可视化界面
- JSON-RPC请求/响应查看器
- 真实设备测试
- 架构验证
2.交互式测试网关(CLI REPL)
用于测试的命令行REPL:
pnpm test-gateway
可用命令:
mcp> connect # Connect to MCP server
mcp> devices # List all devices
mcp> status <deviceId> # Get device status
mcp> on <deviceId> # Turn device on
mcp> off <deviceId> # Turn device off
mcp> help # Show commands
mcp> exit # Exit gateway
3.单元和集成测试
自动化测试套件:
# Run all tests
pnpm test
# Run unit tests only
pnpm test:unit
# Run integration tests (requires built server)
pnpm build
pnpm test:integration
# Run tests with coverage
pnpm test:coverage
4.Shell辅助函数
用于脚本编写的快速单行程序:
source tools/test-helpers.sh
# List devices
st_list_devices
# Control a device
st_turn_on "abc-123-device-id"
st_turn_off "abc-123-device-id"
# Run full test suite
mcp_test_all
看 测试快速开始 获取全面的测试指南。
📚 文档
综合文档可在 docs/ 目录:
能力系统
设置和配置
实施指南
- Alexa自定义技能 -详细的Alexa集成指南
- 聊天机器人界面 -构建聊天机器人界面
- 诊断工具 -诊断工具开发
测试与质量
研究与建筑
- 研究 -技术研究和分析文件
有关完整索引,请参阅 docs/README.md.
🎯 关键差异
是什么让更智能的东西与众不同?
-
双模式操作
- 同一代码库同时服务于MCP协议和Alexa自定义技能
- 统一的能力系统跨两种模式工作
- 无论接口如何,设备控制都是一致的
-
类型安全能力系统
- TypeScript严格模式下的编译时安全
- 品牌类型可防止域错误(混合设备ID、功能名称)
- 运行时能力检测
hasCapability() - 平台格式之间的自动值转换
-
跨平台抽象
- 用于SmartThings、Tuya和Lutron设备的单个API
- 与平台无关的能力定义
- 无缝双向值映射
- 面向未来的设计,用于添加新平台
-
生产就绪架构
- 指数回退自动重试
- Winston结构化日志记录(JSON格式)
- 全面的错误处理
- 广泛的测试覆盖范围(单元+集成)
-
开发者友好
- 丰富的文档和示例
- 交互式测试工具(REPL、Inspector、shell助手)
- 所有API的类型定义
- 明确的贡献指南
🔐 环境变量
| 变量 | 必填 | 默认 | 描述 |
|---|---|---|---|
SMARTTHINGS_PAT |
是 | - | SmartThings个人访问令牌 |
MCP_SERVER_NAME |
没有 | smartthings-mcp |
MCP服务器名称 |
MCP_SERVER_VERSION |
没有 | 1.0.0 |
MCP服务器版本 |
MCP_SERVER_PORT |
没有 | 3000 |
HTTP服务器端口(仅限HTTP模式) |
NODE_ENV |
没有 | development |
节点环境 |
LOG_LEVEL |
没有 | info |
日志记录级别(错误、警告、信息、调试) |
TRANSPORT_MODE |
没有 | stdio |
传输模式(stdio或http) |
OPENROUTER_API_KEY |
没有聊天机器人的 | - | OpenRouter API密钥(可选) |
🛠️ 发展
类型检查
pnpm typecheck
代码检查
pnpm lint
pnpm lint:fix
代码格式化
pnpm format
pnpm format:check
项目结构
Smarter Things/
├── src/
│ ├── index.ts # Main MCP server entry point
│ ├── cli/
│ │ ├── chat.ts # Interactive chatbot
│ │ └── alexa-server.ts # Alexa Custom Skill server
│ ├── mcp/
│ │ ├── server.ts # MCP server implementation
│ │ └── tools/ # MCP tool definitions
│ ├── lib/
│ │ ├── layer2/ # Unified capability system
│ │ │ ├── registry.ts # Platform registry
│ │ │ ├── converters/ # Value converters
│ │ │ └── capabilities/ # Capability definitions
│ │ ├── adapters/ # Platform adapters
│ │ │ ├── smartthings/ # SmartThings adapter
│ │ │ ├── tuya/ # Tuya adapter
│ │ │ └── lutron/ # Lutron adapter
│ │ └── smartthings-client.ts # SmartThings API client
│ └── types/
│ ├── unified-device.ts # Unified type definitions
│ └── branded.ts # Branded type utilities
├── docs/ # Documentation
├── tests/ # Test suites
│ ├── unit/ # Unit tests
│ └── integration/ # Integration tests
├── tools/ # Development tools
│ ├── mcp-test-gateway.ts # Interactive REPL
│ └── test-helpers.sh # Shell helper functions
├── package.json
├── tsconfig.json
└── README.md
🐛 故障排除
“环境验证失败:需要SMARTTHINGS_PAT”
- 确保您已创建
.env文件具有有效SMARTTHINGS_PAT - 验证令牌是否为空或已过期
“未授权”或“禁止”错误
- 检查您的PAT是否具有所需的范围:
r:devices:*和x:devices:*r:scenes:*和x:scenes:*r:locations:*
- 验证令牌是否未过期
“找不到设备”
- 确保设备UUID正确(使用
list_devices验证) - 检查该设备是否仍在您的SmartThings帐户中注册
未返回任何设备 list_devices
- 验证您的SmartThings帐户是否已配置设备
- 检查您的PAT是否可以访问正确的位置
🤝 贡献
欢迎投稿!请确保:
- 所有测试均通过(
pnpm test) - 代码格式正确(
pnpm format) - 无跳线错误(
pnpm lint) - 类型检查通过(
pnpm typecheck)
看 贡献.md 详细指南。
📄 许可证
麻省理工学院-参见 许可证 了解详情。
🙏 致谢
内置:
- @模型上下文协议/sdk -MCP协议实现
- @智能事物/核心sdk -SmartThings API客户端
- 禁食 -用于Alexa集成的HTTP服务器
- 温斯顿 -日志框架
灵感来源:
- 模型上下文协议 -MCP官方规范
- SmartThings API -SmartThings开发人员文档
📞 支持
对于问题和疑问:
- 检查 SmartThings API文档
- 回顾 MCP SDK文档
- 搜索现有 GitHub问题
- 打开一个包含详细描述和日志的新问题
由...制作❤️ 面向智能家居和人工智能社区