欢迎使用 Google Home 开发者中心,您可以在这里学习有关如何开发智能家居 Action 的新平台。注意:你将继续在 Actions 控制台中构建操作。
使用集合让一切井井有条 根据您的偏好保存内容并对其进行分类。

智能家居 ColorSpectrum Trait 架构

action.devices.traits.ColorSpectrum - 此特征属于能够设置色谱的任何设备。这适用于采用 RGB 颜色范围的“完整”颜色灯泡。光源可能采用 ColorSpectrum 和 ColorTemperature 的任意组合。强调色灯和 LED 灯条可能只有“频谱” 而有些阅读灯只有“温度”基本灯泡或智能插头上的哑光灯也没有。

设备属性

属性 定义
colorModel (可选)可以设置为字符串 hsv 来指示设备对 HSV(色调、饱和度、值)颜色模型偏好。默认值为 rgb

SYNC 请求和响应示例

请求
{
    "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
    "inputs": [{
      "intent": "action.devices.SYNC"
    }]
}
Node.js
'use strict';

const {smarthome} = require('actions-on-google');
const functions = require('firebase-functions');

const app = smarthome();

app.onSync((body, headers) => {
  return {
    requestId: body.requestId,
    payload: {
      agentUserId: '1836.15267389',
      devices: [{
        id: '123',
        type: 'action.devices.types.LIGHT',
        traits: [
          'action.devices.traits.ColorSpectrum'
        ],
        name: {
          defaultNames: ['AAA bulb A19 color hyperglow'],
          name: 'lamp1',
          nicknames: ['reading lamp']
        },
        willReportState: true,
        attributes: {
          colorModel: 'rgb'
        },
        deviceInfo: {
          manufacturer: 'AAA',
          model: 'hg11',
          hwVersion: '1.2',
          swVersion: '5.4'
        },
        customData: {
          fooValue: 12,
          barValue: false,
          bazValue: 'dancing alpaca'
        }
      }]
    }
  };
});

// ...

exports.smarthome = functions.https.onRequest(app);
JSON
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "payload": {
    "agentUserId": "1836.15267389",
    "devices": [
      {
        "id": "123",
        "type": "action.devices.types.LIGHT",
        "traits": [
          "action.devices.traits.ColorSpectrum"
        ],
        "name": {
          "defaultNames": [
            "AAA bulb A19 color hyperglow"
          ],
          "name": "lamp1",
          "nicknames": [
            "reading lamp"
          ]
        },
        "willReportState": true,
        "attributes": {
          "colorModel": "rgb"
        },
        "deviceInfo": {
          "manufacturer": "AAA",
          "model": "hg11",
          "hwVersion": "1.2",
          "swVersion": "5.4"
        },
        "customData": {
          "fooValue": 12,
          "barValue": false,
          "bazValue": "dancing alpaca"
        }
      }
    ]
  }
}
验证器

设备状态

状态 定义
color 对象。当前颜色设置。由于给定光源处于光谱或温度模式下,因此该对象包含相关模式下的当前颜色设置。
  • name 字符串。如果颜色点(光谱或温度)与合作伙伴颜色列表中的预设名称匹配,则返回该名称。
  • spectrumRGB 整数。RGB 格式的频谱值(十六进制值,以整数表示)。

设备命令

命令 参数/定义
action.devices.commands.ColorAbsolute color 对象。必填。将包括 RGB 或 Temperature 和名称(可选)。
  • name 字符串。用户命令中提供的颜色名称(英语)。并非始终可用(适用于相对命令)。
  • spectrumRGB 整数。RGB 格式的频谱值(十六进制值,以整数表示)。

示例 EXECUTE 请求和响应

把我的灯设为红色。
请求
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "inputs": [{
    "intent": "action.devices.EXECUTE",
    "payload": {
      "commands": [{
        "devices": [{
          "id": "123",
          "customData": {
            "fooValue": 74,
            "barValue": true,
            "bazValue": "sheepdip"
          }
        }],
        "execution": [{
          "command": "action.devices.commands.ColorAbsolute",
          "params": {
            "color": {
            "name": "red",
            "spectrumRGB": 16711680
            }
          }
        }]
      }]
    }
  }]
}
Node.js
'use strict';

const {smarthome} = require('actions-on-google');
const functions = require('firebase-functions');

const app = smarthome();

app.onExecute((body, headers) => {
  return {
    requestId: body.requestId,
    payload: {
      commands: [{
        ids: ['123'],
        status: 'SUCCESS',
        states: {
          color: {
            name: 'red',
            spectrumRGB: 12655639
          }
        }
      }]
    }
  };
});

// ...

exports.smarthome = functions.https.onRequest(app);
JSON
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "payload": {
    "commands": [
      {
        "ids": [
          "123"
        ],
        "status": "SUCCESS",
        "states": {
          "color": {
            "name": "red",
            "spectrumRGB": 12655639
          }
        }
      }
    ]
  }
}
其他示例调用包括:
  • 把我的灯设为绿色。
  • 把台灯的灯光调成红色