tadasdanielius / daikin_altherma

Daikin Altherma custom component for home assistant
MIT License
76 stars 6 forks source link

Error: Concurrent call to receive() is not allowed #60

Closed mdkeil closed 1 year ago

mdkeil commented 1 year ago

I have some automations that often failes due to following same error messages for space heating and hot water tank Integration device.

Homeassistent 2023.2.2

  1. Space Heater
    
    Logger: homeassistant.components.automation.wp_nachtabsenkung_off
    Source: custom_components/daikin_altherma/number.py:177
    Integration: Automatisierung (documentation, issues)
    First occurred: 06:00:00 (2 occurrences)
    Last logged: 06:00:00

WP_Nachtabsenkung_OFF: Error executing script. Unexpected error for device at pos 1: Concurrent call to receive() is not allowed While executing automation automation.wp_nachtabsenkung_off Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 451, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 692, in _async_device_step await device_action.async_call_action_from_config( File "/usr/src/homeassistant/homeassistant/components/device_automation/action.py", line 71, in async_call_action_from_config await platform.async_call_action_from_config(hass, config, variables, context) File "/usr/src/homeassistant/homeassistant/components/number/device_action.py", line 62, in async_call_action_from_config await hass.services.async_call( File "/usr/src/homeassistant/homeassistant/core.py", line 1787, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1824, in _execute_service await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)( File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service await service.entity_service_call( File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 680, in entity_service_call future.result() # pop exception if have File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 968, in async_request_call await coro File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 720, in _handle_entity_call await result File "/usr/src/homeassistant/homeassistant/components/number/init.py", line 96, in async_set_value await entity.async_set_native_value(native_value) File "/config/custom_components/daikin_altherma/number.py", line 177, in async_set_native_value await self._api.device.climate_control.call_operation(key, float(value)) File "/usr/local/lib/python3.10/site-packages/pyaltherma/controllers.py", line 126, in call_operation return await self._connection.request(destination, payload=payload) File "/usr/local/lib/python3.10/site-packages/pyaltherma/comm.py", line 46, in request response_str = await self._client.receive_str(timeout=self._timeout) File "/usr/local/lib/python3.10/site-packages/aiohttp/client_ws.py", line 273, in receive_str msg = await self.receive(timeout) File "/usr/local/lib/python3.10/site-packages/aiohttp/client_ws.py", line 217, in receive raise RuntimeError("Concurrent call to receive() is not allowed") RuntimeError: Concurrent call to receive() is not allowed

Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht

Logger: custom_components.daikin_altherma Source: custom_components/daikin_altherma/init.py:57 Integration: Daikin Altherma HVAC (documentation, issues) First occurred: 05:30:00 (4 occurrences) Last logged: 06:23:43

Bad logger message: Failed to update the device status with error Received message 8:1007 is not str ((TypeError('Received message 8:1007 is not str'),))

2. Hot water tank

Logger: homeassistant.components.automation.wp_dhw_eco Source: custom_components/daikin_altherma/water_heater.py:62 Integration: Automatisierung (documentation, issues) First occurred: 05:30:00 (6 occurrences) Last logged: 06:23:43

WP_DHW_ECO_werktags: Error executing script. Unexpected error for call_service at pos 1: Concurrent call to receive() is not allowed While executing automation automation.wp_dhw_eco Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 451, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 684, in _async_call_service_step await service_task File "/usr/src/homeassistant/homeassistant/core.py", line 1787, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1824, in _execute_service await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)( File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service await service.entity_service_call( File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 680, in entity_service_call future.result() # pop exception if have File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 968, in async_request_call await coro File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 720, in _handle_entity_call await result File "/usr/src/homeassistant/homeassistant/components/water_heater/init.py", line 370, in async_service_temperature_set await entity.async_set_temperature(**kwargs) File "/config/custom_components/daikin_altherma/water_heater.py", line 62, in async_set_temperature await device.set_domestic_hot_water_temperature_heating(target_temperature) File "/usr/local/lib/python3.10/site-packages/pyaltherma/controllers.py", line 231, in set_domestic_hot_water_temperature_heating await self.call_operation('DomesticHotWaterTemperatureHeating', value) File "/usr/local/lib/python3.10/site-packages/pyaltherma/controllers.py", line 126, in call_operation return await self._connection.request(destination, payload=payload) File "/usr/local/lib/python3.10/site-packages/pyaltherma/comm.py", line 46, in request response_str = await self._client.receive_str(timeout=self._timeout) File "/usr/local/lib/python3.10/site-packages/aiohttp/client_ws.py", line 273, in receive_str msg = await self.receive(timeout) File "/usr/local/lib/python3.10/site-packages/aiohttp/client_ws.py", line 217, in receive raise RuntimeError("Concurrent call to receive() is not allowed") RuntimeError: Concurrent call to receive() is not allowed

mdkeil commented 1 year ago

automation example:

alias: WP_DHW_ECO_werktags
description: ""
trigger:
  - platform: time
    at: "05:30:00"
condition:
  - condition: time
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
    after: "05:30:00"
action:
  - service: water_heater.set_temperature
    data:
      temperature: 32
    target:
      entity_id: water_heater.domestic_hot_water_tank
  - delay:
      hours: 0
      minutes: 0
      seconds: 15
      milliseconds: 0
    enabled: true
  - service: water_heater.set_operation_mode
    data:
      operation_mode: "on"
    target:
      entity_id: water_heater.domestic_hot_water_tank
    enabled: true
mode: single
tadasdanielius commented 1 year ago

Yes, this is known issue. The problem is that daikin gateway accepts only one connection and sometimes it happens when getting the data from the device and setting the data at the same time it throws that error. I just need to find a time to fix that as it requires some refactoring to be done. In the meantime as a workaround you can change how often the integration query the device for new changes. In order to do that you can go to /config/custom_components/daikin_altherma/const.py and change

UPDATE_INTERVAL_SECONDS = 2

To something like 10 seconds (and of course restart HA)

UPDATE_INTERVAL_SECONDS = 10

The drawback is that changes made on the device might take longer to appear on the HA.

You can look into this issue.

Keep in mind if you make a change and later reinstall/upgrade the integration the changes will be lost so you will need to update that again.

mdkeil commented 1 year ago

ok, I will try this workaround.

I have some new warning for further investigation:

Detected integration that called async_setup_platforms instead of awaiting async_forward_entry_setups; this will fail in version 2023.3. Please report issue to the custom integration author for daikin_altherma using this method at custom_components/daikin_altherma/__init__.py, line 81: hass.config_entries.async_setup_platforms(entry, PLATFORMS)

tadasdanielius commented 1 year ago

ok it looks like async_setup_platforms is going to be deprecated very soon. At the moment it shouldn't be a problem but thanks for pointing that out.

mdkeil commented 1 year ago

the workaround didn't work for me.. I parallel use espaltherma, that readout some registers every 10s.

Get some more error message with the same cause:

Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht

Logger: custom_components.daikin_altherma
Source: custom_components/daikin_altherma/__init__.py:190
Integration: Daikin Altherma HVAC (documentation, issues)
First occurred: 06:00:00 (1 occurrences)
Last logged: 06:00:00

Something went wrong while updating data from the device
Traceback (most recent call last):
  File "/config/custom_components/daikin_altherma/__init__.py", line 190, in async_update
    self._status = await self.device.get_current_state()
  File "/usr/local/lib/python3.10/site-packages/pyaltherma/controllers.py", line 398, in get_current_state
    unit_status = await unit.get_current_state()
  File "/usr/local/lib/python3.10/site-packages/pyaltherma/controllers.py", line 129, in get_current_state
    sensors = await self.read_sensors()
  File "/usr/local/lib/python3.10/site-packages/pyaltherma/controllers.py", line 63, in read_sensors
    results[sensor] = await self.read_sensor(sensor)
  File "/usr/local/lib/python3.10/site-packages/pyaltherma/controllers.py", line 57, in read_sensor
    return await self.read(query_type='Sensor', prop=sensor)
  File "/usr/local/lib/python3.10/site-packages/pyaltherma/controllers.py", line 49, in read
    result = await self._connection.request(destination)
  File "/usr/local/lib/python3.10/site-packages/pyaltherma/comm.py", line 46, in request
    response_str = await self._client.receive_str(timeout=self._timeout)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client_ws.py", line 273, in receive_str
    msg = await self.receive(timeout)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client_ws.py", line 217, in receive
    raise RuntimeError("Concurrent call to receive() is not allowed")
RuntimeError: Concurrent call to receive() is not allowed
Meatballs1 commented 1 year ago

Following, hit the same issue

tadasdanielius commented 1 year ago

I looked at your automation maybe you should increase the delay between actions as well. Try 30 seconds or 1 minute. After change has been made the integration might try to refresh the current status which can take a while to query all parameters. ESPAltherma should not cause any problems

mdkeil commented 1 year ago

Will give this a try.. but the last error I get with following simple automation: (no further queries)

device_id = "Space Heating"

alias: WP_Nachtabsenkung_OFF
description: ""
trigger:
  - platform: time
    at: "06:00:00"
condition: []
action:
  - device_id: be7a5189fd8cdd68e59cad3ccd8f6b3e
    domain: number
    entity_id: number.temperature_control
    type: set_value
    value: 0
mode: single
tadasdanielius commented 1 year ago

I have created alpha release 1.3.9 which should address this problem. Haven't fully tested that but If you want you can try to install and test yourself. If you are using HACS you might want to switch "show beta releases" and redownload the repo.

mdkeil commented 1 year ago

I will try the alpha release and give feedback.

mdkeil commented 1 year ago

No more errors and my automations working as expected without changing the update interval. 💪🏻