Home Connect: alpha testers wanted

I hope someone can help me here, I’ve been trying it since hours to get it to work… My authorization fails when I click on the “Link Home Connect account” link in HA.

I’m getting this error message:
{
“error”: “unauthorized_client”,
“error_description”: “client or redirection URI not authorized”,
“state”: “M0mHJobp7FPs4Xv5vyoOwh0vnu5n0j”
}

the duckdns URL is working as I can access it over https://xxx.duckdns.org:8123 and it is showing up as secure. only when I access it local with https://hassio.local:8123 it is showing as non secure. Don’t know if this is normal…

on the homeconnect site I put in my site: https://xxx.duckdns.org:8123/api/homeconnect
xxx and put the Client ID and Client Secret into the configuration.yaml together with the website https://xxx.duckdns.org:8123.

what could be possibly wrong here?

What do you mean by “together with the website https://xxx.duckdns.org:8123”?

Your configuration.yaml should look like this:

http:
  base_url: https://xxx.duckdns.org:8123
  # ...

homeconnect:
  client_id: # ...
  client_secret: # ...

@DavidMStraub Sorry for not being precise enough. I’ve meant that I put the https://xxx.duckdns.org:8123 into my configuration.yaml (as base_url)

it looks a bit different than yours:

http:
  base_url: https://xxx.duckdns.org:8123
  ssl_certificate: /ssl/fullchain.pem
  ssl_key: /ssl/privkey.pem

if I leave the 2 sll lines, then ssl won’t work.

Sure, by # ... I meant that you might have additional config there.

This all looks fine so I don’t know why it doesn’t work. So all I can say is please double-check all your setting, also on the Home Connect side.

  • did you register your application as “Authorization Code Grant Flow”?
  • have you checked the “Enabled” box in your app’s settings?

Managed to get the connection to work now. But after reboot I get errors. And it is looking for Python3.7 which is not installed (running Docker on Synology).
Error during setup of component homeconnect
Traceback (most recent call last):
File “/usr/src/app/homeassistant/setup.py”, line 156, in _async_setup_component
component.setup, hass, processed_config) # type: ignore
File “/usr/local/lib/python3.7/concurrent/futures/thread.py”, line 57, in run
result = self.fn(*self.args, **self.kwargs)
File “/config/custom_components/homeconnect/init.py”, line 49, in setup
from homeconnect import HomeConnect
File “/usr/local/lib/python3.7/site-packages/homeconnect/init.py”, line 1, in
from .api import HomeConnect
File “/usr/local/lib/python3.7/site-packages/homeconnect/api.py”, line 1, in
from requests_oauthlib import OAuth2Session
File “/usr/local/lib/python3.7/site-packages/requests_oauthlib/init.py”, line 3, in
from .oauth1_auth import OAuth1
File “/usr/local/lib/python3.7/site-packages/requests_oauthlib/oauth1_auth.py”, line 10, in
from requests.utils import to_native_string
File “/usr/local/lib/python3.7/site-packages/requests/utils.py”, line 24, in
from . import certs
File “/usr/local/lib/python3.7/site-packages/requests/init.py”, line 114, in
from .models import Request, Response, PreparedRequest
File “/usr/local/lib/python3.7/site-packages/requests/models.py”, line 28, in
from .auth import HTTPBasicAuth
File “/usr/local/lib/python3.7/site-packages/requests/auth.py”, line 22, in
from .utils import parse_dict_header
ImportError: cannot import name ‘parse_dict_header’ from ‘requests.utils’ (/usr/local/lib/python3.7/site-packages/requests/utils.py)

I already commented on that: Home Connect: alpha testers wanted

Sorry missed the last line which is new:

homeconnect.api.HomeConnectError: {‘key’: ‘invalid_token’, ‘description’: ‘The access token is revoked’}

OK, please delete .homeconnect_token_cache.json and restart HA

Wohoo it works!! Thanks David!

It is working now for me and I don’t even know the reason, because I haven’t changed anything. :slight_smile: I think there was just an issue with the authorization server there…

Thanks for your help and your great plugin!

1 Like

Great component! However, my connection to the backend seems to be lost silently after about a day. If I restart Home Assistant, everything is fine again. For about a day. :slight_smile:
What can I do?

There is nothing in the home assistant log about this, apart from Unexpected value for HomeConnect door state: {} which I get at startup, and I guess is unrelated since it works for a while.

Interesting, this probably means that the token refresh fails since tokens have a lifetime of 24h. This is supposed to be taken care of automatically by the requests_oauthlib library and in my case works. Does anybody else have this problem? Can you check if the homeconnect-token-cache file appears in your HA config dir when you log in?

Yes, I have a .homeconnect-token-cache file. It looks like this:

{
  "id_token": "<token>",
  "access_token": "<token>",
  "expires_in": 86400,
  "scope": [ <long list> ],
  "refresh_token": "<token>",
  "token_type": "Bearer",
  "expires_at": 1563826443.0318155
}

The expires_at is already passed by more than a day now. It reads 2019-07-22 20:14 UTC, and right now we have 2019-07-23 21:39 UTC. The fil was last touched at 2019-07-21 20:14 UTC. HA was restarted about 2019-07-21 11:31 UTC.
I run the latest and greatest HA in a Docker.

Is there anything I can do to further debug this?

Hi,

you could further debug it without using HA by directly using requests_oauthlib. I think it should be

from requests_oauthlib import OAuth2Session
TOKEN_URI = 'https://api.home-connect.com/security/oauth/token'
refresh_kwargs = {
            'client_id': <client_id>,
            'client_secret': <client_secret>
        }
oauth = OAuth2Session(<client_id>
                      token=token,
                      auto_refresh_url=TOKEN_URI,
                      auto_refresh_kwargs=refresh_kwargs)

where token is the content of the JSON file loaded as a dictionary.

The source code corresponding to that in the homeconnect library is here.

Hi

I thought I was coming back here to tell you that lack of time, pour knowledge of OAuth and Python made me not be able to debug this much further. But, it seems to work now! I don’t know if it is related to me updating Home Assistant to 0.96.5 or fiddling with Home Connect, but it seems to be working now for at least four days without restarting HA…

I had the problem for many months and tried tweaking both Home Connect and Home Assistant before without success.

Oh, well. Right now I’m happy. :slight_smile:

I read thru the thread but could not really find out if there is a sensor which shows the current status. Like the openHAB. https://community.openhab.org/t/home-connect-addon-looking-for-beta-testers/49702 Shows the operation state but it does not show this as a sensor in HA.

Just added the component … if you run into problems with unauthorized_client errors, check the URL you were meant to click on. If it has %3A443 (or likewise %3A8123) in there, update the redirect_url at the developers site accordingly to state https://hass.example.org:443/api/homeconnect.

@DavidMStraub nice work, seems to give a lot of entities to look at tomorrow.

@DavidMStraub This component worked fine for a while and all of a sudden it would not start anymore. I deleted the token cache file and re-ran the authorisation. Now i get this error, only get it to work again if i make a new application in the DEV website of homeconnect. But after one reboot that also gives this error.

Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/homeconnect/__init__.py", line 72, in setup
    hass.data[DOMAIN]['devices'] = get_devices(hc)
  File "/config/custom_components/homeconnect/__init__.py", line 129, in get_devices
    appl = retry(hc.get_appliances, times=20, sleep=0.1)
  File "/config/custom_components/homeconnect/__init__.py", line 120, in retry
    return f()
  File "/usr/local/lib/python3.7/site-packages/homeconnect/api.py", line 146, in get_appliances
    data = self.get(ENDPOINT_APPLIANCES)
  File "/usr/local/lib/python3.7/site-packages/homeconnect/api.py", line 109, in get
    raise HomeConnectError(res['error'])
homeconnect.api.HomeConnectError: {'key': 'invalid_token', 'description': 'The access token is malformed'} ```

I was just looking to set this up and then noticed that their App is also spitting out all sorts of errors - can you use the App itself?

I cannot login to their app, shows a ‘no connection to the server’ error, ‘the backend server is currently not available’ or it spits out a general 503 application error. Even the password reset link was not working earlier this morning, but seems to be now… but unable to login after resetting the password.

I think Bosch/Home Connect might be having some general problems.

I have a dishwasher from Bosh (SBV88TX36E/38) and must say that your plugin was very easy to install and runs without any problems. Thanks very much for your good work.

A small bug (i think it is a bug?) I have found:
Sometimes (i think after a restart of Hass.io the sensors are all not available. Then when I restart one or two times everything is back). I also think there is nothing really much in the error log. If I have more info, I let you know.

Thanks for your work!
Gilbert