OpenEPaperLink / Home_Assistant_Integration

Home assistant Integration for the OpenEPaperLink project
Apache License 2.0
137 stars 32 forks source link

Concurrent call detected #54

Closed jurasjo closed 7 months ago

jurasjo commented 9 months ago

Describe the bug Hi, I have two automations for two different tags. Those automations are tgiggered by the same trigger tough(Nordpool price change, every hour). It looks like one tag is refreshed properly, while the second one is not updated. At the time of the event there are warnings in the HA logs like shown below:

Logger: custom_components.open_epaper_link
Source: custom_components/open_epaper_link/__init__.py:23
Integration: OpenEPaperLink ([documentation](https://github.com/jonasniesner/open_epaper_link_homeassistant), [issues](https://github.com/jonasniesner/open_epaper_link_homeassistant/issues))
First occurred: 11:00:00 (1 occurrences)
Last logged: 11:00:00
concurrent call detected, waiting
 Logger: homeassistant.util.async_
Source: util/async_.py:140
First occurred: 11:00:00 (1 occurrences)
Last logged: 11:00:00
Detected blocking call to sleep inside the event loop by custom integration 'open_epaper_link' at custom_components/open_epaper_link/__init__.py, line 24: time.sleep((round(float(filecontent)) + timebetweencalls) - curtime), please create a bug report at https://github.com/jonasniesner/open_epaper_link_homeassistant/issues
Logger: custom_components.open_epaper_link.imagegen
Source: custom_components/open_epaper_link/imagegen.py:313
Integration: OpenEPaperLink ([documentation](https://github.com/jonasniesner/open_epaper_link_homeassistant), [issues](https://github.com/jonasniesner/open_epaper_link_homeassistant/issues))
First occurred: 11:00:04 (1 occurrences)
Last logged: 11:00:04
409

To Reproduce Steps to reproduce the behavior:

  1. Set separate automations with the same trigger.
  2. Wait until automations are triggered by trigger.
  3. See error in HA logs.
  4. Only one tag would be updated.

Expected behavior Alle the tags should be updated.

Additional context I don't know if this is only related to Nordpool as trigger, but I suscpect it is not.

I assume I can add delay to one of my automations after Nordpool price changes, but this is predictible trigger. What if we have a triggers which are random and they might trigger at the same time?

jurasjo commented 9 months ago

Additionally, sometimes those two problems occur at the time of above mentioned triggers:

Logger: websocket
Source: custom_components/open_epaper_link/hub.py:182
Integration: OpenEPaperLink ([documentation](https://github.com/jonasniesner/open_epaper_link_homeassistant), [issues](https://github.com/jonasniesner/open_epaper_link_homeassistant/issues))
First occurred: 08:00:39 (2 occurrences)
Last logged: 08:00:39
[Errno 104] Connection reset by peer - goodbye
Logger: custom_components.open_epaper_link.hub
Source: custom_components/open_epaper_link/hub.py:169
Integration: OpenEPaperLink ([documentation](https://github.com/jonasniesner/open_epaper_link_homeassistant), [issues](https://github.com/jonasniesner/open_epaper_link_homeassistant/issues))
First occurred: 08:00:39 (2 occurrences)
Last logged: 08:00:39
Websocket connection lost, trying to reconnect every 30 seconds

So, when those occur, both tags are not updated.

zarqeon commented 9 months ago

I have the same issue. my use case is: set up an automation that runs every 5 minutes to update multiple tags at the same time (with current weather and temperature data, and whether the heating is currently on). sometimes it works as expected. Sometimes i get back a 104 error, sometimes the number "409". Sometimes one of the tags do gets updated, sometimes none of them.

edit to elaborate more: i think the problem comes from having multiple automation that are triggered at the same time (i have like 5 automation that run every 5 minutes), and either the draw image thingy cannot handle all the requests thrown at it, or the AP is not liking all the images thrown at it, though sometimes the AP has 4 images waiting to be sent to the tags at the same time. I have 6 tags in total that should be updated in every 5 minutes.

zarqeon commented 9 months ago

I did some additional testing. It seems the problem is with the "drawcustom" service, I suspect that the underlying python code can not handle a lot of calls to draw a new image at the same time.

The tests I've done: in the development tools, I created a payload for the drawcustom service and added 8 tags as a target. I called the service in about every minute for like 5 minutes. All 8 tags got updated, every time. While having 5 different automation that trigger the same time, calling drawcustom with 5 different payloads to generate the image, then sending 5 images to 5 different tags have at least one tag failing to update (most probably because it fails at the draw image stage) every single time.

So for the time being a workaround could be to generate the image in a different way if you want to update multiple tags at the same time.

jurasjo commented 9 months ago

Thanks for the info. For now I have delayed those automations(with Nordpool price), so one of them should run 30 seconds later. It has been working for the whole day. I assume this would be solved in the future releases.

zarqeon commented 9 months ago

hopefully yes. I am also thinging about how i can rearrange the refresh of the tags for my own use case to make it work.

I also have to add, that it takes about 4 full minutes for the AP to send the images to 8 tags (we are speaking about the same image). I have the v2 AP, and having a second AP might help with this, or maybe even just having the V3, but this is just a blind assumption from my side. Initially I thought that a refresh in every minute should be fine (since the Tag calls back to the AP in every 40 seconds to check if there is a new image), but it seems, at least right now, it's not really feasible to go under 5 minutes with 8 or more tags.

discodogge commented 9 months ago

hopefully yes. I am also thinging about how i can rearrange the refresh of the tags for my own use case to make it work.

I also have to add, that it takes about 4 full minutes for the AP to send the images to 8 tags (we are speaking about the same image). I have the v2 AP, and having a second AP might help with this, or maybe even just having the V3, but this is just a blind assumption from my side. Initially I thought that a refresh in every minute should be fine (since the Tag calls back to the AP in every 40 seconds to check if there is a new image), but it seems, at least right now, it's not really feasible to go under 5 minutes with 8 or more tags.

Just for what it's worth. the same problem exists on the v3 with only two tags, and two automation that just happened to trigger at the same time

Fettkeewl commented 8 months ago

This is from the 2.01 change logs for the AP firmware.. Seems it's intended! Might be that this integration is not adapted for this change as it was released yesterday Screenshot_20231208_181741_Chrome

jonasniesner commented 7 months ago

Fixed in 5104996