mikejac / node-red-contrib-google-smarthome

A collection of Node-RED nodes to control your smart home devices via Google Assistant.
GNU General Public License v3.0
121 stars 38 forks source link

Unable to pass Check, then "Could not reach ..." #188

Closed jazzgil closed 2 years ago

jazzgil commented 3 years ago

Thanks for this library. I'm still trying to make it work for me.. :)

I'm unable to pass the check test. Noticed in Node-red's log the following:

SmartHome:Start(listen): using internal SSL
SmartHome:Start(): registered routes:
SmartHome:Start(): \oauth
SmartHome:Start(): \oauth
SmartHome:Start(): \token
SmartHome:Start(): \smarthome
SmartHome:Start(): \check
SmartHome:Start(): \smarthome

Notice the '\'. I guess this makes /check and /oauth operations fail with "Cannot GET"...

Windows 10.0.19042 64bit Node.js v16.9.1 Node-RED v2.0.6 node-red-contrib-google-smarthome v0.1.8

Any idea why this happens? Thanks for your help!

Caprico85 commented 3 years ago

Yes, the '\' is the problem. We use path.join() to build URLs, although path.join() is only for file system paths. On Windows it uses backslashes, which will not work for URLs. I'll see, if I can fix it this evening.

Caprico85 commented 3 years ago

Thanks to @ckhmer1. Should be fixed in 0.1.9.

jazzgil commented 3 years ago

I guess I'm the first to try the library on Windows? wow - I didn't know Windows was that unpopular for Node-Red ;)

Thanks for your efforts! I'll try it right away

jazzgil commented 3 years ago

SUCCESS! :))

Now trying to figure out why the app rejects the connection after a successful login. Getting "Could not reach [test] devName. Please try again".

Client ID and Secret are alphanumeric. Any quick ideas to direct my investigation? No error is thrown to the log on Node-red side.

HttpAuth:httpAuthRegister(GET /oauth)
GET /oauth?response_type=code&client_id=NodeRedSmarthome&redirect_uri=https://oauth-redirect.googleusercontent.com/r/myhome&state=ABdO3MW... 200 0.669 ms - 7914
HttpAuth:httpAuthRegister(POST /oauth): body = {"username":"","password":"","client_id":"NodeRedSmarthome","redirect_uri":"https://oauth-redirect.googleusercontent.com/r/myhome","state":"ABdO3MW...","response_type":"","id_token":"eyJhbGci..."}
HttpAuth:httpAuthRegister(POST /oauth): Google login
HttpAuth:httpAuthRegister(POST /oauth): email (myemail) valid: true
HttpAuth:handleUserAuth(): login successful
HttpAuth:handleUserAuth(): authCode successful; authCode = HrDNbG...
POST /oauth 302 305.108 ms - 1536

Looks like the process stops in the beginning of the step: "Google calls our service to exchange the auth code into an access token." Do I need any specific nodes set up other than just a Management node at this point?

jazzgil commented 3 years ago

My Action Console - Account linking settings. Anything missing?

Clipboard01 And Action...: Clipboard02

ckhmer1 commented 3 years ago

try adding a new node, not only the management one.

jazzgil commented 3 years ago

Added. Even got this on the log:

Devices:SetState(): state = {"online":true,"on":true,"brightness":50,"color":{"name":"","temperatureK":3000}}
Device:SetState(): key = "online"
Device:SetState(): key = "on"
Device:SetState(): key = "brightness"
Device:SetState(): key = "color"
HttpActions:reportState(): deviceId = 8aedd4d1.866dd8
HttpActions:reportState(): states = {"online":true,"on":true,"brightness":50,"color":{"name":"","temperatureK":3000}}

But still, device refusing to be added. Even tried to remove the project and redefine it. No dice. Still investigating...

ckhmer1 commented 3 years ago

Could you please add more log rows? I need to understand the result of the report state.

Also, could you please restart node red and post the complete log starting from the restart?

jazzgil commented 3 years ago

Sure. I've further set node-red to debug: output.log

Thanks for your help

ckhmer1 commented 3 years ago

It seems that you have problem with mqtt, are you able to remove all the nide using it (mqtt) and try it again?

jazzgil commented 3 years ago

Are you referring to the exception there? It's related to bad login credentials for Tesla. I'll disable it and try again.

Or is there another issue with mqtt I'm missing? Also, bare in mind anything past line 115 is me pressing Ctrl-C.... :)

jazzgil commented 3 years ago

One place in the setup which may be the problem is steps 3 and 4 under "Integrating Google Sign-In":

  1. In the sidebar under "APIs & Services", select Credentials, then click Configure consent screen.
  2. Choose an Email Address, specify a Product Name, and press Save.

Never deciphered what those mean. I don't have "Configure consent screen" in Credentials.

ckhmer1 commented 3 years ago

Hi, I'm sorry but I'm a bit confused about the status.

Are you able to link the Google home app with Node-RED? Could you please describe exactly all the steps, where it starts to not work and include the complete log?

Thanks

jazzgil commented 3 years ago

Status is till the same. "Could not reach..." - unable to link home app. Failure point is shown here

Caprico85 commented 3 years ago

The problem seems to happen at the point when the user filled out the login form, we generated an auth code and redirected the user back to Google. Now Google should call /token to exchange the auth code into tokens. But Google does not call, there are no further request in the log.

So either Google is requesting the wrong URL, the HTTP request doesn't get through or some other setting is blocking Google from calling your service and it's incorrectly reported as "can't reach"

So my advices would be:

Caprico85 commented 3 years ago

Never deciphered what those mean. I don't have "Configure consent screen" in Credentials.

Damn. Google seems to regularly move around those options. I should probably recreate my project once again and update the Readme. In the meantime, I'd recommend disabling "Use Google login" and use username/password.

jazzgil commented 3 years ago

Thanks @Caprico85. reqbin.com POST returns 400 exactly as you expected. All other tests you listed result the same: "can't reach". The last thing shown in the log is that "POST /oauth 302".

I've run out of ideas. Google's log doesn't show anything, otherwise it could have helped pinpoint the problem. :(

Caprico85 commented 3 years ago

For comparison, these are the settings in my Management node. Although I don't think you have something totally wrong there.

image image

Caprico85 commented 3 years ago

I just noticed something interesting.

Your Actions Console looked like this:

image

Mine looks like this:

image

Something is strange in your Actions Console. Did you create your project of type "Smart Home"?

image

jazzgil commented 3 years ago

@Caprico85, I've since redid my Action definition on Google, and now my Develop page options look the same as yours. Still no go.

@ckhmer1, what do you mean by interactive check? Where do I use/see it? Thanks!

ckhmer1 commented 3 years ago

Enable the log in the Google configuration node and open again the check link

jazzgil commented 3 years ago

"Google configuration node" - are you referring to this:

image

Enabled... I don't see any new log entries, other than what I've listed above.

ckhmer1 commented 3 years ago

Did you open again the check link https://example.com:3001/check ?

Caprico85 commented 3 years ago

@jazzgil ActivePresenter looks promising. Thank you! Already working on the first video.

FireWizard52 commented 2 years ago

Hi,

It seems that I have the same issue as @jazzgil and I'm not able to reach google smarthomeserver.

I followed the guideline carefully and with some minor deviations as follows:

  1. Go to the Actions console.

  2. Click New project.

  3. Enter a name for your project (Project Name: "A name")

  4. Choose a language for your action (you can change later): Dutch

  5. Choose your country or region: Netherlands

  6. Click Create Project

  7. What kind of Action do you want to build? Choose Smart Home

  8. Click Start Building

  9. Under Quick Setup, click Name your Smart Home action. Enter the name for your Action (Name). This is the name of the smart home Action that you can connect to from the Google Home app.

  10. Click Save

  11. Click Actions in the left menu.

  12. In the Fulfillment URL field, enter a URL for the backend server that will provide fulfillment for the smart home intents and then click Save. https://example.nl:3001/smarthome

  13. All other fields empty or untouched. Log level: Error

  14. Click Save

  15. Still on the development tab click Account

  16. Client ID and secret: Credentials, with which Google will authenticate against your app. Use a password generator tool to generate two strings of reasonable length and complexity. Copy both strings, you'll need them later.

  17. Authorization URL: https://example.nl:3001/oauth

  18. Token URL: https://example.nl:3001/token

  19. All other fields are empty

  20. Click Save 21 On tab Test, click Reset Test

  21. Goto Home Graph API

  22. In the header bar select your project from the project chooser

  23. Enable the [HomeGraph API].

  24. Go to Google Cloud Console API & Services page

  25. Again, select your project in the header bar

  26. Select + Create Credentials and create a Service account key

  27. Enter a name for your service account (A name) and click Create and Continue

  28. Click Done

  29. Your new service account is listed on the Credentials page. Click on it

  30. In the page Service account details, click on Keys

  31. Click on Add Key to create a new key of type JSON

  32. Download the JSON Web Token keyfile (jwt Key) and copy it to your Node-RED server, in a location where the Node-RED service can read it. Copied it to /home/pi/.node-red

I'm using Node RED version 2.1.3, Node version 14.18.1 and Google Smarthome version 0.1.13.

Filled in carefully the Configuration Node. Both the Configuration Node and a Light Node for testing show "Ready"

However trying with ReqBin and the URL https://example.nl:3001/check shows: 404 (Not Found) If I browse from the internal network to the same URL, I see: Cannot GET /check

Checking with nmap show that port 3001 has been opened, so I assume that the "webserver" is running. And pressing "Deploy" in Node Red show an error message for the Configuration node: "HttpActions:reportState(): no user logged!"

Does anybody has an idea, what could be wrong. I have already tried to setup this project 2 times, the only thing I see is two times the same project in the Google Home app. Any hint is appreciated.

Thanks in advance

Regards

Caprico85 commented 2 years ago

What do the server settings in your config look like? They should look like this:

image

Port must be 3001, otherwise it would obviously be https://example.nl:12345/check. Path must be empty, otherwise it would be https://example.nl:3001/your_path/check. "Use http Node-RED root path" must be disabled. Otherwise the endpoint would be somewhere below Node-REDs httpAdminRoot path (e.g. if Node-RED listens on https://example.nl:1880/node-red, it would be https://example.nl:1880/node-red/check).

FireWizard52 commented 2 years ago

Hello @Caprico85,

Thank you, thank you. That was the issue.

My settings in the Configuration Node, were as follows:

Screenshot_Web_Config Google Home

I had my path set in the path setting, instead of leaving it empty. I had not expected, that a path, like https://example.nl:3001/check would not work.

But okay, you solved it for me.

I have one question left.

As I tried to create two similar projects in Google Actions, because the first one did not work (same issue), I have now two [test] ProjectName services in the Google Home app. One of them I was able to link, the other one (of course), not. Do you know, how I can remove (delete) this useless service. Or will it disappear after a certain time?

Thanks in advance

Caprico85 commented 2 years ago

You can delete your projects in Google Actions.

image

It should be deleted 30 days later ... but days seem to be longer at Google. Still waiting for some of my projects to disappear.

FireWizard52 commented 2 years ago

@Caprico85

Thanks for your quick response. That is the way I deleted the old project. So it is simple, I have to wait 30+ days?

Thank you for your support.

Paul-Reed commented 2 years ago

It took over 2 months for Google to delete my old project...

ckhmer1 commented 2 years ago

Is this problem still present?

FireWizard52 commented 2 years ago

Hello @ckhmer1,

For me is this issue solved. But the old project still exists in Google Home, but this is a Google issue. So for me this issue can be closed.

Regards

Caprico85 commented 2 years ago

Still waiting for my old projects to disappear. Seems they never really get deleted.