3

I spent many hours trying to update Home Graph in real-time in more than 1 device.

Actually this project have 2 devices: 1 washer and 1 lamp.

The washer is perfect, real-time update when I make changes direct in database.

The lamp is the problem. If I make changes direct in database it just updates if I close the device page and open again (on Google Home App, of course). It is not updating in real-time.

I believe the problem is in this code below, because I don't know how many devices it is calling in [context.params.deviceId], but I'm not sure if this is the problem or how to solve it.

Please help me with that. I spent all night in this for nothing.

Many thanks in advance.

PS: I've followed that tutorial to make the washer work perfectly. https://codelabs.developers.google.com/codelabs/smarthome-washer/


UPDATE:

I tried something new:

I used all the code exactly as the tutorial on the link above and changed only the action device type action.devices.types.WASHER to action.devices.types.LIGHT or action.devices.types.SWITCH

After this test I realized that the real-time ReportState is only working with the washer and not working with the light or the switch even changing only one line of code.

So it looks like the problem is on Google, not in the code. Does anyone agree?

/**
 * Send a REPORT STATE call to the homegraph when data for any device id
 * has been changed.
 */
exports.reportstate = functions.database.ref('{deviceId}').onWrite(async (change, context) => {
  console.info('Firebase write event triggered this cloud function');
  const snapshot = change.after.val();

  const requestBody = {
    requestId: 'ff36a3cc', /* Any unique ID */
    agentUserId: '123', /* Hardcoded user ID */
    payload: {
      devices: {
        states: {         
          [context.params.deviceId]: {
            on: snapshot.OnOff.on,          
          },          
        },
      },
    },
  };

  const res = await homegraph.devices.reportStateAndNotification({
    requestBody
  });
  console.info('Report state response:', res.status, res.data);
});
  • Can you please clarify a couple of things? Does the report state method return an error in any case or does it always return successful? Also, when you say "real-time update" are you referring to the UI in the Google Home app updating or are you using some other method to verify that the data was saved to Home Graph? – devunwired Oct 28 '19 at 17:14
  • Sure, thanks for trying to help. 1 - The ReportState always return successful. 2 - When I say "real-time update", yes I'm referring to the UI in the Google Home App on my Android smartphone. – Renann Antunes Oct 28 '19 at 20:05

1 Answers1

0

The Google Home app UI is not tied directly to the report state functionality in your smart home integration, so it's not the best method for verifying your integration's behavior. I would suggest using tools like the report state dashboard and the test suite for smart home to validate the data you are posting to Home Graph instead. If you're seeing the right results using these tools, it means your report state implementation is correct.

devunwired
  • 62,780
  • 12
  • 127
  • 139