名称: nest-devices
描述: 通过设备访问 API 控制 Nest 智能家居设备(恒温器、摄像头、门铃)。当用户要求检查或调节家庭温度、查看摄像头画面、确认门口访客、监控房间或设置温度计划时使用。
元数据:
clawdbot:
emoji: "🏠"
通过 Google 智能设备管理 API 控制 Nest 设备。
https://www.google.com 作为已授权的重定向 URI。运行 OAuth 流程以获取刷新令牌:
# 1. 在浏览器中打开此 URL(替换 CLIENT_ID 和 PROJECT_ID):
https://nestservices.google.com/partnerconnections/PROJECT_ID/auth?redirect_uri=https://www.google.com&access_type=offline&prompt=consent&client_id=CLIENT_ID&response_type=code&scope=https://www.googleapis.com/auth/sdm.service
# 2. 授权后,从重定向 URL 复制 'code' 参数
# 3. 将授权码交换为令牌:
curl -X POST https://oauth2.googleapis.com/token \
-d "client_id=CLIENT_ID" \
-d "client_secret=CLIENT_SECRET" \
-d "code=AUTH_CODE" \
-d "grant_type=authorization_code" \
-d "redirect_uri=https://www.google.com"
存储在 1Password 或环境变量中:
1Password(推荐):
创建一个包含以下字段的项目:project_id, client_id, client_secret, refresh_token
环境变量:
export NEST_PROJECT_ID="your-project-id"
export NEST_CLIENT_ID="your-client-id"
export NEST_CLIENT_SECRET="your-client-secret"
export NEST_REFRESH_TOKEN="your-refresh-token"
python3 scripts/nest.py list
# 获取状态
python3 scripts/nest.py get <device_id>
# 设置温度(摄氏度)
python3 scripts/nest.py set-temp <device_id> 21 --unit c --type heat
# 设置温度(华氏度)
python3 scripts/nest.py set-temp <device_id> 70 --unit f --type heat
# 更改模式 (HEAT, COOL, HEATCOOL, OFF)
python3 scripts/nest.py set-mode <device_id> HEAT
# 节能模式
python3 scripts/nest.py set-eco <device_id> MANUAL_ECO
# 生成实时流 URL (RTSP,有效期约 5 分钟)
python3 scripts/nest.py stream <device_id>
from nest import NestClient
client = NestClient()
# 列出设备
devices = client.list_devices()
# 恒温器控制
client.set_heat_temperature(device_id, 21.0) # 摄氏度
client.set_thermostat_mode(device_id, 'HEAT')
client.set_eco_mode(device_id, 'MANUAL_ECO')
# 摄像头流
result = client.generate_stream(device_id)
rtsp_url = result['results']['streamUrls']['rtspUrl']
脚本按以下顺序检查凭据:
NEST_OP_VAULT 和 NEST_OP_ITEM(或使用默认值:保险库 "Alfred",项目 "Nest Device Access API")。NEST_PROJECT_ID, NEST_CLIENT_ID, NEST_CLIENT_SECRET, NEST_REFRESH_TOKEN。| 设置 | 摄氏度 | 华氏度 |
|---|---|---|
| 节能(离家) | 15-17°C | 59-63°F |
| 舒适 | 19-21°C | 66-70°F |
| 温暖 | 22-23°C | 72-73°F |
| 夜间 | 17-18°C | 63-65°F |
要在有人按门铃或检测到移动时获得即时警报,您需要设置带有 Webhook 的 Google Cloud Pub/Sub。
gcloud)添加到您的 clawdbot.json:
{
"hooks": {
"enabled": true,
"token": "your-secret-token-here"
}
}
生成令牌:openssl rand -hex 24
gcloud config set project YOUR_GCP_PROJECT_ID
# 创建主题
gcloud pubsub topics create nest-events
# 授予 SDM 发布权限(服务账户和发布者组都需要)
gcloud pubsub topics add-iam-policy-binding nest-events \
--member="serviceAccount:sdm-prod@sdm-prod.iam.gserviceaccount.com" \
--role="roles/pubsub.publisher"
gcloud pubsub topics add-iam-policy-binding nest-events \
--member="group:sdm-publisher@googlegroups.com" \
--role="roles/pubsub.publisher"
访问 console.nest.google.com/device-access → 您的项目 → 编辑 → 将 Pub/Sub 主题设置为:
projects/YOUR_GCP_PROJECT_ID/topics/nest-events
# 安装 cloudflared
curl -L -o ~/.local/bin/cloudflared https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64
chmod +x ~/.local/bin/cloudflared
# 身份验证(会打开浏览器)
~/.local/bin/cloudflared tunnel login
# 创建命名隧道
~/.local/bin/cloudflared tunnel create nest-webhook
# 记下输出中的隧道 ID (UUID)
创建 ~/.cloudflared/config.yml:
tunnel: nest-webhook
credentials-file: /home/YOUR_USER/.cloudflared/TUNNEL_ID.json
ingress:
- hostname: nest.yourdomain.com
service: http://localhost:8420
- service: http_status:404
创建 DNS 路由:
~/.local/bin/cloudflared tunnel route dns nest-webhook nest.yourdomain.com
Webhook 服务器 (/etc/systemd/system/nest-webhook.service):
[Unit]
Description=Nest Pub/Sub Webhook Server
After=network.target
[Service]
Type=simple
User=YOUR_USER
Environment=CLAWDBOT_GATEWAY_URL=http://localhost:18789
Environment=CLAWDBOT_HOOKS_TOKEN=your-hooks-token-here
ExecStart=/usr/bin/python3 /path/to/skills/nest-devices/scripts/nest-webhook.py
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
Cloudflare 隧道 (/etc/systemd/system/cloudflared-nest.service):
[Unit]
Description=Cloudflare Tunnel for Nest Webhook
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=YOUR_USER
ExecStart=/home/YOUR_USER/.local/bin/cloudflared tunnel run nest-webhook
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
启用并启动:
sudo systemctl daemon-reload
sudo systemctl enable --now nest-webhook cloudflared-nest
gcloud pubsub subscriptions create nest-events-sub \
--topic=nest-events \
--push-endpoint="https://nest.yourdomain.com/nest/events" \
--ack-deadline=30
# 测试 webhook 端点
curl https://nest.yourdomain.com/health
# 模拟门铃事件
curl -X POST http://localhost:8420/nest/events \
-H "Content-Type: application/json" \
-d '{"message":{"data":"eyJyZXNvdXJjZVVwZGF0ZSI6eyJuYW1lIjoiZW50ZXJwcmlzZXMvdGVzdC9kZXZpY2VzL0RPT1JCRUxMLTAxIiwiZXZlbnRzIjp7InNkbS5kZXZpY2VzLmV2ZW50cy5Eb29yYmVsbENoaW1lLkNoaW1lIjp7ImV2ZW50SWQiOiJ0ZXN0In19fX0="}}'
| 事件 | 行为 |
|---|---|
DoorbellChime.Chime |
🔔 发送警报 — 将照片发送到 Telegram |
CameraPerson.Person |
🚶 发送警报 — 将照片发送到 Telegram |
CameraMotion.Motion |
📹 仅记录(无警报) |
CameraSound.Sound |
🔊 仅记录(无警报) |
CameraClipPreview.ClipPreview |
🎬 仅记录(无警报) |
陈旧事件过滤: 超过 5 分钟的事件会被记录但永远不会触发警报。这可以防止延迟送达的 Pub/Sub 消息导致通知泛滥。
当门铃或人员事件触发警报时:
GenerateImage API — 快速、事件特定的快照。ffmpeg 从 RTSP 直播流捕获帧(需要安装 ffmpeg)。| 变量 | 必需 | 描述 |
|---|---|---|
CLAWDBOT_GATEWAY_URL |
否 | 网关 URL(默认:http://localhost:18789) |
CLAWDBOT_HOOKS_TOKEN |
是 | 用于感知通知的网关 hooks 令牌 |
OP_SVC_ACCT_TOKEN |
是 | 用于获取 Nest API 凭据的 1Password 服务账户令牌 |
TELEGRAM_BOT_TOKEN |
是 | 用于发送警报的 Telegram 机器人令牌 |
TELEGRAM_CHAT_ID |
是 | 接收警报的 Telegram 聊天 ID |
PORT |
否 | Webhook 服务器端口(默认:8420) |
projects/YOUR_GCP_PROJECT_ID/topics/nest-events