Smart Device Management API

SDM API 是一种 REST API,提供各种方法来 查看 trait 并执行 trait 命令,以便管理 Google Nest 设备。使用 授权流程。

特征

SDM API 使用基于特征的模型来获取设备信息 和功能。请查看各个设备指南,了解有哪些特征 :

方法

请参阅 API 参考,了解关于 适用于 SDM API 的所有方法。

executeCommand

对授权设备执行命令。

使用 POST 调用来执行命令。例如,调节温控器 模式:

POST /enterprises/project-id/devices/device-id:executeCommand
{
  "command" : "sdm.devices.commands.ThermostatMode.SetMode",
  "params" : {
    "mode" : "HEAT"
  }
}

您可以在各个特征参考中找到更多命令示例 页面。请参阅完整的特征列表

get

获取已获授权的结构或设备的相关信息。

GET 调用会返回单个响应,其中包含所有字段的当前字段和值 某个结构或设备 user 具有的 和“parentRelations”对象,用于表示父资源 当前资源(建筑物或房间)

例如,Nest Thermostat 可能会返回 以下:

GET /enterprises/project-id/devices/device-id
{
  "name" : "enterprises/project-id/devices/device-id",
  "type" : "sdm.devices.types.THERMOSTAT",
  "assignee" : "enterprises/project-id/structures/structure-id/rooms/room-id",
  "traits" : {
    "sdm.devices.traits.Connectivity" : {
      "status" : "ONLINE"
    },
    "sdm.devices.traits.Fan" : {
      "timerMode" : "ON",
      "timerTimeout" : "2019-05-10T03:22:54Z"
    },
    "sdm.devices.traits.Humidity" : {
      "ambientHumidityPercent" : 35.0
    },
    "sdm.devices.traits.Info" : {
      "customName" : "My device"
    },
    "sdm.devices.traits.Settings" : {
      "temperatureScale" : "CELSIUS"
    },
    "sdm.devices.traits.Temperature" : {
      "ambientTemperatureCelsius" : 23.0
    },
    "sdm.devices.traits.ThermostatEco" : {
      "availableModes" : ["MANUAL_ECO", "OFF"],
      "mode" : "MANUAL_ECO",
      "heatCelsius" : 20.0,
      "coolCelsius" : 22.0
    },
    "sdm.devices.traits.ThermostatHvac" : {
      "status" : "HEATING"
    },
    "sdm.devices.traits.ThermostatMode" : {
      "availableModes" : ["HEAT", "COOL", "HEATCOOL", "OFF"],
      "mode" : "COOL"
    },
    "sdm.devices.traits.ThermostatTemperatureSetpoint" : {
      "heatCelsius" : 20.0,
      "coolCelsius" : 22.0
    }
  },
  "parentRelations" : [
    {
      "parent" : "enterprises/project-id/structures/structure-id/rooms/room-id",
      "displayName" : "Lobby"
    }
  ]
}

list

列出已获授权的结构、房间或设备。

列出在单次授权下授权的所有建筑物、房间或设备 请对相应的资源端点进行 GET 调用:

GET /enterprises/project-id/structures
GET /enterprises/project-id/structures/structure-id/rooms
GET /enterprises/project-id/devices

Google 助理集成

设备获得使用 SDM 的授权后,Google 会在主屏幕中得知该设备 绘制和管理其状态。如果您集成了 Google 助理 作为商业产品/服务的一部分:

错误

请参阅 API 错误代码参考,了解 API 错误代码的完整列表。