bosch-thermostat / home-assistant-bosch-custom-component

HA custom component for Bosch thermostats
Apache License 2.0
213 stars 44 forks source link

Integration stops working after few hours #404

Open mcervar opened 4 months ago

mcervar commented 4 months ago

First of all, this new version is way faster when updating thermostats, really good job! For some reason after > 6h, integration simply stops working, everything becomes unavailable, if I restart the integration it again works perfectly for few hours and then same problem occurs. Tried completely uninstalling integration and repo, and then reinstalling it from scratch, didnt help.

image

Bosch component version is v0.25.1

Debug SCAN doesnt provided anything, it only say nothing is available (more information can be seen in debug logs attached)

bosch_HA_debug_log.txt

Everything works in this log output until around ~ 01:01:00, after that time in this example, most of the requests are getting null response, but the wierd thing is that some request got proper reply like current temperatures of the thermostats.

Pommes2910 commented 4 months ago

same here

pszafer commented 4 months ago

Disable most sensor and leave only one climate entity enabled. Might be too many requests to bosch servers and you got locked temporarily.

mcervar commented 4 months ago

khmm, but if they lock me out, then it shouldn't work immediately if I restart the integration. From the sensors I only use battery status for each thermostat which is really important to me, this shouldnt be a problem.

Even from the logs its visible after the problem occurs, some of the requests like current temperature and set temperature is succesfully fetched, but device or entity becomes unavailable for some reason

pszafer commented 4 months ago

Do it just for testing so we could try to find out why there is no response from server.

mcervar commented 4 months ago

Found what the problem is in the logs today, integration (homeconnect sub lib, sseclient file ) implements oauth for auth towards bosch cloud api, token after X hours expires which causes communication to stop working.

I suggest using refresh token if possible, and if refresh token is to be expired, then new refresh token should be also requested. It would be good to have try catch exceptions on all api calls towards bosch cloud or at least on important functions (not crucial but long term good to have) if not already implemented. :D

`Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/homeconnect/sseclient.py", line 81, in next next_chunk = next(self.resp_iterator) ^^^^^^^^^^^^^^^^^^^^^^^^ StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/homeconnect/api.py", line 168, in _listen for event in sse: File "/usr/local/lib/python3.12/site-packages/homeconnect/sseclient.py", line 91, in next self._connect() File "/usr/local/lib/python3.12/site-packages/homeconnect/sseclient.py", line 56, in _connect self.resp = requester.get(self.url, stream=True, self.requests_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 602, in get return self.request("GET", url, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/requests_oauthlib/oauth2_session.py", line 483, in request url, headers, data = self._client.add_token( ^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 217, in add_token raise TokenExpiredError() oauthlib.oauth2.rfc6749.errors.TokenExpiredError: (token_expired) `

home-assistant_2024-04-27T19-07-06.159Z.log

pszafer commented 4 months ago

You talking about different integration. It's not homeconnect integration .

mcervar commented 4 months ago

ohhh, you are right, my bad, I thought filter was applied but somehow that log message was caught by it. still nothing what can point out the problem in the logs, but I noticed that last 7 days it always stops working around 1am, earliest 00:35 am, latest around 01:10 am. I already checked my automations and nothing is triggered at that time.

image

Does integration maybe trigger something at that time? Maybe it tries to fetch energy metrics around 1am and something goes wrong there XD

pszafer commented 4 months ago

Can you try to turn on debug log of the integration and library in the evening and provide what is happening in the night. As it's Easycontrol it just download last day at 1am.

mcervar commented 4 months ago

I am already running debug mode, here are logs from last night

Debug mode set like this:

logger:
  default: warning
  logs:
    custom_components.bosch: debug
    bosch_thermostat_client: debug

Message at the end marked in bold only occurs in logs after devices stop working (verified the pattern in last few days), seems stats are fetched but not updated in HA:

024-04-28 01:02:01.708 DEBUG (MainThread) [bosch_thermostat_client.circuits.circuit] Current temp of LIVING ROOM is {'value': 24.5, 'minValue': 5.0, 'maxValue': 30.0, 'unitOfMeasure': 'C', 'writeable': 0, 'used': 'true', 'stepSize': 0.5} 2024-04-28 01:02:01.708 DEBUG (MainThread) [custom_components.bosch.climate] Update of climate Work room component called. 2024-04-28 01:02:01.708 DEBUG (MainThread) [bosch_thermostat_client.circuits.circuit] Current temp of WORK ROOM is {'value': 17.6, 'minValue': 5.0, 'maxValue': 30.0, 'unitOfMeasure': 'C', 'writeable': 0, 'used': 'true', 'stepSize': 0.5} 2024-04-28 01:02:01.709 DEBUG (MainThread) [custom_components.bosch.climate] Update of climate Bedroom component called. 2024-04-28 01:02:01.709 DEBUG (MainThread) [bosch_thermostat_client.circuits.circuit] Current temp of BEDROOM is {'value': 20.2, 'minValue': 5.0, 'maxValue': 30.0, 'unitOfMeasure': 'C', 'writeable': 0, 'used': 'true', 'stepSize': 0.5} 2024-04-28 01:02:01.709 DEBUG (MainThread) [custom_components.bosch.climate] Update of climate Bathroom component called. 2024-04-28 01:02:01.709 DEBUG (MainThread) [bosch_thermostat_client.circuits.circuit] Current temp of BATHROOM is {'value': 23.3, 'minValue': 5.0, 'maxValue': 30.0, 'unitOfMeasure': 'C', 'writeable': 0, 'used': 'true', 'stepSize': 0.5}

2024-04-28 01:02:01.712 DEBUG (MainThread) [custom_components.bosch] Update already in progress. Not updating.

ChristophPech commented 4 months ago

I do have the same issue since the last update. The debug log doesn't show anything out of the ordinary, the regular "Update of climate ... component called." still continue normally but all the values stop updating until I reload the integration. It happens at 4 o'clock every night, which is the same time my internet router reconnects and receives a new public IPv4.

mcervar commented 4 months ago

My IP doesnt change at problematic time of the integration, only clue is this in the logs which starts showing after integration stops working properly:

2024-04-28 01:02:01.712 DEBUG (MainThread) [custom_components.bosch] Update already in progress. Not updating.

@ChristophPech can you check if the same occurs in your logs only after integration stops working? You need to enable debug logs if you havent already :D

ChristophPech commented 4 months ago

Yes, right. I too have this message, overlooked it before. I also forgot to enable debug logging for bosch_thermostat_client. I now get these after manually requesting a new DSL connection:

INFO (MainThread) [bosch_thermostat_client.connectors.xmpp] Msg exception for /dhwCircuits/dhw1/programs DEBUG (MainThread) [bosch_thermostat_client.connectors.xmpp] Response to GET request /dhwCircuits/dhw1/programs: null

This means asyncio.TimeoutError. Maybe Bosch changed something or the new XMPP library behaves slightly different.

pszafer commented 4 months ago

I think new library doesn't reconnect properly. I'll fix that but HA changed too much in 2024.5; I have to rewrite a lot of code of component and don't have time for that.

sergioras commented 3 months ago

I have the same issue. I temporarily solved it with an automation that reloads the integration every 24h: service: homeassistant.reload_config_entry target: {} data: entry_id: 06d7ca863dc3f075184f663ef0399e10

I found the correct entry_id in the core.config_entries file.

ChristophPech commented 3 months ago

I found the correct entry_id in the core.config_entries file.

You can find the ID in the URL when listing devices of the bosch integration: image

sergioras commented 3 months ago

Great suggestion! Thanks

Sergio

Il mer 29 mag 2024, 11:23 Christoph Pech @.***> ha scritto:

I found the correct entry_id in the core.config_entries file.

You can find the ID in the URL when listing devices of the bosch integration: image.png (view on web) https://github.com/bosch-thermostat/home-assistant-bosch-custom-component/assets/3427525/6584e965-02d6-462f-80f8-4e83f4766bc4

— Reply to this email directly, view it on GitHub https://github.com/bosch-thermostat/home-assistant-bosch-custom-component/issues/404#issuecomment-2136950717, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK2ZUCTUV6A43GDXFWRLGWTZEWM75AVCNFSM6AAAAABGYLQOJSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZWHE2TANZRG4 . You are receiving this because you commented.Message ID: <bosch-thermostat/home-assistant-bosch-custom-component/issues/404/2136950717 @github.com>

andyktaylor commented 2 months ago

I have the same issue. I temporarily solved it with an automation that reloads the integration every 24h: service: homeassistant.reload_config_entry target: {} data: entry_id: 06d7ca863dc3f075184f663ef0399e10

I found the correct entry_id in the core.config_entries file.

Been wondering why this suddenly stops working for a while now. Your solution works a treat, thanks!

I did it as an automation:

alias: Boiler reload description: "" trigger: