jaroschek / home-assistant-myuplink

Custom Home Assistant integration for devices and sensors in myUplink account.
43 stars 10 forks source link

Timeout fetching myUplink data #15

Closed rawrgit closed 1 year ago

rawrgit commented 1 year ago

I installed this integration just over a day ago and it is timing out all the time making the device/entities (Hot water heater) unavailable for 2-3-5-10 minutes at a time. I just turned on debug and see a lot of throttle messages as shown under here.

When successfully connected it all works perfectly as i see all the settings/values and can adjust them.

A few minutes of log: https://dpaste.com/A8KHNLQ6P

jaroschek commented 1 year ago

Thanks for your error report. The current implementation tries to avoid the official rate limiting of the myUplink API by manually throttling to allow requests only every 5 seconds:

The myUplink API is rate limited. All requests reaching the myUplink API is counted and when the limit has been reached the following requests will get an error message with the HTTP status code 429 in return. The current limit for public API clients is one request every 4th second with occasional bursts allowed. These limits can be be adjusted at any time without notice if deemed necessary.

If an application or client is found abusing the API in any way, myUpTech AB has the right to block it until the client owner has solved the issues highlighted by myUplink.

The update coordinator is configured to update the integration every 60 seconds. For a complete update of your integration the following requests will be made (every 60 seconds):

  1. fetch users system containing information for the system and each contained device
  2. for each device collect all available parameters with one request per device
  3. for each device collect all available smart-home-zones with one request per device

As these 3 requests are made sequentially we need to throttle the 2nd and the 3rd request to wait some seconds. Otherwise we would run into the rate limiting. So you should always see 2 messages like Delaying request by 4.999936 seconds due to throttle in your system log.

The total time to update a single device with some parameter points should not exceed 30 seconds. So I initially set the timeout for the update coordinator to 30 seconds. But as I see in your log the timeout is reached very often. And reaching the timeout will cause the device to be (temporarily) unavailable for home assistant.

How many devices and parameters do you have in your myUplink system? Each additional device would cause the system to make 2 additional requests with 5 seconds throttling for each request. So you could reach the 30s timeout if you have 2 or even 3 devices.

Then there would be 2 possible solutions:

jaroschek commented 1 year ago

I applied the changes from #16 and observed the requests through the debug log. As expected only 1 request (per device) is made on each coordinator update. This should solve your timeout issues.

rawrgit commented 1 year ago

Thank you for the detailed description of how this works. Am I the only one seeing this problem with the instability which makes my device down/unavailable? Have added a screenshot here from HA history to whow how significant this is for me throughout a timespan of 4 hours.

Screenshot

To answer your question in your response I can mention that i have only one device, a hot water boiler, in my myUplink system.

jaroschek commented 1 year ago

Okay. Good to know, that even with only one device the 30s timeout for the coordinator have been exceeded so often.

Can you please update the integration through HACS?

It should be more reliable now, as I reduced the number of requests from 3 (per device) to only 1 for each coordinator update every 60s.

rawrgit commented 1 year ago

I have updated the integration and can confirm that the stability is significantly better. When writing this response the integration has been running on updated version for 1,5hrs and has only had 1 timeout.