Home Connect: alpha testers wanted

you’re welcome! Looking forward to your simplified integration. :slight_smile:

I think this might be an even easier implementation for the device “Homey” (which is also some kind of HA). This is done directly by the manufacturer Bosch-Siemens, so they might have some other tricks for the integration:

That sound great, I’d really like to try this plugin but I don’t want do go through the hassle of installing custom certificates.

Unfortunately, I didn’t find a Python library supporting the Device Flow, since it’s a very new OAuth feature. There is an issue on this in oauthlib. Until this is implemented, I’m afraid this cannot be used (I can’t write a client for this from scratch).

that’s a pity, there is no easier integration possible in HA :frowning:

Trying to get this to work but gett the following error while starting up HA:

‘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 have registered and have edited configuration.yaml with Client_ID and Client_Secret

Running HA 0.95.4 on Docker

Any ideas

I sometimes get this error, too, and it doesn’t make any sense to me as the file in question does contain that name. I have no idea so far what is causing it. But usually when I restart HA the problem is gone. Sorry, not a very good solution…

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.