DewGew / DZGA-Flask

Domoticz Google Assisting using Flask
GNU General Public License v3.0
8 stars 4 forks source link

Google CLientID from "Service Account" or from "OAuth 2.0 Client IDs" #76

Closed Xavier82 closed 5 months ago

Xavier82 commented 5 months ago

Hi, sorry to create new "issue".

I have just a question, in your Wiki you mention to use ClientID en ClientSecret. Which ClientID do I need to use? I have a ClientID in my Service Account and I have a clientID in my "OAuth 2.0 Client IDs". Both are different from each other. The CLientID from the service account is actually named "Unique ID". Within the downloaded .json file the same number is mentioned as "Client_id" . The .json file from the Service Account doesn't contain the client_secret but has a Private_key_id. The .json file from "OAuth 2.0 Client IDs" has both client_id and client_secret.

Since I don't get it to work because each time in Google Home I get an error that the project [test] dzga can't be reached I'm not sure where to look for the error...

I hope u can clarify things up. Thanks,

DewGew commented 5 months ago

Service Account with .json file is only to make report state to google servers to work. OAuth 2.0 Client IDs is needed to use google developers API:s nothing to set in DZGA-Flask

This is needed to connection google server to your DZGA-Flask: Client Information, Client ID: Just add som random name, remember it and add it in DZGA-Flask UI under server settings (Actions on Google Client id) Client secret: Just add som random password, remember it and add it in DZGA-Flask UI under server settings (Actions on Google Client secret)

The error that the project [test] dzga can't be reached: Missing step somewhere during installation. Restart from scratch. Make sure your DZGA-Flask is available trough public HTTPS with valid certificate.

Xavier82 commented 5 months ago

Thanks for the information! Client ID and Client Secret match the project in Google Actions Console. I use the .json Service Account file and uploaded it to DZGA uploadfolder.

I use Use ngrok for a secure SSL tunnel with valid public HTTPS URL. Do I need to enable SSL in DZGA? If yes how and where do I get the certificate and key from Ngrok?

Just to clearify: Filled out the form/fiels in DZGA Created project in Google Actions Console (based on the Wiki) Enabled API (based on the Wiki) Created the key in the service account Downloaded the .json file Renamed the .json to smart-home-key.json Uploaded the .json file to DZGA Installed Ngrok on RPi Made settings Ngrok on Rpi Established a tunnel/agent on Rpi with Ngrok. Copied the https://<code>-IP-address.ngrok-free.app Went back to Google Action Console Develop Actions and pasted the link https://<code>-<IP-Address).ngrok-free.app/smarthome Went to account linking and added the link to Authorization URL: https://<code>-<IP-Address).ngrok-free.app/oauth Went to account linking and added the link to Token URL: https://<code>-<IP-Address).ngrok-free.app/token Saved project Tested project Went to Google Home--> add service In Google Home I can my created project I press [test] to add. Then I get the notification "Linking your [test] account". 2 Seconds later I get an other notification "Could not reach [test] . Please try again later".

Ofcourse I tried this several team but with no luck.

Is there something elase I need to do with Ngrok for the part of "DZGA-Flask is available trough public HTTPS with valid certificate." ?

DewGew commented 5 months ago

Other user had this issue also. I google this issue and this solved the issue form some users:

Apparently Google have a little splash screen to the flow that happens before it calls https://[YOUR _DOMIAN]/auth/authorize. In order for this info screen to work correctly, try complete the “Enter information required for the Actions directory” portion of the Actions setup overview. This requires you to provide:

A description of your app
A logo image for your app
Your name and email
A link to a privacy policy

Description example:
Short: “Connect Google Assistant to a private Domoticz server”
Long: “This Action is intended for personal use. It exposes smart home devices controlled by a local Domoticz server to Google Assistant and by extension the Google Home mobile app.”

For the logo, just upload a suitable logo.

For the privacy policy, create a Google Doc that can be viewed by anyone with the link that says:

" This application is intended for the private use of its developer. Any unauthorized users which connect to this service should have no expectation of privacy or protection of their data."

Try now link GA to DZGA-Flask.
Xavier82 commented 5 months ago

Followed your leads and added the information. Then again pressed testing. Went back to Google Home. tried to add the [test] but again same error: "Linking your [test] account" and 2 seconds later I get an other notification "Could not reach [test] . Please try again later".

In DZGA I get these loggs: 2024-01-24 10:05:50 Starting new HTTPS connection (1): accounts.google.com:443 2024-01-24 10:05:50 https://accounts.google.com:443 "POST /o/oauth2/token HTTP/1.1" 200 None 2024-01-24 10:05:50 Starting new HTTPS connection (1): homegraph.googleapis.com:443 2024-01-24 10:05:50 https://homegraph.googleapis.com:443 "POST /v1/devices:requestSync HTTP/1.1" 404 None

But I gues I get this because the project is not added as a service in Google Home.

Xavier82 commented 5 months ago

I created a ticket @Google yesterday and I just got a repley back:

Dear Developer,

Thank you for reaching out to us. Based on the information you provided, it appears that the requestSync is receiving a 404 Not Found response. Please ensure that you have sent a valid agentUserId, and confirm that the agentUserId matches the value in your SYNC Response.

For more information, please refer to: https://developers.home.google.com/cloud-to-cloud/integration/request-sync#error_responses

If the issue persists after you have confirmed that requestSync is working correctly, please share the following information with us:

[SYNC Response](https://developers.home.google.com/cloud-to-cloud/integration/sync)
[Project Viewer access](https://developers.home.google.com/cloud-to-cloud/test#share-action) to our test account: [nedtarly.752093@gmail.com](mailto:nedtarly.752093@gmail.com)
test account and password to your test project
Thank you.

Is this of any help? If I understand correct DZGA can't connect to Google, thats why the 404 error shows up in the logging right? So the issue is somewhere between Google Action, Ngrok? and Google Home. I can reach DZGA as project from Google Home as a service (I need to use username and password to authentica to DZGA, when I press login then Google Home tries to add the service/project ( [test] DZGA ). After that I get the error in Google Home "Could not reach [test] . Please try again later"

Xavier82 commented 5 months ago

ok, so now I do the following (Project and ngrok remain the same, just like settings in DZGA. On the logging of DZGA I see the following directly after I logged in in DZGA after I add the service [test] DZGA: 2024-01-24 11:56:16 generated code 2024-01-24 11:56:19 request: { "inputs": [ { "intent": "action.devices.SYNC" } ], "requestId": "LONGNUMBER" } 2024-01-24 11:56:19 Starting new HTTP connection (1): 192.168.0.30:8084 2024-01-24 11:56:19 http://192.168.0.30:8084 "GET /json.htm?type=command&param=getdevices&plan=0&filter=all&used=true HTTP/1.1" 200 12166 2024-01-24 11:56:19 Retreiving devices from domoticz 2024-01-24 11:56:19 Devices is saved in DZGA_devices.json in config folder 2024-01-24 11:56:20 response: { "requestId": "LONGNUMBER", "payload": { "agentUserId": "DZGA", "devices": [ { All devices from domoticz to sync...

In the Google Home app again the same failure.

DewGew commented 5 months ago

I tested with my RPI with docker dzga-flask to ngrok without any problem. I install DZGA-Flask docker version, change my settings. then I clicked "sync my devices" to retrive my devices to dzga

Then installed ngrok then run ngrok http http://localhost:8181

Changed the links in Action on Google console. Added "sampleClientId" and "sampleClientSecret" in Actions on Google console Clicked test.

Added smart-home-key.json from correct project in Google Cloud console
Then I enabled Google Assistant in dzga-flask UI and add my project in Google Home app

Xavier82 commented 5 months ago

mmzzz ok strange I did exactly the same but not in docker. When I try to add my project [test] DZGA in Google Home then the next thing I get is the login screen of DZGA (so this proves that ngrok and tunnel is working and that DZGA can be reached by Google Actions. I enter my credentials in DZGA screen en klik login, then Google Home says it is trying to connect/add [test] DZGA to Google Home, then I get the error that the [test] DZGA project is can't be reached. I even created a complete new project, just to be sure I did all the steps correct.

Could it be that I use the clientID number from Google credentials instead of just using "sampleClientId"?

DewGew commented 5 months ago

mmzzz ok strange I did exactly the same but not in docker. When I try to add my project [test] DZGA in Google Home then the next thing I get is the login screen of DZGA (so this proves that ngrok and tunnel is working and that DZGA can be reached by Google Actions. I enter my credentials in DZGA screen en klik login, then Google Home says it is trying to connect/add [test] DZGA to Google Home, then I get the error that the [test] DZGA project is can't be reached. I even created a complete new project, just to be sure I did all the steps correct.

Could it be that I use the clientID number from Google credentials instead of just using "sampleClientId"?

Try change clientID and ClientSecret, it must be the same in dzga UI and in action on google console I used "sampleClientId" and "sampleClientSecret" because its already added in dzga from start

EDIT: Dont forget to enabled Google Assistant in dzga-flask UI for the user

Xavier82 commented 5 months ago

I changed clientID en and Clientsecret in DZGA and in Google Actions Console. Pressed Save and Test. Restarted DZGA (with Google Assistant enabled, has always been enabled) but still no luck. I can't add the project to Google Home. Google Home keeps geving me the error that is wasn't able to reach [test] DZGA project. Very weird....

Is there any possibility to get more logging in the GUI error logfile (enhancement)? Or is this only possible by running manually?

Xavier82 commented 5 months ago

I got a response from google about this issue. It seems to be an issue with the sync. I use in Domoticz a device "Door lock Inverted" to monitor my garagedoor. In Domoticz this is set as a type "Light", Google knows 2 action types "On" or "Off" while Domoticz status "Locked" or "Unlocked".

This is a copy of the reaction of Google support: `Dear Developer,

Thank you for sharing the information with us. We've identified an issue with your SYNC Response. The device with device_id DoorLockInverted_353 is marked as a LIGHT type, but its traits are empty, which is invalid. For LIGHT types, the OnOff traits are required. Please refer to https://developers.home.google.com/cloud-to-cloud/guides/light.

To resolve this, kindly update your SYNC Response and ensure it's valid. You can use the SYNC Data Validator for validation.`

I also checked https://developers.home.google.com/cloud-to-cloud/guides/lock

Is this something which can be fixed in DZGA-Flask? Since I can't choose a device type in Domoticz because type "Light" is fixed to Door Lock (Inverted) in Domoticz.

As per test I have disabled all devices which have/are "Doorlock" in Domoticz. I restarted DZGA and I did a sync between DZGA and Domoticz. I went to Google Home and I added again the service "[test] DZGA", and now indeed I'm able to connect to Google Home. So I think we have tracked a possible issue with these type of devices.....

I think this issue is the same problem or part of it and also reflects to DZGA-Flask: https://github.com/DewGew/Domoticz-Google-Assistant/issues/351

DewGew commented 5 months ago

Un supported device you can see under "other devices" in UI dashboard. So if you exclude that device, it should work. (set as hide in device config)

Xavier82 commented 5 months ago

I don't have any "unsupported devices" anymore at this moment, though when I have the doorlock added I still have an issue. Need to investigate this. For now doorlock is hidden. I have upgraded to newest version DZGA.

DewGew commented 5 months ago

I don't have any "unsupported devices" anymore at this moment, though when I have the doorlock added I still have an issue. Need to investigate this. For now doorlock is hidden. I have upgraded to newest version DZGA.

This i now fixed