chamberlain2007 / aprilaire-ha

A custom component for Home Assistant to interact with Aprilaire thermostats.
MIT License
12 stars 5 forks source link

Automation Connection Lost When Home Assistant is Restarted #41

Closed Nerwyn closed 8 months ago

Nerwyn commented 9 months ago

Sometimes when Home Assistant restarts, the thermostat device (in this case an Aprilaire 8840) becomes unavailable. An "Automation Connection Lost" message also appears on the thermostat screen. This has happened on integration versions 0.8.0 and 0.8.1.

This error appeared after restart before attempting to re-setup:

This error originated from a custom integration.

Logger: custom_components.aprilaire.coordinator
Source: custom_components/aprilaire/coordinator.py:75
Integration: Aprilaire (documentation, issues)
First occurred: 12:41:18 AM (2 occurrences)
Last logged: 12:43:37 AM

Failed to connect to thermostat: [Errno 110] Connect call failed ('192.168.0.160', 8000)

And when I tried deleting the entry and re-setting up without restarting the thermostat:

2023-12-28 00:44:05.567 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Aprilaire for aprilaire
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 402, in async_setup
result = await component.async_setup_entry(hass, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/aprilaire/__init__.py", line 26, in async_setup_entry
await coordinator.start_listen()
File "/config/custom_components/aprilaire/coordinator.py", line 75, in start_listen
await self.client.start_listen()
File "/usr/local/lib/python3.11/site-packages/pyaprilaire/socket_client.py", line 139, in start_listen
await self._reconnect()
File "/usr/local/lib/python3.11/site-packages/pyaprilaire/socket_client.py", line 110, in _reconnect
await asyncio.get_event_loop().create_connection(
File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1069, in create_connection
sock = await self._connect_sock(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/base_events.py", line 973, in _connect_sock
await self.sock_connect(sock, address)
File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 628, in sock_connect
return await fut
^^^^^^^^^
asyncio.exceptions.CancelledError: Global task timeout

I've found that I am able to re-setup the device by deleting the entry in Home Assistant, restarting the thermostat by removing and replacing it from the wall, and then re-adding an entry for it in Home Assistant. So it is consistently fixable (hopefully, small sample size of 2/2 times in the last few weeks).

chamberlain2007 commented 8 months ago

Unfortunately this is something that happens on the thermostat side. The thermostats are VERY flaky and do drop connectivity. I have some safeguards in to reduce the frequency of this by being careful about not making too many connections, but unfortunately it is not something we can really control.

I'm going to close this as there's nothing I can really do about it, but I appreciate your feedback.

Nerwyn commented 8 months ago

Fortunately it hasn't happened since I reported this bug, despite many Home Assistant update and router restarts since then. Thanks for all your hard work!