欢迎使用 Google Home 开发者中心,这是一个学习如何开发智能家居 Action 的新平台。注意:构建 Action 的工作仍需在 Actions 控制台中完成。
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
智能家居 ColorTemperature 特征架构
action.devices.traits.ColorTemperature
- 此特征属于任何能够设置色温的设备。
这适用于以开尔文为单位的“温”灯泡。这通常与
ColorSpectrum 是不同的模态,并且 Spectrum 可能存在通过温度提供的白点。根据可用的特征,Google 可能会根据请求和灯具类型选择合适的模式(例如,“将客厅的灯设为白色”可能会向某些灯泡发送温度命令,向 LED 灯条发送光谱命令)。
设备属性
属性 |
定义 |
temperatureMinK |
可选。如果设置了 temperatureMaxK ,则必须提供此属性。光线支持的最低色温(以开尔文为单位)。 |
temperatureMaxK |
可选。如果设置了 temperatureMinK ,则必须提供此属性。光线支持的最高色温(以开尔文为单位)。 |
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.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);
{
"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 字符串。如果色点(光谱或温度)与合作伙伴颜色列表中的预设名称匹配,则返回该名称。
temperature 整数。色温(以开尔文为单位)。
|
示例 QUERY 请求和响应
我当前的灯光色温是多少?
{
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
"inputs": [{
"intent": 'action.devices.QUERY',
"payload": {
"devices": [{
"id": "123",
"customData": {
"fooValue": 74,
"barValue": true,
"bazValue": "foo"
}
}]
}
}]
}
'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);
{
"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 或 Temperature,以及名称(可选)。
name 字符串。用户命令中提供的颜色名称(英文)。并非始终可用(对于相对命令)。
temperature 整数。色温(以开尔文为单位)。
|
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": "soft white",
"temperature": 2700
}
}
}]
}]
}
}]
}
'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);
{
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
"payload": {
"commands": [
{
"ids": [
"123"
],
"status": "SUCCESS",
"states": {
"color": {
"name": "soft white",
"temperature": 2700
}
}
}
]
}
}
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2023-09-21。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["Incorrect information","incorrectInformation","thumb-down"],["Not enough information/samples","notEnoughInformationSamples","thumb-down"],["Too complicated","tooComplicated","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2023-09-21。"],[],[]]