corvis / homeassistant_prana

HomeAssistant integration with Prana recuperators
GNU General Public License v3.0
22 stars 8 forks source link

Can't read data from prana recuperator due to connection failing after 5 attempts #3

Open MislavMandaric opened 3 years ago

MislavMandaric commented 3 years ago

Hi.

First of all, thank you for the great work on this integration. I never thought I'd see my recuperator integrated with HA and I really appreciate the work you've done, both on the integration and the awesome prana_rc library.

I set up this integration and prana_rc server on my RPi (both running on the same HA OS) and when I first start the prana_rc docker container, everything works well.

But after some time, I always get the error from the title after which my recuperator disconnects from HA and becomes unavailable.

This is my setup:

I can ping the prana_rc server from my laptop terminal, which means the server itself is running and it does show proper connection to the recuperator:

curl -X POST -H "Accept: application/json" http://homeassistant.local:8881/ -d '{ "jsonrpc": "2.0", "id": 1, "method": "prana.healthcheck" }'
{"result": {"version": "0.4.4", "timestamp": "2021-05-06T19:21:15.699394", "current_connections": ["XX:XX:XX:XX:XX:XX"]}, "id": 1, "jsonrpc": "2.0"}

But this is the log from HA, showing connection errors. I enabled the debug log and there is nothing in addition to these error snippets, which occur 3-4 times in the log.

2021-05-06 21:22:46 WARNING (MainThread) [custom_components.prana.fan] Can't read data from prana recuperator Prana (prana_XX_XX_XX_XX_XX_XX): RPC Invocation error -32000: Server error. Cause: RuntimeError: Connection to device XX:XX:XX:XX:XX:XX failed after 5 attempts
2021-05-06 21:22:46 ERROR (MainThread) [custom_components.prana.fan] Unexpected error fetching prana_XX_XX_XX_XX_XX_XX data: RPC Invocation error -32000: Server error. Cause: RuntimeError: Connection to device XX:XX:XX:XX:XX:XX failed after 5 attempts
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 173, in _async_refresh
self.data = await self._async_update_data()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 143, in _async_update_data
return await self.update_method()
File "/config/custom_components/prana/fan.py", line 67, in async_get_state
raise e
File "/config/custom_components/prana/fan.py", line 62, in async_get_state
return await prana_client.get_state(
File "/usr/local/lib/python3.8/site-packages/prana_rc/contrib/client/common.py", line 45, in get_state
await self.async_invoke(
File "/usr/local/lib/python3.8/site-packages/sizzlews/client/common.py", line 179, in async_invoke
return await self._invoke_request(rq, expected_response_type)
File "/usr/local/lib/python3.8/site-packages/sizzlews/client/aiohttp.py", line 47, in _invoke_request
return self._parse_rpc_response(await response.json(), expected_response_type)
File "/usr/local/lib/python3.8/site-packages/sizzlews/client/common.py", line 119, in _parse_rpc_response
raise RPCInvocationError.from_rpc_dict(response[RESPONSE_FIELD_EROR])
sizzlews.client.common.RPCInvocationError: RPC Invocation error -32000: Server error. Cause: RuntimeError: Connection to device XX:XX:XX:XX:XX:XX failed after 5 attempts
2021-05-06 21:22:46 DEBUG (MainThread) [custom_components.prana.fan] Finished fetching prana_XX_XX_XX_XX_XX_XX data in 2.729 seconds

This is the screenshot of how it looks like from the UI (all entities are disabled and unavailable). image

If there is anything I can do more to help out in in resolving this issue, I'll gladly contribute.

corvis commented 3 years ago

Hi Mislav,

Thank you for the feedback and such a comprehensive report.

I saw similar behavior but typically this happened after ~ month of work. So it seems like this issue has higher priority then I thought initially. I'll investigate whenever have a chance.

On Thu, May 6, 2021, 10:50 PM Mislav Mandarić @.***> wrote:

Hi.

First of all, thank you for the great work on this integration. I never thought I'd see my recuperator integrated with HA and I really appreciate the work you've done, both on the integration and the awesome prana_rc library.

I set up this integration and prana_rc server on my RPi (both running on the same HA OS) and when I first start the prana_rc docker container, everything works well.

But after some time, I always get the error from the title after which my recuperator disconnects from HA and becomes unavailable.

This is my setup:

  • HA OS running on RPi4, version 5.12; HA Core version is core-2021.4.6; Supervisor version is supervisor-2021.04.3
  • Prana RC server running on the same machine, deployed using Portainer (config from the prana_rc repository is used -- /run/dbus/system_bus_socket, hassio network, restart unless stopped policy, with default 8881 port mapping), version corvis/prana-rc:0.4.4 of the image
  • Integration installed using HACS as custom repository
  • RPi is ~6m away from the recuperator, in the same room

I can ping the prana_rc server from my laptop terminal, which means the server itself is running and it does show proper connection to the recuperator:

curl -X POST -H "Accept: application/json" http://homeassistant.local:8881/ -d '{ "jsonrpc": "2.0", "id": 1, "method": "prana.healthcheck" }' {"result": {"version": "0.4.4", "timestamp": "2021-05-06T19:21:15.699394", "current_connections": ["XX:XX:XX:XX:XX:XX"]}, "id": 1, "jsonrpc": "2.0"}

But this is the log from HA, showing connection errors. I enabled the debug log and there is nothing in addition to these error snippets, which occur 3-4 times in the log.

2021-05-06 21:22:46 WARNING (MainThread) [custom_components.prana.fan] Can't read data from prana recuperator Prana (prana_XX_XX_XX_XX_XX_XX): RPC Invocation error -32000: Server error. Cause: RuntimeError: Connection to device XX:XX:XX:XX:XX:XX failed after 5 attempts 2021-05-06 21:22:46 ERROR (MainThread) [custom_components.prana.fan] Unexpected error fetching prana_XX_XX_XX_XX_XX_XX data: RPC Invocation error -32000: Server error. Cause: RuntimeError: Connection to device XX:XX:XX:XX:XX:XX failed after 5 attempts Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 173, in _async_refresh self.data = await self._async_update_data() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 143, in _async_update_data return await self.update_method() File "/config/custom_components/prana/fan.py", line 67, in async_get_state raise e File "/config/custom_components/prana/fan.py", line 62, in async_get_state return await prana_client.get_state( File "/usr/local/lib/python3.8/site-packages/prana_rc/contrib/client/common.py", line 45, in get_state await self.async_invoke( File "/usr/local/lib/python3.8/site-packages/sizzlews/client/common.py", line 179, in async_invoke return await self._invoke_request(rq, expected_response_type) File "/usr/local/lib/python3.8/site-packages/sizzlews/client/aiohttp.py", line 47, in _invoke_request return self._parse_rpc_response(await response.json(), expected_response_type) File "/usr/local/lib/python3.8/site-packages/sizzlews/client/common.py", line 119, in _parse_rpc_response raise RPCInvocationError.from_rpc_dict(response[RESPONSE_FIELD_EROR]) sizzlews.client.common.RPCInvocationError: RPC Invocation error -32000: Server error. Cause: RuntimeError: Connection to device XX:XX:XX:XX:XX:XX failed after 5 attempts 2021-05-06 21:22:46 DEBUG (MainThread) [custom_components.prana.fan] Finished fetching prana_XX_XX_XX_XX_XX_XX data in 2.729 seconds

This is the screenshot of how it looks like from the UI (all entities are disabled and unavailable). [image: image] https://user-images.githubusercontent.com/2945713/117355165-7d07b180-aeb2-11eb-93e9-c8ecb424f697.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/corvis/homeassistant_prana/issues/3, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABKVUD2SU73JKY4BYBXSC63TMLXKFANCNFSM44HZMT3Q .

MislavMandaric commented 3 years ago

Hey @corvis. Do you have any updates on this one?

I still have this same behavior -- once I set up my integration, it works for some time (~hours) and after that it stops working.

Now I checked out the usage by curling the API some more and apparently it doesn't work even from the terminal. Same as before, I can get a proper health check response (same as I already wrote), but when I do a curl for get_state method, it returns an error:

curl -X POST -H "Accept: application/json" http://homeassistant.local:8881/ -d '{ "jsonrpc": "2.0", "id": 1, "method": "prana.get_state", "params": {"address": "XX:XX:XX:XX:XX:XX"} }' 
{"error": {"code": -32000, "message": "Server error", "data": {"type": "RuntimeError", "args": ["Connection to device XX:XX:XX:XX:XX:XX failed after 10 attempts"], "message": "Connection to device XX:XX:XX:XX:XX:XX failed after 10 attempts"}}, "id": 1, "jsonrpc": "2.0"}

So it might not be connected to the integration, rather to the prana_rc server.

I'm looking at the logs in Portainer for my prana_rc container and there aren't any. Is there a way to run the prana_rc server with some verbose logging, so I can provide more details on the issue?

Also, would you rather to open another PR in prana_rc repository since the issue is most likely somewhere in the server, not in the integration.

EDIT: Stopping and starting the container again makes it work from the CLI, but from Home Assistant it is still showing as unavailable.

aurelian17 commented 1 year ago

I have a similar problem. On HA 2022.10 is impossible to connect to the Prana recuperator. If makes any sense, in the past 2 releases, HA added support natively for BT BLE. Also, a new feature called BT Proxy might help connect to the recuperators that are far from the server running the prana_rc.

yuriilemberg commented 8 months ago

I have same issue, sometimes it works sometimes it gives me this error

code: -32000, message: 'Server error', data: { type: 'RuntimeError', args: [Array], message: 'Connection to device xx:94:xx:F5:xx:xx failed after 10 attempts'

btw, discover works all the time