स्मार्ट होम ऐक्शन बनाने का तरीका सीखने के लिए, Google Home डेवलपर सेंटर में आपका स्वागत है. ध्यान दें: आप Actions कंसोल में कार्रवाइयां बनाना जारी रखेंगे.

क्वेरी और एक्ज़ीक्यूट करें

संग्रह की मदद से व्यवस्थित रहें अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.

जब उपयोगकर्ता 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. से इंटरैक्ट करते हैं

QUERY इंटेंट हैंडल करें

आपके QUERY रिस्पॉन्स में, अनुरोध किए गए डिवाइसों के साथ काम करने वाले हर एट्रिब्यूट के लिए, स्थितियों का पूरा सेट शामिल होता है.

अनुरोध
{
    "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);
}

ज़्यादा जानकारी के लिए, QUERY इंटेंट रेफ़रंस दस्तावेज़ देखें.

EXECUTE इंटेंट हैंडल करें

QUERY की तरह, सिर्फ़ एक इंटेंट ही कई डिवाइस आईडी को टारगेट कर सकता है. एक EXECUTE इंटेंट में कई अलग-अलग निर्देश भी शामिल हो सकते हैं, जो डिवाइसों के एक ग्रुप को दिए जाते हैं. उदाहरण के लिए, ट्रिगर किया गया इंटेंट लाइट के समूह पर चमक और रंग, दोनों सेट कर सकता है या अलग-अलग रंगों में एक से ज़्यादा रोशनी सेट कर सकता है. एक्ज़ीक्यूशन के बाद EXECUTE आपके रिस्पॉन्स से डिवाइस की नई स्थिति मिल जाएगी.

उपयोगकर्ताओं के डिवाइस की स्थिति में बदलाव होने पर Report State का इस्तेमाल करें. उदाहरण के लिए, EXECUTE में कोई इंटेंट या स्थानीय स्थिति में बदलाव होने पर (जैसे कि लाइट स्विच को मैन्युअल रूप से बदलना). यह 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);
}

ज़्यादा जानकारी के लिए, EXECUTE पहचान के लिए दस्तावेज़ देखें.

स्थिति के जवाब

आपके QUERY और EXECUTE जवाबों में अनुरोध के नतीजे की रिपोर्ट करने के लिए, एक status फ़ील्ड शामिल होता है. स्थिति के हर जवाब से, इनमें से कोई एक वैल्यू मिल सकती है:

  • SUCCESS अनुरोध पूरा हुआ.
  • OFFLINE: टारगेट डिवाइस ऑफ़लाइन है या उसे ऐक्सेस नहीं किया जा सकता.
  • EXCEPTIONSअनुरोध से जुड़ी कोई समस्या या सूचना है.
  • ERROR: संबंधित errorCode के साथ अनुरोध पूरा नहीं हुआ.

ज़्यादा जानकारी के लिए, ERROR और EXCEPTIONS गड़बड़ियां और अपवाद प्रबंधित करना और गड़बड़ियां और अपवाद देखें.