Nest SDM Skill
Control and monitor Google Nest devices via the Smart Device Management REST API.
Setup
Prerequisites
- 1. Device Access Console — Register at https://console.nest.google.com/device-access ($5 one-time fee)
- GCP Project — Create at https://console.cloud.google.com with SDM API enabled
- OAuth Client — Web application type with
https://www.google.com as redirect URI - SDM scope — Add
https://www.googleapis.com/auth/sdm.service to OAuth consent screen
First-time Authorization
- 1. Build the authorization URL:
CODEBLOCK0
- 2. Open in browser, sign in as the device owner Google account
- Enable ALL device permissions, click Next, then Continue through consent
- Copy the
code= parameter from the redirect URL - Exchange for tokens:
CODEBLOCK1
- 6. Save tokens to the config file (see Configuration below)
Configuration
Create ~/.openclaw/workspace/.nest-sdm-tokens.json:
{
"client_id": "<your-client-id>",
"client_secret": "<your-client-secret>",
"project_id": "<device-access-project-id>",
"refresh_token": "<your-refresh-token>",
"token_type": "Bearer",
"scope": "https://www.googleapis.com/auth/sdm.service"
}
Secure it: INLINECODE4
CLI Usage
CODEBLOCK3
Device Discovery
CODEBLOCK4
Thermostat
CODEBLOCK5
Doorbell & Cameras
CODEBLOCK6
Raw API
CODEBLOCK7
Supported Devices
| Type | Traits | Control |
|---|
| THERMOSTAT | Temperature, Humidity, Mode, Eco, Fan, HVAC, Setpoint, Connectivity | Full read/write |
| DOORBELL |
LiveStream, CameraImage, Person, Motion, Chime, EventImage, ClipPreview | Read + stream |
| DISPLAY | LiveStream, CameraImage, Person, Sound, Motion, EventImage | Read + stream |
SDM API Commands Reference
Thermostat Commands
| Command | Params |
|---|
| INLINECODE5 | INLINECODE6 |
| INLINECODE7 |
{"heatCelsius": <float>} |
|
ThermostatTemperatureSetpoint.SetCool |
{"coolCelsius": <float>} |
|
ThermostatTemperatureSetpoint.SetRange |
{"heatCelsius": <float>, "coolCelsius": <float>} |
|
ThermostatEco.SetMode |
{"mode": "MANUAL_ECO\|OFF"} |
|
Fan.SetTimer |
{"timerMode": "ON", "duration": "<seconds>s"} |
Camera Commands
| Command | Params |
|---|
| INLINECODE17 | INLINECODE18 |
| INLINECODE19 |
{"mediaSessionId": "<id>"} |
|
CameraLiveStream.ExtendWebRtcStream |
{"mediaSessionId": "<id>"} |
|
CameraEventImage.GenerateImage |
{"eventId": "<event-id>"} |
Pub/Sub Real-Time Events
Get instant alerts for doorbell presses, motion, person detection, and device state changes.
CLI: nest-events
CODEBLOCK8
Setup Steps
- 1. OAuth with Pub/Sub scope — Run OAuth flow as your-email@example.com with
pubsub + cloud-platform scopes. Save tokens to .nest-pubsub-tokens.json. - Create topic —
nest-events create-topic (creates projects/YOUR_GCP_PROJECT/topics/nest-sdm-events) - Grant permissions —
nest-events grant-permissions (adds sdm-publisher@googlegroups.com) - Create subscription — INLINECODE33
- Enable in Device Access Console — https://console.nest.google.com/device-access → Enable Pub/Sub → Enter topic ID
- Trigger initial events —
nest devices (one-time API call) - Start listener — INLINECODE35
Event Types Supported
| Event | Alert |
|---|
| INLINECODE36 | 🔔 DOORBELL — Someone rang! |
| INLINECODE37 |
👤 Person detected at device |
|
CameraMotion.Motion | 🏃 Motion at device |
|
CameraSound.Sound | 🔊 Sound at device |
|
ThermostatHvac status change | ❄️/🔥 HVAC now COOLING/HEATING |
|
ThermostatTemperatureSetpoint | 🌡️ Setpoint changed |
|
Temperature trait | 🌡️ Ambient temperature change |
Configuration
Environment Variables:
| Variable | Description | Default |
|---|
| INLINECODE43 | Path to Pub/Sub OAuth tokens | INLINECODE44 |
| INLINECODE45 |
Bot token for alerts | from
~/.zshenv |
|
TELEGRAM_CHAT_ID | User/chat ID for alerts | from
~/.zshenv |
|
POLL_INTERVAL | Seconds between polls | 10 |
|
GCP_PROJECT | GCP project ID |
YOUR_GCP_PROJECT |
|
PUBSUB_TOPIC | Topic name |
nest-sdm-events |
|
PUBSUB_SUBSCRIPTION | Subscription name |
nest-sdm-events-sub |
Event Logs
Raw events are logged to data/nest-events/events-YYYY-MM-DD.jsonl.
Alert Dedup
Same event type won't re-alert within 60 seconds to prevent alert fatigue.
Important Notes
- - Token expiry: If the GCP app is in "testing" mode, refresh tokens expire in 7 days. Publish the app to avoid re-auth.
- Temperature: API uses Celsius internally. The CLI handles F↔C conversion.
- Setpoint constraints: HEATCOOL range must have at least 1.5°C (2.7°F) gap between heat and cool setpoints.
- Camera streams: WebRTC only (no RTSP). Requires SDP offer/answer exchange.
- Rate limits: 10 queries/min per device, 10 commands/min per device.
- Events: Use
nest-events listen for real-time alerts. Requires Pub/Sub setup (see above).
Nest SDM 技能
通过智能设备管理REST API控制和监控Google Nest设备。
设置
前提条件
- 1. 设备访问控制台 — 在 https://console.nest.google.com/device-access 注册(一次性费用5美元)
- GCP项目 — 在 https://console.cloud.google.com 创建并启用SDM API
- OAuth客户端 — Web应用类型,重定向URI设置为 https://www.google.com
- SDM范围 — 在OAuth同意屏幕中添加 https://www.googleapis.com/auth/sdm.service
首次授权
- 1. 构建授权URL:
https://nestservices.google.com/partnerconnections/ID>/auth?redirecturi=https://www.google.com&accesstype=offline&prompt=consent&clientid=ID>&responsetype=code&scope=https://www.googleapis.com/auth/sdm.service
- 2. 在浏览器中打开,使用设备所有者的Google账号登录
- 启用所有设备权限,点击下一步,然后继续同意
- 从重定向URL中复制 code= 参数
- 交换令牌:
bash
curl -s -X POST https://oauth2.googleapis.com/token \
-d client
id=ID> \
-d clientsecret=SECRET> \
-d code= \
-d granttype=authorizationcode \
-d redirect_uri=https://www.google.com
- 6. 将令牌保存到配置文件中(参见下面的配置)
配置
创建 ~/.openclaw/workspace/.nest-sdm-tokens.json:
json
{
client_id: <您的客户端ID>,
client_secret: <您的客户端密钥>,
project_id: <设备访问项目ID>,
refresh_token: <您的刷新令牌>,
token_type: Bearer,
scope: https://www.googleapis.com/auth/sdm.service
}
设置安全权限:chmod 600 ~/.openclaw/workspace/.nest-sdm-tokens.json
CLI使用
bash
便捷别名
alias nest=<技能目录>/nest-sdm.sh
设备发现
bash
nest devices # 列出所有设备(JSON格式)
nest structures # 列出结构/房间
恒温器
bash
nest thermostat # 当前状态(温度、湿度、模式、设定点)
nest set-cool <华氏度> # 设置为制冷模式并设定温度
nest set-heat <华氏度> # 设置为制热模式并设定温度
nest set-range <低温°F> <高温°F> # 设置制热制冷范围
nest set-mode <模式> # HEAT | COOL | HEATCOOL | OFF
nest set-eco <模式> # MANUAL_ECO | OFF
nest fan-on [持续时间秒] # 开启风扇(默认:900秒/15分钟)
nest fan-off # 关闭风扇
门铃与摄像头
bash
nest doorbell # 门铃信息与功能
nest display # 厨房显示屏信息
nest camera-stream <设备ID> # 生成WebRTC实时流(返回SDP应答)
nest camera-image <事件ID> # 获取事件快照URL
原始API
bash
nest api GET devices # 原始设备列表
nest api GET devices/<设备ID> # 单个设备
nest api POST devices/<设备ID>:executeCommand {command:...,params:{...}}
支持的设备
| 类型 | 特征 | 控制 |
|---|
| 恒温器 | 温度、湿度、模式、节能、风扇、暖通空调、设定点、连接状态 | 完全读写 |
| 门铃 |
实时流、摄像头图像、人员、移动、铃声、事件图像、剪辑预览 | 读取+流 |
| 显示屏 | 实时流、摄像头图像、人员、声音、移动、事件图像 | 读取+流 |
SDM API命令参考
恒温器命令
| 命令 | 参数 |
|---|
| ThermostatMode.SetMode | {mode: HEAT\ | COOL\ | HEATCOOL\ | OFF} |
| ThermostatTemperatureSetpoint.SetHeat |
{heatCelsius: <浮点数>} |
| ThermostatTemperatureSetpoint.SetCool | {coolCelsius: <浮点数>} |
| ThermostatTemperatureSetpoint.SetRange | {heatCelsius: <浮点数>, coolCelsius: <浮点数>} |
| ThermostatEco.SetMode | {mode: MANUAL_ECO\|OFF} |
| Fan.SetTimer | {timerMode: ON, duration: <秒数>s} |
摄像头命令
| 命令 | 参数 |
|---|
| CameraLiveStream.GenerateWebRtcStream | {offerSdp: <SDP提议>} |
| CameraLiveStream.StopWebRtcStream |
{mediaSessionId: } |
| CameraLiveStream.ExtendWebRtcStream | {mediaSessionId: } |
| CameraEventImage.GenerateImage | {eventId: <事件ID>} |
Pub/Sub实时事件
获取门铃按铃、移动、人员检测和设备状态变化的即时提醒。
CLI:nest-events
bash
nest-events setup-check # 验证Pub/Sub配置是否就绪
nest-events create-topic # 创建GCP Pub/Sub主题
nest-events grant-permissions # 授予SDM发布者角色
nest-events create-subscription # 创建拉取订阅
nest-events poll # 拉取一次事件
nest-events listen # 持续轮询(守护进程)
设置步骤
- 1. 带Pub/Sub范围的OAuth — 以your-email@example.com运行OAuth流程,包含pubsub + cloud-platform范围。将令牌保存到.nest-pubsub-tokens.json。
- 创建主题 — nest-events create-topic(创建projects/YOURGCPPROJECT/topics/nest-sdm-events)
- 授予权限 — nest-events grant-permissions(添加sdm-publisher@googlegroups.com)
- 创建订阅 — nest-events create-subscription
- 在设备访问控制台中启用 — https://console.nest.google.com/device-access → 启用Pub/Sub → 输入主题ID
- 触发初始事件 — nest devices(一次性API调用)
- 启动监听器 — nest-events listen
支持的事件类型
| 事件 | 提醒 |
|---|
| DoorbellChime.Chime | 🔔 门铃 — 有人按铃! |
| CameraPerson.Person |
👤 在设备检测到人员 |
| CameraMotion.Motion | 🏃 设备检测到移动 |
| CameraSound.Sound | 🔊 设备检测到声音 |
| ThermostatHvac 状态变化 | ❄️/🔥 暖通空调现在制冷/制热 |
| ThermostatTemperatureSetpoint | 🌡️ 设定点已更改 |
| Temperature 特征 | 🌡️ 环境温度变化 |
配置
环境变量:
| 变量 | 描述 | 默认值 |
|---|
| NESTPUBSUBTOKENS | Pub/Sub OAuth令牌路径 | ~/.openclaw/workspace/.nest-pubsub-tokens.json |
| TELEGRAMBOTTOKEN |
提醒的机器人令牌 | 来自 ~/.zshenv |
| TELEGRAMCHATID | 提醒的用户/聊天ID | 来自 ~/.zshenv |
| POLL_INTERVAL | 轮询间隔秒数 | 10 |
| GCPPROJECT | GCP项目ID | YOURGCP_PROJECT |
| PUBSUB_TOPIC | 主题名称 | nest-sdm-events |
| PUBSUB_SUBSCRIPTION | 订阅名称 | nest-sdm-events-sub |
事件日志
原始事件记录到 data/nest-events/events-YYYY-MM-DD.jsonl。
提醒去重
相同事件类型在60秒内不会重复提醒,以防止提醒疲劳。
重要说明
- - 令牌过期: 如果GCP应用处于测试模式,刷新令牌将在7天后过期。发布应用以避免重新认证。
- 温度: API内部使用摄氏度。CLI处理华氏度↔摄氏度转换。
-