Wenn Nutzer mit Google Assistant to query the current
state of a device, your fulfillment receives an
action.devices.QUERY
intent containing a
list of device IDs (as provided by your SYNC
response).
Your fulfillment receives an
action.devices.EXECUTE
intent
when users send commands to Assistant to control your
device. interagieren
QUERY
-Intents verarbeiten
Ihre QUERY
-Antwort enthält eine vollständige Reihe von Zuständen für jede Eigenschaft, die von den angeforderten Geräten unterstützt wird.
{ "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf", "inputs": [{ "intent": "action.devices.QUERY", "payload": { "devices": [{ "id": "123", "customData": { "fooValue": 74, "barValue": true, "bazValue": "foo" } }, { "id": "456", "customData": { "fooValue": 12, "barValue": false, "bazValue": "bar" } }] } }] }
JSON
{ "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf", "payload": { "devices": { "123": { "on": true, "online": true }, "456": { "on": true, "online": true, "brightness": 80, "color": { "name": "cerulean", "spectrumRGB": 31655 } } } } }
Node.js
const {smarthome} = require('actions-on-google'); const app = smarthome(); // ... app.onQuery((body, headers) => { // TODO Get device state return { requestId: body.requestId, payload: { devices: { 123: { on: true, online: true }, 456: { on: true, online: true, brightness: 80, color: { name: "cerulean", spectrumRGB: 31655 } } } } }; });
Java
@NotNull @Override public QueryResponse onQuery(@NotNull QueryRequest queryRequest, @Nullable Map<?, ?> map) { QueryResponse.Payload payload = new QueryResponse.Payload(); payload.setDevices( new HashMap<String, Map<String, Object>>() { { put( "123", new HashMap<String, Object>() { { put("on", true); put("online", true); } }); put( "456", new HashMap<String, Object>() { { put("on", true); put("online", true); put("brightness", 80); put( "color", new HashMap<String, Object>() { { put("name", "cerulean"); put("spectrumRGB", 31655); } }); } }); } }); return new QueryResponse(queryRequest.getRequestId(), payload); }
Weitere Informationen finden Sie in der Referenzdokumentation zu QUERY
.
EXECUTE
-Intents verarbeiten
Ähnlich wie bei QUERY
kann ein einzelner Intent auf mehrere Geräte-IDs ausgerichtet sein. Ein einzelner EXECUTE
-Intent kann auch mehrere unterschiedliche Befehle für eine Gruppe von Geräten enthalten. Beispielsweise kann ein ausgelöster Intent sowohl die Helligkeit als auch die Farbe einer Gruppe von Lampen oder mehrere Lampen jeweils in einer anderen Farbe festlegen. Ihre EXECUTE
-Antwort sollte nach der Ausführung den neuen Status des Geräts zurückgeben.
Verwende Report State, wenn sich der Status des Nutzergeräts ändert. Beispiel: Aufgrund eines EXECUTE
-Intents oder einer lokalen Statusänderung (z. B. manuelles Umdrehen eines Lichtschalters).
Damit bleibt Google Home Graph synchronized with your cloud service.
{ "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf", "inputs": [{ "intent": "action.devices.EXECUTE", "payload": { "commands": [{ "devices": [{ "id": "123", "customData": { "fooValue": 74, "barValue": true, "bazValue": "sheepdip" } }, { "id": "456", "customData": { "fooValue": 36, "barValue": false, "bazValue": "moarsheep" } }], "execution": [{ "command": "action.devices.commands.OnOff", "params": { "on": true } }] }] } }] }
JSON
{ "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf", "payload": { "commands": [ { "ids": [ "123" ], "status": "SUCCESS", "states": { "on": true, "online": true } }, { "ids": [ "456" ], "status": "ERROR", "errorCode": "deviceTurnedOff" } ] } }
Node.js
const {smarthome} = require('actions-on-google'); const app = smarthome(); // ... app.onExecute((body, headers) => { // TODO Send command to device return { requestId: body.requestId, payload: { commands: [{ ids: ["123"], status: "SUCCESS", states: { on: true, online: true } }, { ids: ["456"], status: "ERROR", errorCode: "deviceTurnedOff" }] } }; });
Java
@NotNull @Override public ExecuteResponse onExecute( @NotNull ExecuteRequest executeRequest, @Nullable Map<?, ?> map) { ExecuteResponse.Payload payload = new ExecuteResponse.Payload(); payload.setCommands( new Commands[] { new Commands( new String[] {"123"}, "SUCCESS", new HashMap<String, Object>() { { put("on", true); put("online", true); } }, null, null), new Commands(new String[] {"456"}, "ERROR", null, "deviceTurnedOff", null) }); return new ExecuteResponse(executeRequest.getRequestId(), payload); }
Weitere Informationen finden Sie in der Dokumentation zu Intent-Referenzen für EXECUTE
.
Statusantworten
Die Antworten QUERY
und EXECUTE
enthalten das Feld status
, um das Ergebnis der Anfrage zu melden. Jede Statusantwort kann einen der folgenden Werte enthalten:
SUCCESS
: Die Anfrage war erfolgreich.OFFLINE
: Das Zielgerät ist offline oder anderweitig nicht erreichbar.EXCEPTIONS
: Mit der Anfrage ist ein Problem oder eine Benachrichtigung verknüpft.ERROR
: Die Anfrage ist mit der entsprechendenerrorCode
fehlgeschlagen.
Weitere Informationen zu ERROR
und EXCEPTIONS
finden Sie unter Fehler und Ausnahmen verwalten und Fehler und Ausnahmen.