home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.99k stars 31.03k forks source link

google assistant integration / unable to add test app #31054

Closed Stefan300381 closed 3 years ago

Stefan300381 commented 4 years ago

Hi,

my environment is quite complex:

Synology NAS with hass 0.104.0 running in docker container, host network, port 8123 ipv4 Synology Reverse Proxy, dns name ha.hauptsache.myds.me, port 443, using let's encrypt cert

Internet access via cable DSLite, ipv6 only incoming :-( This means if you try to reach the dns name via ipv4 it won't work. only ipv6

Anyway, so far the reverse proxy works fine and I can access my hass installation via the android companion app remotely (via cell network, German Vodafone) and locally via WiFi.

The problem is the google assistant integration. I read the documentation and setup the whole environment to connect to ha.hauptsache.myds.me.

This works: In Google Home app I click on the "+" to add new devices and I select my test app. The home assistant webpage appears. I enter my credentials and the app shows a popup which tells me in German "sie werden angemeldet" (translated: logging in).

This doesn't work: After a few seconds the popup disappears and I'm back in the "Konten verwalten" (manage accounts) screen. my test app is still not listed under the assigned services section.

Now I wonder, what am I missing? How can I debug this? Things I found in the logfile:

2020-01-17 15:11:28 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/report_state.py", line 45, in async_entity_state_listener
    if entity_data == old_entity.query_serialize():
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/helpers.py", line 442, in query_serialize
    deep_update(attrs, trt.query_attributes())
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/trait.py", line 1288, in query_attributes
    ERR_NOT_SUPPORTED, "Querying state is not supported"
homeassistant.components.google_assistant.error.SmartHomeError: Querying state is not supported
2020-01-17 17:35:10 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/report_state.py", line 45, in async_entity_state_listener
    if entity_data == old_entity.query_serialize():
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/helpers.py", line 442, in query_serialize
    deep_update(attrs, trt.query_attributes())
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/trait.py", line 1288, in query_attributes
    ERR_NOT_SUPPORTED, "Querying state is not supported"
homeassistant.components.google_assistant.error.SmartHomeError: Querying state is not supported
2020-01-21 13:19:20 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/report_state.py", line 45, in async_entity_state_listener
    if entity_data == old_entity.query_serialize():
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/helpers.py", line 442, in query_serialize
    deep_update(attrs, trt.query_attributes())
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/trait.py", line 1288, in query_attributes
    ERR_NOT_SUPPORTED, "Querying state is not supported"
homeassistant.components.google_assistant.error.SmartHomeError: Querying state is not supported

Screenshot_2020-01-21-16-02-01-836_com google android googlequicksearchbox Screenshot_2020-01-21-16-02-17-165_com android chrome Screenshot_2020-01-21-16-02-32-757_com google android googlequicksearchbox

probot-home-assistant[bot] commented 4 years ago

Hey there @home-assistant/cloud, mind taking a look at this issue as its been labeled with a integration (google_assistant) you are listed as a codeowner for? Thanks!

dshokouhi commented 4 years ago

Check all the steps again and ensure that your proxy is properly routing all the api's for google assistant. There are a few URLs you will want to make sure are routed correctly. Also ensure you have removed the app shortcut that gets created from Chrome when you add to homescreen. There is a note about that in the docs as well.

elupus commented 4 years ago

Start with less entities exposed. You are exposing som entity with unknown state.

Stefan300381 commented 4 years ago

@dshokouhi thanks for trying to help, but I'm not sure how to respond. I tried to follow the documentation but unfortunately it's outdated. If you walk through it step by step you'll find out some things have changed. Nevertheless I think I have done it correctly. Not sure about the homescreen shortcut. I didn't have one. The URLs might in deed be the problem. To be correct: my reverse proxy. For home assistant to be accessible via reverse proxy I needed to set some special http header configuration. Not sure if the same is needed on top for for google assistant integration.

@elupus can you be more specific? Maybe google integration doesn't work if one of the entities is in unknown state? I say this because I faced the exact same issue with openHAB in the past, but it was fixed somehow. I don't know the reason. Can you point me to the problematic entity? I'm not even sure my configuration is correct.

This is my config:

google_assistant:
  project_id: home-assistant-project-265414
  service_account: !include home-assistant-project-265414-b665ef99bd7e.json
  report_state: true
  exposed_domains:
    - switch
    - light
    - cover
  entity_config:
    switch.shelly_shsw_1_24d457:
      name: Deckenlicht_HomeOffice
      aliases:
        - BRIGHT_LIGHTS
        - ENTRY_LIGHTS
elupus commented 4 years ago

You are exposing all switches all covers and all lights. Please reduce your exposed entities to a minimum to start with. I suspect it's covers that is causing problem.

Stefan300381 commented 4 years ago

I reduced the config to (see below) and restarted the server. The behavior is still the same, google home app returns to the list of service providers and has not added my test app:

google_assistant:
  project_id: home-assistant-project-265414
  service_account: !include home-assistant-project-265414-b665ef99bd7e.json
  report_state: true

The log says:

2020-01-22 20:29:19 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/report_state.py", line 45, in async_entity_state_listener
    if entity_data == old_entity.query_serialize():
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/helpers.py", line 442, in query_serialize
    deep_update(attrs, trt.query_attributes())
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/trait.py", line 1288, in query_attributes
    ERR_NOT_SUPPORTED, "Querying state is not supported"
homeassistant.components.google_assistant.error.SmartHomeError: Querying state is not supported
dshokouhi commented 4 years ago

@Stefan300381 by default all entities are included based on your configuration. Try to include just 1 entity and see if it works.

Set this false https://www.home-assistant.io/integrations/google_assistant/#expose_by_default

Then expose only 1 device

Stefan300381 commented 4 years ago

@dshokouhi my config below (without any entity), same behavior. After login I'm back in the accounts screen of google home app.

Any chance I can manually test/verify the URLs I have setup in the google actions console?

https://ha.hauptsache.myds.me/api/google_assistant https://ha.hauptsache.myds.me/auth/authorize https://ha.hauptsache.myds.me/auth/token

google_assistant:
  project_id: home-assistant-project-265414
  service_account: !include home-assistant-project-265414-b665ef99bd7e.json
  expose_by_default: false
  report_state: true
cybrox commented 4 years ago

I just performed the whole setup myself and I used the same config @Stefan300381 ended up with in his last comment. (Unintentionally, I only now found this issue). I am currently facing the exact same problem.

I don't know a lot about OAuth but as far as I know, the service must provide a redirect-url after a succesful login. Could it be that the redirect URL that homeassistant provides is wrong?

elupus commented 4 years ago

Any errors in log when no entities are setup? @Stefan300381 also are you behind som reverse proxy?

cybrox commented 4 years ago

Network wise, I'm using a DynDNS with an additional CNAME record on top of it plus port-forwarding, so technically the most straight-forward configuration.

There are no errors in the log. I have a few test entities set up (TV + Hue) but set expose_by_default to false in the config. Should I delete them all for further testing?

cybrox commented 4 years ago

For additional information:

So, I'm pretty much out of ideas for the moment. I wish Google Home itself would provide some more meaningful errors other than just "it did not work" :roll_eyes:

Stefan300381 commented 4 years ago

My main question remains, what can I do to test the setup components (like authorization URL). Something is clearly not working, but what?

elupus commented 4 years ago

If you haven't, turning on debug logging might help. Also, the test app is enable I'm action console right? It turns off after some time.

Stefan300381 commented 4 years ago

@elupus

debug didn't reveal anything more. about testing: to be honest I'm not 100% sure. I thought if testing isn't enabled then the test app wouldn't show up in the google home app, right? in the google actions console it says on the top right: testing on device: enabled

Stefan300381 commented 4 years ago

@cybrox, did you make any progress?

cybrox commented 4 years ago

@Stefan300381 Sadly not. I tried the HomeAssistant cloud free trial period just to see if my setup somehow messes that connection up as well (I know it's different endpoints but I'm running out of ideas) but that works fine.

My next guess would be to see if there's any way to have Home Assistant log every single HTTP request and its OAuth flow. From how I understand the OAuth workflow, the error happens after successful authorization of the Google App Client, which leads me to believe that either the redirect URL used in the guide is wrong (outdated) or Home Assistant gets a request that errors right after completing the OAuth flow and the Google Home app aborts.

I'll report if I figure something out. Will look at it in the next few days again.

Stefan300381 commented 4 years ago

@cybrox The strange thing is, that I experienced exactly the same situation with openHAB in the past. But the problem solved itself after a day or two. And with openHAB I was NOT using my own local instance, but the official cloud service. This is so frustrating, as I would really love to move from openHAB to HA ;-)

codecvlt commented 4 years ago

I'm having the exact same issue. Except there are no errors at all in the logs. Checked debug level as well, nothing..

cybrox commented 4 years ago

@codecvlt How are you running HomeAssistant? It seems @Stefan300381 and I are both running it in a docker container. Are you using docker as well?

I'm considering trying out the actual hass.io image for the Raspberry Pi and see if there's any difference. - I know there really should not be but I'm absolutely out of ideas and I don't think this issue will get much actual attention, since the GA integration is one of Nabu Casa's selling points.

codecvlt commented 4 years ago

I'm running it in docker yes. Took this route cuz I also run pihole on the same pi and that has its own image. Let me know if you have any luck with the hassio image.

cybrox commented 4 years ago

cc @codecvlt @Stefan300381 I tried using the actual hass.io image on the raspberry pi, complete with plugin registry and re-setup let's-encrypt via plugin. Re-published the test application aaand.... the exact same error...

The only idea I have left would be to re-setup the docker setup and use tcpdump to capture traffic on lo and see if there's any clue in there, as to why it is not working. To be honest, I'm kind of running out of motivation, though.

Stefan300381 commented 4 years ago

Thanks for testing. Do you have an ipv4 internet account? I run unity media which is ipv6 only (idp ipv4 natted). For now I will just stay with Openhab where they provide the cloud service for free. A pity as I love HA

cybrox commented 4 years ago

Per default, my provider sets up a dual-stack setup, but I had them change it to just IPv4 because of some legacy devices. I think if network connectivity was the issue, Google Assistant would not be able to even start the OAuth flow and show the HomeAssistant login screen.

Interestingly, I actually forgot to add my GCP credentials yesterday, and the error was the exact same. Added them today, went through the whole app setup process again, still no luck. Commented them out, same error.

This leads me to assume that the issue is with the GCP access configuration. Maybe they just updated the expected configuration format, the documentation is oudated and our provided settings are never even loaded / have no impact at all...

elupus commented 4 years ago

If gcp you mean the service account, then that is not needed to complete the linking.

cybrox commented 4 years ago

What is the service account used for then? Just so that HA can push new devices to google without performing the authentication flow again?

Regarding my previous answer, the config seems to be loaded correctly. I can comment out keys and it will complain about them missing, so that's working, even though it might not have any impact on the error.

cybrox commented 4 years ago

For the sake of completion for the maintainers, I ran the whole flow again with debug logging enabled for all components.

Sometimes, there would be a 404 returned by the following endpoint so I removed all integrations and tried again.

2020-02-27 10:04:57 DEBUG (MainThread) [homeassistant.components.google_assistant.http] Response on https://homegraph.googleapis.com/v1/devices:reportStateAndNotification

This is the debug log during the OAuth flow. Looks to me like the flow completes successfully and there is no additional activity logged afterwards. (Set the default log level to debug, so all components should log).

2020-02-27 09:56:27 DEBUG (MainThread) [homeassistant.components.http.view] Serving /auth/providers to 172.30.33.2 (auth: False)
2020-02-27 09:56:27 DEBUG (MainThread) [homeassistant.components.http.view] Serving /manifest.json to 172.30.33.2 (auth: False)
2020-02-27 09:56:27 DEBUG (MainThread) [homeassistant.components.http.view] Serving /auth/login_flow to 172.30.33.2 (auth: False)
2020-02-27 09:56:36 DEBUG (MainThread) [homeassistant.components.http.view] Serving /auth/login_flow/8cb89d631d0c442a8573b73a441afb90 to 172.30.33.2 (auth: False)
2020-02-27 09:56:38 DEBUG (MainThread) [homeassistant.components.http.view] Serving /auth/login_flow to 172.30.33.2 (auth: False)
2020-02-27 09:56:38 DEBUG (MainThread) [homeassistant.components.http.view] Serving /manifest.json to 172.30.33.2 (auth: False)
2020-02-27 09:56:39 DEBUG (MainThread) [homeassistant.components.http.view] Serving /auth/token to 172.30.33.2 (auth: False)
2020-02-27 09:56:41 DEBUG (SyncWorker_17) [homeassistant.helpers.storage] Writing data for auth
2020-02-27 09:56:41 DEBUG (MainThread) [homeassistant.components.http.auth] Authenticated 172.30.33.2 for / using bearer token
2020-02-27 09:56:49 DEBUG (MainThread) [homeassistant.components.http.view] Serving /api/hassio/app/entrypoint.js to 172.30.33.2 (auth: False)
2020-02-27 09:56:49 DEBUG (MainThread) [homeassistant.components.http.view] Serving /api/hassio/app/chunk.b2dce600432c76a53d8c.js to 172.30.33.2 (auth: False)
2020-02-27 09:56:49 DEBUG (MainThread) [homeassistant.components.http.view] Serving /api/hassio/app/chunk.e46c606dd9100816af4e.js to 172.30.33.2 (auth: False)
2020-02-27 09:56:49 DEBUG (MainThread) [homeassistant.components.http.view] Serving /api/hassio/app/chunk.0b82745c7bdffe5c1404.js to 172.30.33.2 (auth: False)
2020-02-27 09:56:49 DEBUG (MainThread) [homeassistant.components.http.view] Serving /api/hassio/app/chunk.d4931d72592ad48ba2be.js to 172.30.33.2 (auth: False)
2020-02-27 09:56:49 DEBUG (MainThread) [homeassistant.components.http.view] Serving /api/hassio/app/chunk.4d45ee0a3d852768f97e.js to 172.30.33.2 (auth: False)
2020-02-27 09:56:49 DEBUG (MainThread) [homeassistant.components.http.view] Serving /auth/token to 172.30.33.2 (auth: False)
2020-02-27 09:56:49 DEBUG (MainThread) [homeassistant.components.http.view] Serving /auth/token to 172.30.33.2 (auth: False)
2020-02-27 09:56:49 DEBUG (MainThread) [homeassistant.components.http.auth] Authenticated 172.30.33.2 for /api/hassio/ingress/session using bearer token
2020-02-27 09:56:49 DEBUG (MainThread) [homeassistant.components.http.view] Serving /api/hassio/ingress/session to 172.30.33.2 (auth: True)
2020-02-27 09:56:49 DEBUG (MainThread) [homeassistant.components.http.auth] Authenticated 172.30.33.2 for /api/hassio/addons/core_configurator/info using bearer token
2020-02-27 09:56:49 DEBUG (MainThread) [homeassistant.components.http.view] Serving /api/hassio/addons/core_configurator/info to 172.30.33.2 (auth: True)
2020-02-27 09:56:49 DEBUG (MainThread) [homeassistant.components.http.view] Serving /api/hassio_ingress/TE80BnOLBnZSSRBfolvAybyOuB9mVUhw7T5bP31F3NE/ to 172.30.33.2 (auth: False)
2020-02-27 09:56:49 DEBUG (MainThread) [homeassistant.components.http.auth] Authenticated 172.30.32.2 for /api/services using bearer token
2020-02-27 09:56:49 DEBUG (MainThread) [homeassistant.components.http.view] Serving /api/services to 172.30.32.2 (auth: True)
2020-02-27 09:56:49 DEBUG (MainThread) [homeassistant.components.http.auth] Authenticated 172.30.32.2 for /api/events using bearer token
2020-02-27 09:56:49 DEBUG (MainThread) [homeassistant.components.http.view] Serving /api/events to 172.30.32.2 (auth: True)
2020-02-27 09:56:49 DEBUG (MainThread) [homeassistant.components.http.auth] Authenticated 172.30.32.2 for /api/states using bearer token
2020-02-27 09:56:49 DEBUG (MainThread) [homeassistant.components.http.view] Serving /api/states to 172.30.32.2 (auth: True)

These look to me like google actually got a correct bearer token and is using it to do.. something(?)

2020-02-27 10:13:50 DEBUG (MainThread) [homeassistant.components.http.view] Serving /api/services to 172.30.32.2 (auth: True)
2020-02-27 10:13:50 DEBUG (MainThread) [homeassistant.components.http.auth] Authenticated 172.30.32.2 for /api/events using bearer token
2020-02-27 10:13:50 DEBUG (MainThread) [homeassistant.components.http.view] Serving /api/events to 172.30.32.2 (auth: True)
2020-02-27 10:13:50 DEBUG (MainThread) [homeassistant.components.http.auth] Authenticated 172.30.32.2 for /api/states using bearer token

Yet, the Google Assistant app still just flashes the Couldn't update settings, check your connection banner after Logging in... and Linking to [test] HomeAssistant

elupus commented 4 years ago

Service account is for syncing new or changed devices on request from hass. You can do this from GA instead by asking it to "Sync my devices". It is also used if you turn on report state feature to proactively report state to GA

elupus commented 4 years ago

Sorry didn't mean to close. Missed button on mobile.

elupus commented 4 years ago

I suggest you disable state reports and remove service account untill you get it linked. Reduces potential issues.

elupus commented 4 years ago

Think you could temporarily port forward instead of using your reverse proxy? So we can exclude it as a problem.

cybrox commented 4 years ago

Ah, gotcha, thanks for clarifying what it actually does.


I suggest you disable state reports and remove service account untill you get it linked. Reduces potential issues.

Disabled it and commented out the service_account portion of the config. HA does not complain but the log output remains the same.

Think you could temporarily port forward instead of using your reverse proxy? So we can exclude it as a problem.

I think @Stefan300381 was using a reverse proxy in his original issue report. I've always used port-forwarding. Forwarding 80, 443 and 8123 to the Pi at the moment. Accessing it from the outside via the HA app for example works and the certificate is valid. So I'm pretty sure that part of the set-up should be alright.

elupus commented 4 years ago

Never forward anything but 443 with certs in place. Just as a ps.

cybrox commented 4 years ago

I'm pretty sure port 80 is needed when using http as acme-challenge for certificate renewal?
I agree that forwarding 8123 makes no sense anymore, once https is set up properly.

Edit: Plus since browsers still default to HTTP, I like having an HTTPS redirect in place for convenience.

Dirckvdb commented 4 years ago

I have the exact same problem. Anyone with a possible solution?

faizalgazali commented 4 years ago

I have the same issue. Really hoping to get my HA to interact with GA

elupus commented 4 years ago

Any errors in your logs @faizalgazali and @Dirckvdb

Dirckvdb commented 4 years ago

Any errors in your logs @faizalgazali and @Dirckvdb

@elupus no, unfortunately I seen nothing in the logs

faizalgazali commented 4 years ago

After login page it is linking WhatsApp Image 2020-03-21 at 17 36 19 And after that WhatsApp Image 2020-03-21 at 17 36 09 In HA new token created represents a login session. And no logs.

Dirckvdb commented 4 years ago

I get the follow error after the login page.

The error translates: Something went wrong, please try again.

IMG_2071

CodeInDreams commented 4 years ago

Exactly same issue here. No useful logs.

Dirckvdb commented 4 years ago

@CodeInDreams @faizalgazali are you guys also running home assistant in Docker in combination with Nginx?

CodeInDreams commented 4 years ago

@CodeInDreams @faizalgazali are you guys also running home assistant in Docker in combination with Nginx?

I'm running Home Assistant 0.106.6 on HassOS 3.12. Using nginx on hass.io official repository. Here is the config: domain: #mydomain.com certfile: fullchain.pem keyfile: privkey.pem hsts: max-age=31536000; includeSubDomains cloudflare: false customize: active: false default: nginx_proxy_default.conf servers: nginx_proxy/.conf

faizalgazali commented 4 years ago

@CodeInDreams I am using HassOS 3.12 on raspberry pie with Nginx

CodeInDreams commented 4 years ago

Just full clean installed 0.107.7 on another ubuntu server (18.04). Same issue.

2020-04-08 01:59:27 DEBUG (MainThread) [homeassistant.components.http.view] Serving /auth/providers to 172.30.33.3 (auth: False)
2020-04-08 01:59:28 DEBUG (MainThread) [homeassistant.components.http.view] Serving /auth/login_flow to 172.30.33.3 (auth: False)
2020-04-08 01:59:37 DEBUG (MainThread) [homeassistant.components.http.view] Serving /auth/login_flow/b1e0fbb9b381479c8523496458ab0fd1 to 172.30.33.3 (auth: False)
2020-04-08 01:59:45 DEBUG (MainThread) [homeassistant.components.http.view] Serving /auth/login_flow to 172.30.33.3 (auth: False)

My time zone is UTC+8 Asia/Shanghai. The date in log is 1 hour later than real time.

chielbos commented 4 years ago

Same problem :(

Could not update settings, please check your connection.

image

Sciph3r commented 4 years ago

Decided to start this Google Assistant integration endeavor two days ago. Was basically stuck at the same connection issue when trying to link in the Google Home app. I was able to finally link it though, but I don't know if this was due to maybe a time thing or a small change I did. The change itself was setting the role of the service account you created (and have set under service_account in configuration.yaml) to Owner within the IAM page in GCP (mine was set to Editor initially)

Hopefully this provides some insight into this issue

elupus commented 4 years ago

Odd. That role doesn't even exist for me. I have mine set to "Service Account Token Creator"

cybrox commented 4 years ago

I think mine was "Service Account Token Creator" as well, since that's what the HomeAssistant documentation recommends. I did not find any way to check or even modify this. But I did delete and re-create the service role and I can select "Project" > "Owner" in the progress.

Unfortunately, I tore down my whole test setup (Running via NabuCasa at the moment, because I just didn't have time to deal with this), so I can't really test if it makes a difference :(

Sciph3r commented 4 years ago

Decided to start this Google Assistant integration endeavor two days ago. Was basically stuck at the same connection issue when trying to link in the Google Home app. I was able to finally link it though, but I don't know if this was due to maybe a time thing or a small change I did. The change itself was setting the role of the service account you created (and have set under service_account in configuration.yaml) to Owner within the IAM page in GCP (mine was set to Editor initially)

Hopefully this provides some insight into this issue

A slight clarification. The change to owner was made to the default service account, not to the one you would create with the JSON key:

tempsnip

Essentially, the one with [Your_Project_ID]@appspot.gserviceaccount.com

I changed it by clicking on the Pencil edit under Inheritance, then changing the Role to Project -> Owner

image