Smart Home ColorSpectrum Trait 結構定義

action.devices.traits.ColorSpectrum - 這個特性屬於任何可設定色譜的裝置。這適用於採用 RGB 色範圍的「全彩」燈泡。燈具可以有 ColorSpectrum 和 ColorTemperature 的組合。強調光燈和 LED 燈條可能只有 Spectrum,但有些閱讀燈泡只有「溫度」。基本燈泡或智慧型插座上的啞燈都沒有。

裝置屬性

屬性 定義
colorModel (選填) 可設為 hsv 字串,表示 HSV (色調、飽和度、值) 色彩模型的裝置偏好設定。預設值為 rgb

SYNC 要求與回應範例

{
   
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
   
"inputs": [{
     
"intent": "action.devices.SYNC"
   
}]
}
'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);
{
 
"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 字串。如果色點 (Spectrum 或 Temperature) 與合作夥伴顏色清單中的預設名稱相符,請傳回該名稱。
  • spectrumRGB 整數。以 RGB 為單位的頻譜值 (以整數表示的十六進位值)。

裝置指令

指令 參數/定義
action.devices.commands.ColorAbsolute color 物件。這是必要項目。可包含 RGB 或溫度,並視情況加上名稱。
  • name 字串。使用者指令中提供的顏色名稱 (英文)。不一定能使用 (適用於相對指令)。
  • spectrumRGB 整數。以 RGB 為單位的頻譜值 (以整數表示的十六進位值)。

執行要求與回應範例

將燈光設為紅色。
要求Node.jsJSON
{
 
"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
           
}
         
}
       
}]
     
}]
   
}
 
}]
}
'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);
{
 
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
 
"payload": {
   
"commands": [
     
{
       
"ids": [
         
"123"
       
],
       
"status": "SUCCESS",
       
"states": {
         
"color": {
           
"name": "red",
           
"spectrumRGB": 12655639
         
}
       
}
     
}
   
]
 
}
}
其他叫用範例包括:
  • 將燈光設為綠色。
  • 把檯燈的燈光切換成紅色