iMicknl / python-overkiz-api

Async Python wrapper to interact with internal Somfy TaHoma API, or other OverKiz API's.
MIT License
46 stars 29 forks source link

Frequently updating device states #968

Closed RichieB2B closed 12 months ago

RichieB2B commented 12 months ago

I wrote an overkiz2mqtt script and noticed that the device states are refreshed once every 10 minutes. The Overkiz server allows me to call get_state() every minute but the data is only actually different after 10 minutes. I am mostly interested in io:MiddleWaterTemperatureState from my io:AtlanticDomesticHotWaterProductionV2_CV4E_IOComponent so I tried calling client.execute_command(device.device_url, "refreshMiddleWaterTemperature") which works but seems rate limited. After calling it about 50 times in one session I get:

TooManyRequestsException while executing refreshMiddleWaterTemperature: Too many requests, try again later

Restarting the session after this works but it feels like a hack (and a violation). I was hoping that the fetch_events() would help but this only gives me io:MiddleWaterTemperatureState after I issue a refreshMiddleWaterTemperature command. So even the 10 minute updates are missed using fetch_events().

What is the supported way of retrieving near-real-time state information from Overkiz?

tetienne commented 12 months ago

Hi, this repository is not supported by Somfy. The goal of pyoverkiz is to wrap the Overkiz API. You can have a try on https://github.com/Somfy-Developer/Somfy-TaHoma-Developer-Mode

As a side note, I can confirm that some devices are really painful to understand.

RichieB2B commented 12 months ago

I know this repo is not official code by Somfy. I am just trying to understand how to best use the API.

I did some more experimenting and it seems TooManyRequestsException is a temporary issue on the Overkiz server end that resolves itself after a while. This is probably the reason this repo is using @backoff for all API calls. When max_tries is exceeded and TooManyRequestsException is thrown anyway, trying again a few minutes later works just fine. Which I guess means max_tries=10 it too low for the "atlantic_cozytouch" server these past few days.

https://github.com/iMicknl/python-overkiz-api/blob/4bbc5f8787842285caf204c7406eec1dd483e664/pyoverkiz/client.py#L614-L618

RichieB2B commented 12 months ago

My previous comment is wrong. TooManyRequestsException is fatal: the server will refuse the API call that receives this as a response for the duration of the session. The only solution is to start a new session (which feels like a hack to bypass rate limiting). Now I understand why this project uses @backoff for TooManyExecutionsException but not for TooManyRequestsException.

I experimentally confirmed that for refreshMiddleWaterTemperature the limit appears to be 50 command executions. It does not matter if I wait 1, 2 or 3 minutes between the calls. Number 51 simply is never allowed in the same session.