Search code examples
google-homegoogle-smart-home

does reportStateAndNotification support multiple device state reporting?


I am trying to report the status of a couple of devices via API and I am getting this error

Request payload:

 { 
   "requestId":"3310672920401175639",
   "agentUserId":"5d8f3dd42ce05140dc1c6a20",
   "payload":{ 
      "devices":{ 
         "states":[ 
            { 
               "5de28e041729ec0cb40ba906":{ 
                  "on":true
               }
            },
            { 
               "5df49862f53ffa4c1452a448":{ 
                  "on":false,
                  "brightness":100
               }
            }
         ]
      }
   }
}

Response:

{ 
   "error":{ 
      "code":400,
      "message":"Invalid JSON payload received. Unknown name "states" at 'payload.devices': Proto field is not repeating, cannot start list.",
      "status":"INVALID_ARGUMENT",
      "details":[ 
         { 
            "@type":"type.googleapis.com/google.rpc.BadRequest",
            "fieldViolations":[ 
               { 
                  "field":"payload.devices",
                  "description":"Invalid JSON payload received. Unknown name "states" at 'payload.devices': Proto field is not repeating, cannot start list."
               }
            ]
         }
      ]
   }
}

can "states" hold more than one status of the device? or am I doing something wrong with this?


Solution

  • The states value in the payload should be an object with each unique device id as a key. It should not be returned with these wrapped into an array. So your request payload should look more like this:

    { 
      "requestId":"3310672920401175639",
      "agentUserId":"5d8f3dd42ce05140dc1c6a20",
      "payload": { 
        "devices": { 
          "states": { 
            "5de28e041729ec0cb40ba906": { 
              "on": true
            },
            "5df49862f53ffa4c1452a448": { 
              "on": false,
              "brightness": 100
            }
          }
        }
      }
    }