Google Assistant commands automation

Hi,

For a long time now I have been experiencing slow responses and random “unable to reach” replies from my Google Assistant integration. I am exposing my HA behind a load balancer (reverse proxy). My tests done so far is that if I do a “sync devices” command before I ask for a light to be turned on or off the commands is executed more or less instantly, but after a while I ask for a light to be turned on again it takes many seconds before the action is executed. Sometimes Google Home also replies back "Sorry, cant reach “application” ". Looking at the logs in my load balancer the total RTT from Google to my HA server is between ~40-150ms. Where the biggest portion of this latency is from Google to my environment. The RTT latency between my load balancer and HA is 1-3 ms (which is expected as they are on my LAN). So the number does not add up in what I experience from I ask the command until it is executed as this can be several seconds. If I do a “sync devices” command just before I say the command its instant again.
Now, is it possible to create an automation issuing the command “sync devices” from HA say every 10 minutes? By using the already installed Google Assistant integration, or other software? Any one have some experience in this?
Tried to read up on this on yesterday on the API pages from Google, found some referencing to Node-Red nodes but I cant seem to figure this out. I would just like to send the simple command “sync devices” to my Google Assistant.

Thanks

hello
there is a service:
service: google_assistant.request_sync

ENABLE DEVICE SYNC

If you want to support active reporting of state to Google’s server (configuration option report_state) and synchronize Home Assistant devices with the Google Home app (google_assistant.request_sync service), you will need to create a service account. It is recommended to set up this configuration key as it also allows the usage of the following command, “Ok Google, sync my devices”. Once you have set up this component, you will need to call this service (or command) each time you add a new device in Home Assistant that you wish to control via the Google Assistant integration. This allows you to update devices without unlinking and relinking an account (see below).

  1. Service Account
  2. In the Google Cloud Platform Console, go to the Create Service account key page.
  3. At the top left of the page next to “Google Cloud Platform” logo, select your project created in the Actions on Google console. Confirm this by reviewing the project ID and it ensure it matches.
  4. From the Service account list, select CREATE SERVICE ACCOUNT.
  5. In the Service account name field, enter a name.
  6. In the Service account ID field, enter an ID.
  7. From the Role list, select Service Accounts > Service Account Token Creator.
  8. Click CONTINUE and then DONE. You are returned to the service account list, and your new account is shown.
  9. Click the three dots menu under Actions next to your new account, and click Manage keys. You are taken to a Keys page.
  10. Click ADD KEY then Create new key. Leave the key type as JSON and click CREATE. A JSON file that contains your key downloads to your computer.
  11. Use the information in this file or the file directly to add to the service_account key in the configuration.
  12. Click Close.
  13. HomeGraph API
  14. Go to the Google API Console.
  15. At the top left of the page next to “Google Cloud Platform” logo, select your project created in the Actions on Google console. Confirm this by reviewing the project ID and it ensure it matches.
  16. Click Enable HomeGraph API.
  17. Try “OK Google, sync my devices” - the Google Home app should import your exposed Home Assistant devices and prompt you to assign them to rooms

Hi and thanks for responding.

I have tried this one, and it doesnt work as expected. I was hoping it was just that simple, but this throws all kinds of 404, 500 errors (with and without agent_user_id). After some searching around I am not sure if that is the same command as “Sync my devices” either.

Thanks

look here

Thanks for your follow up on this. I read all the comments in the thread and tried the one where I just deleted google_assistant config under .storage (even though all information in there were correct), unlinked my HA app in Google Home and relinked it.
I think I only were able to get fewer api errors reported in homegraph. I still have the issue with a huge delay from speaking the command until it is actually executed in HA.
The google_assistant_request_sync service still throw errors in HA logs when executed manually.

I wish I just could find an easy way of scheduling the command “Sync my devices” in Google Home/Assistant every 10 mins or so, then the delay would come down to more or less instant. Then I can buy myself some more time to figure out whats going on, if it is even an issue on my side or at Googles side. The thing is that this is something that has become a problem, it was not like this to begin with.

Thanks

…from the previous link
Finally got rid of them! I had this issue too. Did my setup following the instructions about a couple of weeks ago (so that means I used a service account). I got thousands of Request for https://homegraph.googleapis.com/v1/devices:reportStateAndNotification failed: 404 as well as 403’s each day in my log. Enabling HomeGraph API in Google Cloud Console got rid of the 403’s, but the 404’s remained…
" then disabled HomeGraph API in Cloud Console and restarted Home Assistant; still no errors and still working. Sweet!"
see:

TROUBLESHOOTING

404 errors on request sync

Syncing may fail after a period of time, likely around 30 days, due to the fact that your Actions on Google app is technically in testing mode and has never been published. Eventually, it seems that the test expires. Control of devices will continue to work but syncing may not. If you say “Ok Google, sync my devices” and get the response “Unable to sync Home Assistant” (or whatever you named your project), this can usually be resolved by going back to your test app in the Actions on Google console and clicking Simulator under TEST. Regenerate the draft version Test App and try asking Google to sync your devices again. If regenerating the draft does not work, go back to the Action section and just hit the enter key for the URL to recreate the Preview.

The request_sync service requires that the initial sync from Google includes the agent_user_id. If not, the service will log an error that reads something like “Request contains an invalid argument”. If this happens, then unlink the account from Home Control and relink.

The request_sync service may fail with a 404 if the project_id of the HomeGraph API differs from the project_id of the Actions SDK found in the preferences of your project on Actions on Google console. Resolve this by:

  1. Removing your project from the Google Cloud API Console.
  2. Add a new project to the Actions on Google console Here you get a new project_id.
  3. Run through the previously mentioned [Actions on Google console] setup instructions until the step to create a service_account.
  4. Once you begin to create a new service_account in the [Google Cloud API Console], ensure you select the project created in [Actions on Google console] by verifying the project_id.
  5. Enable HomeGraph API to the new project.

Verify that the Google Assistant is available on https://[YOUR HOME ASSISTANT URL:PORT]/api/google_assistant If it is working it should return 405: Method Not Allowed when opened in a browser or via curl.

Thanks again!
I deleted everything on the Google side, everything on the HA side.
Created a new project in Google, configured everything from scratch in HA following the HA config guide for Google Assistant. Got rid of the 404 error. And just a few API errors in Google.
I also made sure that all potential IPs Google Assistant use is not geo-blocked by my firewall. I still experience some delays (compared to how it was before) when I ask my Google speakers to perform an action on my HA devices.
I have tested to run the request_sync command from HA just before I talk to Google in hope for this to reduce the delay, but I dont seem to get the delay down the same way as when I do when I ask Google to sync my devices. Need to investigate more, but at least now everything should be ok on the HA side.

Thanks