home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.61k stars 30.77k forks source link

nVent Senz integration periodically stops working #83274

Closed timjackson closed 3 months ago

timjackson commented 1 year ago

The problem

After upgrades to HA (even minor upgrades), in almost all (or perhaps all?) cases, the nVent Senz integration stops working. The logs show a 500 error when talking to Account Link.

The only solution I am able to find is removing the integration and re-adding it (which includes going via Account Link to re-establish API authorisation). Then it works fine again until the next upgrade.

This has been persisting since at least 2022.6.3 (see forum post) and possibly earlier. The Senz integration was merged in 2022.05.

What version of Home Assistant Core has the issue?

2022.11.5

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

senz

Link to integration documentation on our website

https://www.home-assistant.io/integrations/senz/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2022-12-05 08:27:29.394 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Home Assistant Cloud for senz
File "/usr/src/homeassistant/homeassistant/components/senz/__init__.py", line 73, in async_setup_entry
account = await senz_api.get_account()
File "/usr/local/lib/python3.10/site-packages/aiosenz/api.py", line 35, in get_account
File "/usr/local/lib/python3.10/site-packages/aiosenz/auth.py", line 55, in _request
File "/usr/src/homeassistant/homeassistant/components/senz/api.py", line 24, in get_access_token
aiohttp.client_exceptions.ClientResponseError: 500, message='Internal Server Error', url=URL('https://account-link.nabucasa.com/refresh_token/senz')

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @milanmeu, mind taking a look at this issue as it has been labeled with an integration (senz) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `senz` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Change the title of the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign senz` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


senz documentation senz source (message by IssueLinks)

fredrik-eriksson commented 1 year ago

I'm also seeing this. I didn't associate it with hass upgrades, and I'm pretty sure I've upgraded at times without breaking the senz integration, but I'm almost completely certain that the 2022.12.7 upgrade broke the integration for me.

I also solve it by removing and re-adding the integration when this happens.

timjackson commented 1 year ago

I have no idea if this means anything or is just "luck", but an upgrade I did today from 2023.1 to 2023.2.1 didn't break the integration.

fredrik-eriksson commented 1 year ago

yes, I've also done a few upgrades without the integration breaking after last comment; I'm back at thinking this is either some sort of token refresh that fails or maybe a session timeout of some sort that de-auth the integration...

irata-coder commented 1 year ago

I don't think it's upgrade related either, as I've seen this happen at other times too. However, today I upgraded and I experienced the exact same issue.

I did login to the senz web portal after this error, which shows all 3rd party applications linked to the account. I do see that exactly one month had passed. Last time it happened, I did see the same, so for me it seems to happen after one month. Likewise I fix it by removing the integration and adding again.

The error appears to be related to refreshing the access token. I don't know how to force the integration to refresh it's access token to see if this always triggers the error?

alexanderlindstrom commented 1 year ago

irata-coder is right. It's the access token that expires after one month. Not an update of HA

ajc117 commented 1 year ago

Is there any chance of a fix or workaround that doesn't involve removing and re-adding the integration?

alexanderlindstrom commented 1 year ago

I wonder if this is an issue with HA or with nvent token handling? Strange how they only would give a month long token. If it is indeed nvent issue, perhaps HA could have a worlarpund where it automatically does the renewing process once a month?

Klench commented 1 year ago

I had a working integration before some update ruined it. Is it not supposed to be handled without access token nowadays? I cannot add the integration again. Maybe it is because I no longer have any third party application on my nVent account?

dlidstrom commented 1 year ago

Any news on this? I’m disappointed that there are no workarounds other than removing and adding the integration again. Here’s what I’m seeing in the logs currently:

Logger: homeassistant.config_entries
Source: components/cloud/account_link.py:132 
First occurred: 15 April 2023 at 08:27:17 (3 occurrences) 
Last logged: 19:15:55

Error setting up entry Home Assistant Cloud for senz
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 383, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/usr/src/homeassistant/homeassistant/components/senz/__init__.py", line 73, in async_setup_entry
    account = await senz_api.get_account()
  File "/usr/local/lib/python3.10/site-packages/aiosenz/api.py", line 35, in get_account
    resp = await self.auth._request("get", "Account")
  File "/usr/local/lib/python3.10/site-packages/aiosenz/auth.py", line 55, in _request
    access_token = await self.get_access_token()
  File "/usr/src/homeassistant/homeassistant/components/senz/api.py", line 24, in get_access_token
    await self._oauth_session.async_ensure_token_valid()
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 499, in async_ensure_token_valid
    new_token = await self.implementation.async_refresh_token(self.token)
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 92, in async_refresh_token
    new_token = await self._async_refresh_token(token)
  File "/usr/src/homeassistant/homeassistant/components/cloud/account_link.py", line 132, in _async_refresh_token
    new_token = await account_link.async_fetch_access_token(
  File "/usr/local/lib/python3.10/site-packages/hass_nabucasa/account_link.py", line 121, in async_fetch_access_token
    resp.raise_for_status()
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 1005, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 500, message='Internal Server Error', url=URL('https://account-link.nabucasa.com/refresh_token/senz')

Is there a contact at Nabucasa that can assist, perhaps?

issue-triage-workflows[bot] commented 1 year ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

fredrik-eriksson commented 1 year ago

I saw this issue as late as a ~2 weeks ago, and I see no reason to expect it has somehow solved itself since then.

timjackson commented 1 year ago

Yes it's still an issue

Brkie commented 1 year ago

Also having same issue..

felixhall commented 1 year ago

Same thing here

dlidstrom commented 1 year ago

Yep me too. Although I didn’t bother setting it up again after it failed a couple of months ago.

Klench commented 1 year ago

Those of you that have re-added the integration, did you need to add a third party application to your nVent account to get an access token or should the authentication be handled in another way?

fredrik-eriksson commented 1 year ago

@Klench Just remove the old integration and re-add it according to the instructions, you will be redirected to a login prompt where you enter our nvent Senz credentials and the device will be automatically added; nothing fancy required. This issue is about that you have to repeat the procedure once every blue moon since it stops working after a while.

Klench commented 1 year ago

@Klench Just remove the old integration and re-add it according to the instructions, you will be redirected to a login prompt where you enter our nvent Senz credentials and the device will be automatically added; nothing fancy required. This issue is about that you have to repeat the procedure once every blue moon since it stops working after a while.

Thank you for the response @fredrik-eriksson. However, when I try to add the integration, I am not being redirected to the login prompt but to the window you can see in the figure below.

Skärmavbild 2023-08-06 kl  23 15 40.

lindsand commented 1 year ago

Same problem for me today. First I got this (not related to any HA upgrade):

Logger: homeassistant.components.senz Source: helpers/update_coordinator.py:303 Integration: nVent RAYCHEM SENZ (documentation, issues) First occurred: 11:18:45 (1 occurrences) Last logged: 11:18:45

Error requesting some.email@yyy.xxx data: 500, message='Internal Server Error', url=URL('https://account link.nabucasa.com/refresh_token/senz')

Then I tried to restart the integration, 2 times. No success.

Logger: homeassistant.config_entries Source: config_entries.py:399 First occurred: 13:57:35 (2 occurrences) Last logged: 13:59:27

Error setting up entry Home Assistant Cloud for senz Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 399, in async_setup result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/senz/init.py", line 55, in async_setup_entry account = await senz_api.get_account() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiosenz/api.py", line 35, in get_account resp = await self.auth._request("get", "Account") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiosenz/auth.py", line 55, in _request access_token = await self.get_access_token() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/senz/api.py", line 24, in get_access_token await self._oauth_session.async_ensure_token_valid() File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 502, in async_ensure_token_valid new_token = await self.implementation.async_refresh_token(self.token) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 91, in async_refresh_token new_token = await self._async_refresh_token(token) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/cloud/account_link.py", line 140, in _async_refresh_token new_token = await account_link.async_fetch_access_token( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/hass_nabucasa/account_link.py", line 121, in async_fetch_access_token resp.raise_for_status() File "/usr/local/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 1005, in raise_for_status raise ClientResponseError( aiohttp.client_exceptions.ClientResponseError: 500, message='Internal Server Error', url=URL('https://account-link.nabucasa.com/refresh_token/senz')

After that I uninstalled and reinstalled the integration (including authorizing Home Assistant to access senz Cloud), it started working after that.

I created my senz-account 13.9.2023 and set up my first thermostat 21.9.2023. And the last one 8.10 (Sunday) so 3 1/2 weeks ago.

https://id.senzthermostat.nvent.com/Grants# image

irata-coder commented 1 year ago

Regardless of the underlying issue.

link.nabucasa.com should not be throwing an internal server error, as that suggests an uncaught exception which is masking the real issue.

lindsand commented 1 year ago

Here it's said that Refresh tokens last about 15-30 days and should be renewed before expiring:

https://api.senzthermostat.nvent.com/#oauth2

Where/when and how is that handled? I tried to read the code here but got lost...

https://github.com/home-assistant/core/tree/dev/homeassistant/components/senz

fredrik-eriksson commented 9 months ago

Just a note that the integration stopped working today, but when I tried to re-add it as usual the link.nabucasa.com callback fails.

I can log into nvent and click the "Yes, Allow" button to allow homeassistant access; but then I'm greeted with this message from the account-link.nabucasa.com callback: Screenshot 2024-01-22 at 20-46-22 Nabu Casa Account Link

lindsand commented 9 months ago

Same for me, there have been access problems the total day from HA and restart didn't help. Looks like some limit for the API has been reached, the app works as it should.

rasmus-wi commented 9 months ago

Yup, happens to me too. Senz document their rate limits pretty clearly in their API documentation, hopefully they can be persuaded to increase those limits...

robanswe commented 9 months ago

Just a note that the integration stopped working today, but when I tried to re-add it as usual the link.nabucasa.com callback fails.

I can log into nvent and click the "Yes, Allow" button to allow homeassistant access; but then I'm greeted with this message from the account-link.nabucasa.com callback: Screenshot 2024-01-22 at 20-46-22 Nabu Casa Account Link

I can confirm that I have the same exact problem after latest update.

Ladida1 commented 9 months ago

I have the same issue since yesterday.

bsdzip commented 9 months ago

Same here, been working great before (except the recurring need for re-install).

stefanes commented 9 months ago

Went ahead and create a new separate issue, #108782, for the new problem (with the hope it gets some attention).

issue-triage-workflows[bot] commented 6 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

timjackson commented 6 months ago

For me, this problem appears to have disappeared, with the nVent integration being stable recently for me. I'm inclined to close unless someone else confirms this is NOT the case.

issue-triage-workflows[bot] commented 3 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.