智慧型住宅色溫特徵結構定義

action.devices.traits.ColorTemperature - 這個特性屬於任何可設定色溫的裝置。

這適用於在克爾文取色點的「暖色」燈泡。這通常是與 ColorSpectrum 的獨立形態,而且可能有 Spectrum 無法觸及的白點可用的白點。Google 可能會根據可用特徵,根據要求和光源選擇適當的模式。舉例來說,「將客廳的燈切換為白色」可能會向部分燈泡傳送「溫度」指令,並將 Spectrum 指令傳送至 LED 燈條。

裝置屬性

屬性 定義
temperatureMinK (選填) 如果已設定 temperatureMaxK,則為必要欄位。指示燈支援的最低色溫,以克耳文表示。
temperatureMaxK (選填) 如果已設定 temperatureMinK,則為必要欄位。指示燈支援的最高色溫,以克耳文為單位。

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.ColorTemperature'
        ],
        name: {
          defaultNames: ['AAA bulb A19 color hyperglow'],
          name: 'lamp1',
          nicknames: ['reading lamp']
        },
        willReportState: true,
        attributes: {
          temperatureMinK: 2000,
          temperatureMaxK: 6500
        },
        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.ColorTemperature"
        ],
        "name": {
          "defaultNames": [
            "AAA bulb A19 color hyperglow"
          ],
          "name": "lamp1",
          "nicknames": [
            "reading lamp"
          ]
        },
        "willReportState": true,
        "attributes": {
          "temperatureMinK": 2000,
          "temperatureMaxK": 6500
        },
        "deviceInfo": {
          "manufacturer": "AAA",
          "model": "hg11",
          "hwVersion": "1.2",
          "swVersion": "5.4"
        },
        "customData": {
          "fooValue": 12,
          "barValue": false,
          "bazValue": "dancing alpaca"
        }
      }
    ]
  }
}
驗證工具

裝置狀態

狀態 定義
color 物件。目前的色彩設定。由於指定燈具處於光譜或溫度模式,因此這個物件會在相關模式下包含目前的色彩設定。
  • name 字串。如果色點 (Spectrum 或 Temperature) 與合作夥伴顏色清單中的預設名稱相符,請傳回該名稱。
  • temperature 整數。色溫 (克耳文)。

QUERY 要求與回應範例

我目前的燈光色溫是多少?
要求
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "inputs": [{
    "intent": 'action.devices.QUERY',
    "payload": {
      "devices": [{
        "id": "123",
        "customData": {
          "fooValue": 74,
          "barValue": true,
          "bazValue": "foo"
        }
      }]
    }
  }]
}
Node.js
'use strict';

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

const app = smarthome();

app.onQuery((body, headers) => {
  return {
    requestId: body.requestId,
    payload: {
      devices: {
        123: {
          online: true,
          color: {
            name: 'warm white',
            temperature: 25000
          },
          status: 'SUCCESS'
        }
      }
    }
  };
});

// ...

exports.smarthome = functions.https.onRequest(app);
JSON
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "payload": {
    "devices": {
      "123": {
        "online": true,
        "color": {
          "name": "warm white",
          "temperature": 25000
        },
        "status": "SUCCESS"
      }
    }
  }
}

裝置指令

指令 參數/定義
action.devices.commands.ColorAbsolute color 物件。這是必要項目。可包含 RGB 或溫度,並視情況加上名稱。
  • name 字串。使用者指令中提供的顏色名稱 (英文)。不一定能使用 (適用於相對指令)。
  • temperature 整數。色溫 (克耳文)。

執行要求與回應範例

將燈光調整為柔和的白色。
要求
{
  "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": "soft white",
                "temperature": 2700
              }
          }
        }]
      }]
    }
  }]
}
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: 'soft white',
            temperature: 2700
          }
        }
      }]
    }
  };
});

// ...

exports.smarthome = functions.https.onRequest(app);
JSON
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "payload": {
    "commands": [
      {
        "ids": [
          "123"
        ],
        "status": "SUCCESS",
        "states": {
          "color": {
            "name": "soft white",
            "temperature": 2700
          }
        }
      }
    ]
  }
}