klejejs / ha-thermia-heat-pump-integration

Thermia Heat Pump Integration for Home Assistant
GNU General Public License v3.0
30 stars 7 forks source link

Integration stops updating values #33

Closed KlasHolger closed 1 year ago

KlasHolger commented 1 year ago

Thank you for an great integration!

Have been testing the integration for a while but running into problems. After some time (6 - 24 hours), the integration stops updating values. If I restart HA it starts updating again

HA Home Assistant 2022.12.1 Supervisor 2022.11.2 Operating System 9.3 Frontend-version: 20221208.0 - latest

Heat pump Outside Thermia iTec 9 Inner section Total +60 Thermia Online

Section of the log 2022-12-09 20:56:10.435 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration thermia which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant 2022-12-09 20:56:10.436 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant 2022-12-09 20:57:13.160 WARNING (MainThread) [homeassistant.bootstrap] Waiting on integrations to complete setup: thermia 2022-12-10 00:43:35.777 WARNING (MainThread) [homeassistant.helpers.state] Integration sensor does not support reproduce state 2022-12-10 00:43:35.783 WARNING (MainThread) [homeassistant.components.water_heater.reproduce_state] Invalid state specified for water_heater.klas_jansson: AUTO 2022-12-10 21:58:13.821 WARNING (SyncWorker_3) [ThermiaOnlineAPI.api.ThermiaAPI] Error authenticating with Azure auth.'access_token' 2022-12-10 21:58:13.833 ERROR (MainThread) [custom_components.thermia] Error fetching thermia data: local variable 'result' referenced before assignment 2022-12-10 21:58:23.766 WARNING (SyncWorker_0) [ThermiaOnlineAPI.api.ThermiaAPI] Error authenticating with Azure auth.'access_token' 2022-12-10 21:58:33.755 WARNING (SyncWorker_2) [ThermiaOnlineAPI.api.ThermiaAPI] Error authenticating with Azure auth.'access_token' 2022-12-10 21:58:43.763 WARNING (SyncWorker_0) [ThermiaOnlineAPI.api.ThermiaAPI] Error authenticating with Azure auth.'access_token' 2022-12-10 21:58:53.766 WARNING (SyncWorker_4) [ThermiaOnlineAPI.api.ThermiaAPI] Error authenticating with Azure auth.'access_token' 2022-12-10 21:59:03.769 WARNING (SyncWorker_2) [ThermiaOnlineAPI.api.ThermiaAPI] Error authenticating with Azure auth.'access_token' 2022-12-10 21:59:13.809 WARNING (SyncWorker_0) [ThermiaOnlineAPI.api.ThermiaAPI] Error authenticating with Azure auth.'access_token' 2022-12-10 21:59:23.808 WARNING (SyncWorker_3) [ThermiaOnlineAPI.api.ThermiaAPI] Error authenticating with Azure auth.'access_token' 2022-12-10 21:59:33.755 WARNING (SyncWorker_4) [ThermiaOnlineAPI.api.ThermiaAPI] Error authenticating with Azure auth.'access_token' And so on.

Please if I can get some help to solve the problem.

Thanks! dump

effinamon commented 1 year ago

I see the same behaviour — reloading the integration resolves it, but the error returns.

It looks like it’s hitting the api every 10s

2022-12-15 04:37:23.785 WARNING (SyncWorker_19) [ThermiaOnlineAPI.api.ThermiaAPI] Error authenticating with Azure auth.'access_token' 2022-12-15 04:37:33.554 WARNING (SyncWorker_4) [ThermiaOnlineAPI.api.ThermiaAPI] Error authenticating with Azure auth.'access_token' 2022-12-15 04:37:43.547 WARNING (SyncWorker_9) [ThermiaOnlineAPI.api.ThermiaAPI] Error authenticating with Azure auth.'access_token'

silvar05123 commented 1 year ago

Hey,

i have also the same error any updates for this error?

best regards

jerrit

klejejs commented 1 year ago

I have updated the underlying Python API and decreased the auth refresh token validity time in an attempt to fix this issue. I have also improved the logging, so in case this fix does not work, there is a clearer error message logged in Home Assistant.

effinamon commented 1 year ago

Great, will report back. Thanks for the update.

fclauson commented 1 year ago

I note these errors started again on Christmas eve it seems that http://thermia-auth-api.azurewebsites.net/api/v1/Jwt/login no longer resolves to am IP address

klejejs commented 1 year ago

@fclauson What is the error exactly? Could you please send it to me? From my experience, if the issue is really with not being able to resolve the IP address for the URL, it sounds like a DNS issue on your machine rather than an issue with the integration.

KlasHolger commented 1 year ago

I try to look up . see below Is this what you are asking for?

Microsoft Windows [Version 10.0.19044.2364] (c) Microsoft Corporation. Med ensamrätt.

C:\Users\klas>nslookup http://thermia-auth-api.azurewebsites.net/api/v1/Jwt/login Server: dns.google Address: 8.8.8.8

*** dns.google can't find http://thermia-auth-api.azurewebsites.net/api/v1/Jwt/login: Non-existent domain

C:\Users\klas>

klejejs commented 1 year ago

@KlasHolger @fclauson Just realized, this is the login URL for the old auth system that was replaced with Azure B2C login. It used to work before alongside the new login flow, but it seems Thermia has finally removed it entirely.

In any case, it should not be used unless Azure Auth is unsuccessful. Do you have the latest version of the integration? If yes and you get an error with this URL, you should also have an error Error authenticating with Azure auth... with additional details. Do you see it?

If you do not have the latest integration version, please update it. Furthermore, I will remove the old auth flow from the underlying API now that it does not work anymore.

KlasHolger commented 1 year ago

Sorry! I was perhaps a bit hasty. I tried the link in the previous post. I will check my setup and get back to you later.

fclauson commented 1 year ago

Hi I use a google script hack of your code It seems Thermia shut off the old method on Christmas Eve - not a nice Santa present

I need to re write my code to use the azure method

something to do over the Christmas break unless the just moved the URL to something different

fclauson commented 1 year ago

@klejejs if I do a https://online.thermia.se/api/configuration I get "apiBaseUrl": "https://online-classic-serviceapi.azurewebsites.net", "authApiBaseUrl": "https://thermia-auth-api.azurewebsites.net",

I was hoping one of these was a replacement for the old
http://thermia-auth-api.azurewebsites.net/api/v1/Jwt/login

and hence I could use the more simple login process  but this does not work 

looking at your own code it seems that if it had to resort to classic authentication it would also fail

Is there anyway of finding out where the old JWT/LOGIN API has gone or have they really turned it off 

as mentioned I emulate you code on Google Apps and on Excel - and I really do not want to have to code up the more complicated Azure login  
klejejs commented 1 year ago

@fclauson I suggest you send me an email with further questions or create an issue here and I'd be happy to advise you and help, but your problems are totally unrelated to this issue and I don't want to spam other people with this problem. 😉

Regarding the authentication URL, I believe it is outdated, not working anymore, and will not in the future as Thermia has been moving away from it since September. Unfortunately, I do not see any other way for you rather than rewriting your code to work with complex Azure auth flow.😞 I'd personally suggest you try using the Python API directly as it will be much easier and has everything implemented, but I am not 100% aware of your setup and don't know if Python code can be used in your case.

effinamon commented 1 year ago

Had the issue pop up again. Got this error:

This error originated from a custom integration.

Logger: ThermiaOnlineAPI.api.ThermiaAPI Source: custom_components/thermia/init.py:91 Integration: Thermia Heat Pump (documentation, issues) First occurred: 13:20:39 (7516 occurrences) Last logged: 23:47:04

Error authenticating with Azure auth.Reauthentication request failed with previous refresh token. Status: 400, Response: {"error":"invalid_grant","error_description":"AADB2C90080: The provided grant has expired. Please re-authenticate and try again. Current time: 1672267604, Grant issued time: 1672226435, Grant expiration time: 1672226332\r\nCorrelation ID: ef511694-f65e-4717-8b0b-fd20e842c7e3\r\nTimestamp: 2022-12-28 22:46:44Z\r\n"} Reauthentication request failed with previous refresh token. Status: 400, Response: {"error":"invalid_grant","error_description":"AADB2C90080: The provided grant has expired. Please re-authenticate and try again. Current time: 1672267614, Grant issued time: 1672226435, Grant expiration time: 1672226332\r\nCorrelation ID: 88c98772-dd48-4750-ae2c-6fc94da5a2a2\r\nTimestamp: 2022-12-28 22:46:54Z\r\n"} Error authenticating with Azure auth.Reauthentication request failed with previous refresh token. Status: 400, Response: {"error":"invalid_grant","error_description":"AADB2C90080: The provided grant has expired. Please re-authenticate and try again. Current time: 1672267614, Grant issued time: 1672226435, Grant expiration time: 1672226332\r\nCorrelation ID: 88c98772-dd48-4750-ae2c-6fc94da5a2a2\r\nTimestamp: 2022-12-28 22:46:54Z\r\n"} Reauthentication request failed with previous refresh token. Status: 400, Response: {"error":"invalid_grant","error_description":"AADB2C90080: The provided grant has expired. Please re-authenticate and try again. Current time: 1672267624, Grant issued time: 1672226435, Grant expiration time: 1672226332\r\nCorrelation ID: aff93943-53e6-4c4d-b176-c5588f7b5d4c\r\nTimestamp: 2022-12-28 22:47:04Z\r\n"} Error authenticating with Azure auth.Reauthentication request failed with previous refresh token. Status: 400, Response: {"error":"invalid_grant","error_description":"AADB2C90080: The provided grant has expired. Please re-authenticate and try again. Current time: 1672267624, Grant issued time: 1672226435, Grant expiration time: 1672226332\r\nCorrelation ID: aff93943-53e6-4c4d-b176-c5588f7b5d4c\r\nTimestamp: 2022-12-28 22:47:04Z\r\n"}

klejejs commented 1 year ago

@effinamon Thanks for the input! It seems we cannot trust either Thermia to keep the refresh token valid or Home Assistant to revalidate every 12h so I have added the changes to try fetching a new token if the refresh token is invalid. Please install the newly released 2.16 version and let's see if the issue persists.

effinamon commented 1 year ago

Cool, I’ve updated now and will report back.

effinamon commented 1 year ago

Integration is still running, but found this in the log:

This error originated from a custom integration.

Logger: custom_components.thermia
Source: helpers/update_coordinator.py:168
Integration: Thermia Heat Pump (documentation, issues)
First occurred: 18:46:30 (1 occurrences)
Last logged: 18:46:30

Error fetching thermia data: HTTPSConnectionPool(host='online-classic-serviceapi.azurewebsites.net', port=443): Max retries exceeded with url: /api/v1/installationstatus/[installationID]/status (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0xffff867727d0>: Failed to establish a new connection: [Errno -3] Try again'))

(I removed the installation ID)

I'm guessing this is part of the fix?

klejejs commented 1 year ago

@effinamon Huh! Your Home Assistant instance is kinda special 😄. I am not sure why it does not want to connect to Thermia servers properly. I am glad the integration is running but I found some fixes for this in Google which I will try. Thanks for reporting!

Just out of curiosity - do you have some "special" Home Assistant setup like additional DNS or Proxy or something like that? I am just wondering what the core issue for this might be. They are all valid errors that make sense, but it is not clear why they appear for you, but not for e.g. me.

effinamon commented 1 year ago

No, nothing special I can think of, but you're right it seems more like a connection issue. Could try setting up SmokePing or similar to see what's what.

Still getting a few like these:

This error originated from a custom integration.

Logger: custom_components.thermia
Source: helpers/update_coordinator.py:168
Integration: Thermia Heat Pump (documentation, issues)
First occurred: 05:07:35 (2 occurrences)
Last logged: 13:42:42

Error fetching thermia data: HTTPSConnectionPool(host='online-classic-serviceapi.azurewebsites.net', port=443): Max retries exceeded with url: /api/v1/Registers/Installations/[installationID]/Groups/REG_GROUP_TEMPERATURES (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0xffff4eac08e0>: Failed to establish a new connection: [Errno -3] Try again'))
Error fetching thermia data: HTTPSConnectionPool(host='online-classic-serviceapi.azurewebsites.net', port=443): Max retries exceeded with url: /api/v1/installations/[installationID] (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0xffff561bc3d0>, 'Connection to online-classic-serviceapi.azurewebsites.net timed out. (connect timeout=None)'))

However, it's still running which is more important.

klejejs commented 1 year ago

I have released a new version 2.17 that introduces HTTP sessions in an attempt to fix the issue. I have also updated some token fetching logic which could also help. Please install the new version and report back with any issues.

KlasHolger commented 1 year ago

I’ve updated now .

effinamon commented 1 year ago

I applied the update right when it was released and haven't had any issues or errors in the log since.

KlasHolger commented 1 year ago

I also run 2.17. No errors so far. Thanks for all the your work on the integration.

klejejs commented 1 year ago

Good to hear! I am closing this issue then and if there are any problems in the future, please open a new issue.