Home assistant keeps disconnecting UniFi controller

Is there anyone using UniFi controller for presence detection?
For some reason Home Assistant keeps losing connection with the UniFi controller.

If I restart the USG and Home Assistant, it works for a while, but never fixes the issue.

019-03-16 08:45:12 ERROR (MainThread) [homeassistant.components.unifi] Error connecting to the UniFi controller at 192.168.1.100
2019-03-16 08:45:12 WARNING (MainThread) [homeassistant.config_entries] Config entry for unifi not ready yet. Retrying in 5 seconds.
2019-03-16 08:45:13 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform unifi
Traceback (most recent call last):
File “/home/htpc/homeassistant/lib/python3.6/site-packages/urllib3/connection.py”, line 159, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File “/home/htpc/homeassistant/lib/python3.6/site-packages/urllib3/util/connection.py”, line 80, in create_connection
raise err
File “/home/htpc/homeassistant/lib/python3.6/site-packages/urllib3/util/connection.py”, line 70, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/htpc/homeassistant/lib/python3.6/site-packages/urllib3/connectionpool.py”, line 600, in urlopen
chunked=chunked)
File “/home/htpc/homeassistant/lib/python3.6/site-packages/urllib3/connectionpool.py”, line 343, in _make_request
self._validate_conn(conn)
File “/home/htpc/homeassistant/lib/python3.6/site-packages/urllib3/connectionpool.py”, line 839, in _validate_conn
conn.connect()
File “/home/htpc/homeassistant/lib/python3.6/site-packages/urllib3/connection.py”, line 301, in connect
conn = self._new_conn()
File “/home/htpc/homeassistant/lib/python3.6/site-packages/urllib3/connection.py”, line 168, in _new_conn
self, “Failed to establish a new connection: %s” % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7f092f67a978>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/htpc/homeassistant/lib/python3.6/site-packages/requests/adapters.py”, line 449, in send
timeout=timeout
File “/home/htpc/homeassistant/lib/python3.6/site-packages/urllib3/connectionpool.py”, line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File “/home/htpc/homeassistant/lib/python3.6/site-packages/urllib3/util/retry.py”, line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=‘192.168.1.100’, port=8443): Max retries exceeded with url: /api/login (Caused by NewConnectionError(‘<urllib3.connection.VerifiedHTTPSConnection object at 0x7f092f67a978>: Failed to establish a new connection: [Errno 111] Connection refused’,))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/htpc/homeassistant/lib/python3.6/site-packages/homeassistant/components/device_tracker/init.py”, line 177, in async_setup_platform
platform.get_scanner, hass, {DOMAIN: p_config})
File “/usr/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/home/htpc/homeassistant/lib/python3.6/site-packages/homeassistant/components/device_tracker/unifi.py”, line 78, in get_scanner
site_id=site_id, ssl_verify=verify_ssl)
File “/home/htpc/homeassistant/lib/python3.6/site-packages/pyunifi/controller.py”, line 89, in init
self._login()
File “/home/htpc/homeassistant/lib/python3.6/site-packages/pyunifi/controller.py”, line 137, in _login
r = self.session.post(login_url, json=params)
File “/home/htpc/homeassistant/lib/python3.6/site-packages/requests/sessions.py”, line 581, in post
return self.request(‘POST’, url, data=data, json=json, **kwargs)
File “/home/htpc/homeassistant/lib/python3.6/site-packages/requests/sessions.py”, line 533, in request
resp = self.send(prep, **send_kwargs)
File “/home/htpc/homeassistant/lib/python3.6/site-packages/requests/sessions.py”, line 646, in send
r = adapter.send(request, **kwargs)
File “/home/htpc/homeassistant/lib/python3.6/site-packages/requests/adapters.py”, line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host=‘192.168.1.100’, port=8443): Max retries exceeded with url: /api/login (Caused by NewConnectionError(‘<urllib3.connection.VerifiedHTTPSConnection object at 0x7f092f67a978>: Failed to establish a new connection: [Errno 111] Connection refused’,))
2019-03-16 08:45:18 ERROR (MainThread) [homeassistant.components.unifi] Unknown UniFi communication error occurred
Traceback (most recent call last):
File “/home/htpc/homeassistant/lib/python3.6/site-packages/homeassistant/components/unifi/controller.py”, line 97, in get_controller
await controller.login()
File “/home/htpc/homeassistant/lib/python3.6/site-packages/aiounifi/controller.py”, line 32, in login
await self.request(‘post’, url, json=auth)
File “/home/htpc/homeassistant/lib/python3.6/site-packages/aiounifi/controller.py”, line 54, in request
‘Invalid content type: {}’.format(res.content_type))
aiounifi.errors.ResponseError: Invalid content type: text/html
2019-03-16 08:45:18 ERROR (MainThread) [homeassistant.components.unifi] Unknown error connecting with UniFi controller.
2019-03-16 08:48:33 WARNING (Thread-2) [pychromecast.socket_client] [Living Room Speaker:8009] Heartbeat timeout, resetting connection
2019-03-16 08:49:03 ERROR (Thread-2) [pychromecast.socket_client] [Living Room Speaker:8009] Failed to connect to service Chromecast-Audio-7493196b845f70e3a10a94a1e3ad93bd._googlecast._tcp.local., retrying in 5.0s
2019-03-16 10:12:19 WARNING (MainThread) [homeassistant.helpers.entity] Update of switch.bedroom_tv_socket is taking over 10 seconds

Looks like more services than just UniFi reconnects

I seem to remember that I had similar issues when I started connecting to the Unifi Controller, my PI got disconnected a lot.
I think I resolved it by creating a separate login for each device that would connect to the controller.

2 Likes

well, I do use the main admin profile, I’m using for everything else.
I’ll create a new one, and test it.
thx!

thx a lot! that was the reason.
it is working fine since yesterday.

QQ:
Which version of the Unifi Controller are you running and on what kind of machine?
Mine worked fine with 5.9.29, now that I upgraded to 5.10 I’m seeing some major issues.

It’s 5.10.19_11646.
Everything seems to be working fine.
One thing I found out. If I restart the host, running the Controller, I need to restart Home Assistant too. Even if the same instance hosts the two service, so both getting restarted…
Probably Ubuntu starts HA before the Controller.

Thanks @szucs.krisz - I’ll probably give it another try then.