名称: switchbot
描述: 通过 SwitchBot Cloud API 控制 SwitchBot 智能家居设备(窗帘、插座、灯、锁等)。当用户要求打开/关闭窗帘、开关灯/插座、查看温湿度或控制任何 SwitchBot 设备时使用。
通过 Cloud API v1.1 控制 SwitchBot 设备。
引导用户完成以下步骤:
请用户:
1. 在手机上打开 SwitchBot App
2. 进入 个人资料(右下角)
3. 点击 偏好设置(或设置)
4. 找到 关于 → 开发者选项
5. 复制 Token 和 Secret Key
mkdir -p ~/.config/switchbot
chmod 700 ~/.config/switchbot
cat > ~/.config/switchbot/credentials.json << 'EOF'
{
"token": "YOUR_TOKEN_HERE",
"secret": "YOUR_SECRET_HERE"
}
EOF
chmod 600 ~/.config/switchbot/credentials.json
运行发现脚本以查找所有设备:
python3 <skill_path>/scripts/switchbot.py list
发现设备后,在 TOOLS.md 中记录设备 ID 以便快速查阅:
## SwitchBot 设备
| 设备 | ID | 类型 |
|------|-----|------|
| 客厅窗帘 | ABC123 | Curtain3 |
| 卧室灯 | DEF456 | Plug Mini |
python3 <skill_path>/scripts/switchbot.py list
# 打开窗帘(位置 0 = 全开)
python3 <skill_path>/scripts/switchbot.py curtain <device_id> open
# 关闭窗帘(位置 100 = 全关)
python3 <skill_path>/scripts/switchbot.py curtain <device_id> close
# 设置特定位置(0-100)
python3 <skill_path>/scripts/switchbot.py curtain <device_id> 50
python3 <skill_path>/scripts/switchbot.py plug <device_id> on
python3 <skill_path>/scripts/switchbot.py plug <device_id> off
python3 <skill_path>/scripts/switchbot.py status <device_id>
python3 <skill_path>/scripts/switchbot.py command <device_id> <command> [parameter]
| 设备类型 | 命令 |
|---|---|
| Curtain / Curtain3 | open, close, setPosition |
| Plug Mini / Plug | turnOn, turnOff, toggle |
| Bot | press, turnOn, turnOff |
| Light / Strip Light | turnOn, turnOff, setBrightness, setColor |
| Lock | lock, unlock |
| Humidifier | turnOn, turnOff, setMode |
| Meter / MeterPlus | (只读:温度、湿度) |
| Hub / Hub Mini / Hub 2 | (仅作为网关) |
| 状态码 | 含义 |
|---|---|
| 100 | 成功 |
| 151 | 设备离线 |
| 152 | 命令不支持 |
| 160 | 未知命令 |
| 161 | 参数无效 |
| 190 | 内部错误 |
status 命令