actions-on-googlegoogle-smart-home

How does Action on Google Smart Home API works Asynchronously?


I recently developed a project on Amazon Alexa for Smart Home Skill API and We developed using Async Method. In Alexa there are Event Gateway to make post call Asynchronously and deffered response to keep event gateway open. I know that Action on Google has homegraph. Working of HomeGraph and EventGateway is it the same I was wondering? I was also wondering how can I make the Execution Asynchronous for the Action on Google? According to my understanding I'll be requiring to make a post call to Homegraph for that purpose.


Solution

  • Yes, you can make a POST to the home graph once the state is completely changed.

    For certain types of devices, which may take a while to complete, you can return an execute response with a PENDING:

    {
      "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
      "payload": {
        "commands": [{
          "ids": ["123"],
          "status": "PENDING",
          "states": {
            "on": false,
            "online": true
          }
        }]
      }
    }
    

    Later, once the status is correct, you can use the Report State API:

    {
      "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
      "agentUserId": "1234",
      "payload": {
        "devices": {
          "states": {
            "123": {
              "on": true
            },
          }
        }
      }
    }