Search code examples
actions-on-googlegoogle-homegoogle-smart-home

Smart Home - Correct JSON to respond to EXECUTE when device is offline


When i try to execute a command and that the device is offline, Assistant still tell me that the command as been successfully be done.

I don't have this problem when it's a QUERY request, but with EXECUTE...

This is my returned JSON:

{
  "requestId": "XXXXXX",
  "payload": {
    "commands": [
      {
        "ids": [123],
        "status": "ERROR",
        "errorCode": "deviceTurnedOff",
        "online": false
      }
    ]
  }
}

I have also try this:

{
  "requestId": "XXXXXX",
  "payload": {
    "commands": [
      {
        "ids": [123],
        "status": "OFFLINE",
        "errorCode": "deviceTurnedOff",
        "online": false
      }
    ]
  }
}

I expect that when i try to do a command on an offline device, google assistant tell me that the device is not available, but i have a Ok, i turn the light on instead.

So if you have any idea, because i have checked my JSON response 1 million times and read the documentation many times but i can't find my mistake.


Solution

  • The documentation here is a bit confusing because the example shows the response payload for the QUERY intent.

    The response payload for an EXECUTE intent is slightly different and is documented here.

    The JSON using the correct reference the EXECUTE response payload will look like:

    {
      "requestId": "XXXXXX",
      "payload": {
        "commands": [{
          "ids": ["123"],
          "status": "OFFLINE",
          "errorCode": "deviceTurnedOff"
        }]
      }
    }
    

    Note: deviceId should be a string, as noted in the EXECUTE Response payload details.

    Quoting from the doc:

    ids: Array. Required. Partner device IDs of the response