nikkow / node-red-contrib-tahoma

Node-RED module to control a Somfy Tahoma box (Roller shutters...). Used for home automation flows.
Apache License 2.0
19 stars 11 forks source link

How to link/login to tahoma #27

Closed ferdoo closed 4 years ago

ferdoo commented 4 years ago

Hi, i try to control my tahoma window shutter from node red. If i try to log in to my tahoma from the config node with button "Link node-red to tahoma" the login fail. I tried to change login data in sample flow and import it but I can't select the device next. Can someone help me successfully set up a connection to tahoma. Thanks.

nikkow commented 4 years ago

Hi @ferdoo,

Have you followed the guide to create the app on the Somfy Open API platform? Do you see any specific output in the node-red logs?

Raphidev commented 4 years ago

Hello, same problem. Got error message from Somfy url after enter credentials. Perhaps a callback url problem ? (http://127.0.0.1:1880/somfy/callback), Http server contrib needed ?

gvdhoven commented 4 years ago

@nikkow same issue here; fresh install; callback URL works if i do view-source.

Somfy page shows error: image

ferdoo commented 4 years ago

Hi, @nikkow Yes i have followed the guide and chcecked steps more times. Nothing in node-red logs. There must be some authentication problem. By login i become same error message as @Webunity . I noticed that when I use the Internet Explorer I can't see this tahoma node. if I use for example chrome then this tahoma node is visible. I dont understand why ? And I still don't know where to take io: // path / to / my / device?

ferdoo commented 4 years ago

Callback URL: enter the URL of your node-red installation, followed by the path /somfy/callback (e.g. if installed locally: http://127.0.0.1:1880/somfy/callback).

should there not be an external ip address instead of the ip address of the node red installation?

gvdhoven commented 4 years ago

Off course your callback URL should be externally reachable; it is the URL where Somfy sends your credentials towards. In my case my external URL is reachable, but Somfy is giving the auth error. I even tried to replicate the callback using the steps in the openapi-docs so i think it is not an issue on this node's end.

ferdoo commented 4 years ago

@Webunity There can be no problem that the external ip is ipv6 ? Some internet providers use ipv6.

ferdoo commented 4 years ago

Off course your callback URL should be externally reachable; it is the URL where Somfy sends your credentials towards. In my case my external URL is reachable, but Somfy is giving the auth error. I even tried to replicate the callback using the steps in the openapi-docs so i think it is not an issue on this node's end.

They the port 1880 must be forwarded in router ?

nikkow commented 4 years ago

Callback URL: enter the URL of your node-red installation, followed by the path /somfy/callback (e.g. if installed locally: http://127.0.0.1:1880/somfy/callback).

should there not be an external ip address instead of the ip address of the node red installation?

Not necessarily. Somfy will not send anything directly to this address (no server-to-server request), but will redirect your browser to your callback, with a token as a query parameter. I will perform a fresh install on a new machine right away and let you know if I can reproduce.

nikkow commented 4 years ago

@ferdoo can you please try the following?

  1. Login to Somfy Open API developer platform (https://developer.somfy.com/)
  2. Try executing one of the example calls (e.g. https://developer.somfy.com/somfy-open-api/apis/get/site)

You will need to click on the "OAuth 2.0 Set..." button that will open a popup prompting for your credentials.

I have just tried this issue and cannot login, I receive an access token negociation error systematically.

Update: I have sent an email to Somfy Developer Support. I am now waiting for their feedback.

ferdoo commented 4 years ago

@ferdoo can you please try the following?

  1. Login to Somfy Open API developer platform (https://developer.somfy.com/)
  2. Try executing one of the example calls (e.g. https://developer.somfy.com/somfy-open-api/apis/get/site)

You will need to click on the "OAuth 2.0 Set..." button that will open a popup prompting for your credentials.

I have just tried this issue and cannot login, I receive an access token negociation error systematically.

Update: I have sent an email to Somfy Developer Support. I am now waiting for their feedback.

I becomme this : Error: access_token negotiation failure

nikkow commented 4 years ago

OK, we face the same issue. I have reported this to the Somfy Devleopment Team, there is not much I can do on my end. We'll have to wait for their answer :)

ferdoo commented 4 years ago

OK, we face the same issue. I have reported this to the Somfy Devleopment Team, there is not much I can do on my end. We'll have to wait for their answer :)

thank you, we moved a little :) please let know if you have some info

nikkow commented 4 years ago

I will update this issue as soon as I receive a feedback 🙂

miro0278 commented 4 years ago

I have the same issue like ferdoo

gvdhoven commented 4 years ago

Thank you @nikkow for your investigations on this :) but, if i click the button "Link node-red to tahoma" i don't even get the login box. I do get a Somfy error (show above) but no way for me to login.

frankis78 commented 4 years ago

I also face the same issue. Hope Somfy will fix it:)

frankis78 commented 4 years ago

I was been able to workaround it by putting different Callback URL (generated from https://webhook.site/) in Somfy developer app settings. Then I get back to my Node Red installation and oauth authentication ran without any problems and gave me the correct access & refresh tokens. Communication with Tahoma Hub is working now. I think something is wrong with callback URL set on the somfy settings. With the right callback url where my node-red is running (http://node-red-ip:1880/somfy/callback) it was giving me {"error":"redirect_uri_mismatch","error_description":"The redirect URI provided does not match registered URI(s)."}. But as soon as I set different URL at the somfy website, I was been able to authenticate from node red.

gvdhoven commented 4 years ago

Any updates because this is blocking my integration...

nikkow commented 4 years ago

I haven't heard back from Somfy since my last e-mail. I just tried to login through their documentation samples and it seems to be back online. Can you please try the procedure mentioned in this comment?

Regarding the callback issue, my setup skips the /somfy/callback bit and manages to login just fine. I tried to reproduce and created a new node-red instance on the LAN (using its local IP as the host and the default port). When creating the app on Somfy portal, I just set http://192.168.x.y:1880/ as the callback URL, wait a few minutes for it to be activated (~10 min. after seeing the "Approved" badge). I then setup the node using the API key/secret provided and it logged just fine.

@frankis78 can you please provide more details about your config (without any private/sensitive info) to better understand the issue you are facing?

Thanks

Raphidev commented 4 years ago

I just checked out the workaround from #frankis78, with no success. As #nikkow says, try to remove /somfy/callback in url didn't work. There is still a issue with de somfy server. I have read that somfy API isn't available in all countries, so check country in your somfy dev account. In my case it was set by default in afghanistan. I managed to change that.

nikkow commented 4 years ago

Hi @Raphidev, did it work after changing the default country?

frankis78 commented 4 years ago

When i first experienced this issue, then i had the local ip in the node-red settings. And i couldnt refresh the tokens. But after i changed to a different external webhook, i was able to get the correct tokens in node-red.

2020-05-06_1911 2020-05-06_1909

I have now tried to set back the local Ip adress in the app settings of somfy, to see it will still work.

risa commented 4 years ago

Hi, I am also trying hard to generate the access_token but without success.

I have even tried to generate the access_code using the Somfy description of the OAuth2 protocol, but event then I did not succeed.

I have tried to change the country as @Raphidev suggested but without success.

I can authorise using the APIs Documentation and test the calls just fine. Using this I can also extract the access token from the Bearer header from the CURL representation.

@nikkow is it possible to inject the access_token straight into your module bypassing the OAuth2 authorisation flow? It seems that there must be something broken on the Somfy side with the application approvals or something. With direct injection, it would be possible to start working now as a temporary hack.

Thanks!

tomy-d commented 4 years ago

Hi, I do have the same issue. One question according the installation: When you are saying that I have to enter the path for the local installation :e.g. http://127.0.0.1:1880/somfy/callback running node ed o a raspy ... is it important where the node is installed exactly on my raspy? I mean do I have to look for in which path nedered and the somfy node has been installed???

nikkow commented 4 years ago

Hi @risa,

It is actually not possible to inject the token directly from the config node, I will create a task to add those fields. It won't hurt to at least make them editable. We also have to keep in mind that the access token is short-lived. During my tests, it was only valid for an hour.

@tomy-d: actually the only elements that matter are the IP and port on which your node-red instance is installed. The /somfy/callback bit is a route created by the node itself.

Raphidev commented 4 years ago

Still malfunction. I tried with HomeAssit and it works, so i think it is not a Somfy related issue.

hmwelsch commented 4 years ago

Hi, I have worked on this again today as well. I have tried to build the calls outside of Node-Red and get persistently the same results too. I have now also tried to contact Somfy (Germany) and hope for some response from there.

tomy-d commented 4 years ago

@hmwelsch have tried several times to contact somfy support...they never replied...really poor service!

jaerc commented 4 years ago

Hi nikkow I have the same error message if I try the Link Node-Red to Tahoma button.

The link on the page with the error message looks like this: https://accounts.somfy.com/oauth/oauth/v2/auth?response_type=code&client_id=xYW2w32OQBSYxGFFGCYvBUQE8ME1HNt4MtVdr_HBucX5tp4jcmUwJUN9M2vwByN5P1BO0ULVvHh8r9Hb1UJrO8JT&redirect_uri=http://myexternalnasurl:1880/somfy/callback&state=setup&grant_type=authorization_code

As callback url I did configure: http://myexternalnasurl:1880/somfy/callback

Oauth2 is authenticated on the somfy page and if I try it out the response is OK. So this authentication works on my site, but I still get the same error message.

Is there anything else I can try?

nikkow commented 4 years ago

Hi @jaerc,

There seems to be a bug when registering callbacks on Somfy's developer portal (see #39). The only workaround for now is to contact them, so they can manually fix the affected callback in their database, hoping that they'll fix their workflow quickly.

nikkow commented 4 years ago

Since they were several login-related issues discussed in this thread, I'll keep #39 open to discuss the callback issue. The other login problems were fixed in the latest releases.

Thanks!