名称: google-home
描述: 通过 Google 智能设备管理 API,使用 curl 和 jq 控制 Google Nest 设备(恒温器、摄像头、门铃)。
元数据: {"clawdbot":{"emoji":"🏠","requires":{"bins":["curl","jq"]}}
通过智能设备管理 (SDM) API,使用 curl 和 jq 控制 Google Nest 设备。
创建 Google Cloud 项目
- 访问 https://console.cloud.google.com
- 创建一个新项目
启用 SDM API
- 进入“API 和服务” → “库”
- 搜索“Smart Device Management”
- 启用该 API
创建 OAuth 凭据
- 进入“API 和服务” → “凭据”
- 创建 OAuth 2.0 客户端 ID
- 下载 JSON 文件
- 从中提取 client_id 和 client_secret
注册您的设备
- 访问 https://nests.google.com/frame/register-user
- 接受条款
获取访问令牌
bash
# 替换为您的实际值
curl -s \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET" \
-d "refresh_token=YOUR_REFRESH_TOKEN" \
-d "grant_type=refresh_token" \
https://www.googleapis.com/oauth2/v4/token
# 列出设备
google-home-cli devices
# 获取恒温器信息
google-home-cli thermostat "客厅" --info
# 设置温度(制热/制冷/自动模式)
google-home-cli thermostat "客厅" --temp 72
# 查询摄像头状态
google-home-cli camera "前门" --status
google-home-cli thermostat <名称> — 显示当前温度/湿度--temp <度数> — 设置目标温度--mode heat|cool|auto — 设置 HVAC 模式--fan on|auto — 控制风扇google-home-cli camera <名称> — 获取流状态/设备状态--snapshot — 下载当前快照图片--stream — 启动实时流 URLgoogle-home-cli speaker <名称> — 设备信息--volume 0-100 — 设置音量--stop — 停止播放export GOOGLE_HOME_CLIENT_ID="your-client-id"
export GOOGLE_HOME_CLIENT_SECRET="your-client-secret"
export GOOGLE_HOME_ACCESS_TOKEN="your-access-token"
# 列出所有设备
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
"https://smartdevicemanagement.googleapis.com/v1/enterprises/YOUR_PROJECT_ID/devices"
# 获取设备特性
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
"https://smartdevicemanagement.googleapis.com/v1/enterprises/YOUR_PROJECT_ID/devices/YOUR_DEVICE_ID"
包含一个 nest 命令行辅助脚本,位于 scripts/nest:
# 使其全局可用
ln -sf /Users/mitchellbernstein/clawd/skills/google-home/scripts/nest /usr/local/bin/nest
# 列出设备
nest list
# 获取恒温器状态
nest status "enterprises/PROJECT_ID/devices/DEVICE_ID"
# 设置温度(摄氏度)
nest temp "enterprises/PROJECT_ID/devices/DEVICE_ID" 22
# 设置模式
nest mode "enterprises/PROJECT_ID/devices/DEVICE_ID" HEAT
创建配置文件 ~/.config/google-home/config.json:
{
"project_id": "your-google-cloud-project-id",
"access_token": "your-oauth-access-token"
}
enterprises/PROJECT_ID/devices/DEVICE_ID