Problems setting up UniFi device tracker

I’m running hassio in docker on ubuntu 18.04. I’m using the UniFi Controller addon to manage my AP and that’s working fine (https://xxxxx.duckdns.org:8443). I’m trying to setup the UniFi device tracker and I’m getting nowhere. Here’s the config for it:

device_tracker:
  - platform: unifi
    host: 192.168.4.3
    port: 8443
    username: !secret unifi_username
    password: !secret unifi_password
    track_new_devices: yes
    verify_ssl: False
    ssid_filter: 
      - 'SSID1'
      - 'SSID2'

And here’s the error I’m getting:

Log Details (ERROR)
Sun Nov 11 2018 22:08:30 GMT-0600 (Central Standard Time)

Error setting up platform unifi
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 159, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 80, in create_connection
    raise err
  File "/usr/local/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 "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 839, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 301, in connect
    conn = self._new_conn()
  File "/usr/local/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 0x7feaa9d57cf8>: 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 "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/local/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.4.3', port=8443): Max retries exceeded with url: /api/login (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7feaa9d57cf8>: 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 "/usr/local/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/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/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 "/usr/local/lib/python3.6/site-packages/pyunifi/controller.py", line 89, in __init__
    self._login(version)
  File "/usr/local/lib/python3.6/site-packages/pyunifi/controller.py", line 148, in _login
    r = self.session.post(login_url, params)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 572, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 524, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 637, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='192.168.4.3', port=8443): Max retries exceeded with url: /api/login (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7feaa9d57cf8>: Failed to establish a new connection: [Errno 111] Connection refused',))

If I switch to the URL:

device_tracker:
  - platform: unifi
    host: xxxxx.duckdns.org
    port: 8443
    username: !secret unifi_username
    password: !secret unifi_password
    track_new_devices: yes
    verify_ssl: False
    ssid_filter: 
      - 'SSID1'
      - 'SSID2'

I get this error message:

Log Details (ERROR)
Sun Nov 11 2018 22:13:23 GMT-0600 (Central Standard Time)

Error setting up platform unifi
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 159, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 80, in create_connection
    raise err
  File "/usr/local/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 "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 839, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 301, in connect
    conn = self._new_conn()
  File "/usr/local/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 0x7fd4c0522f60>: 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 "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/local/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='tehan.duckdns.org', port=8443): Max retries exceeded with url: /api/login (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fd4c0522f60>: 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 "/usr/local/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/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/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 "/usr/local/lib/python3.6/site-packages/pyunifi/controller.py", line 89, in __init__
    self._login(version)
  File "/usr/local/lib/python3.6/site-packages/pyunifi/controller.py", line 148, in _login
    r = self.session.post(login_url, params)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 572, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 524, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 637, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='tehan.duckdns.org', port=8443): Max retries exceeded with url: /api/login (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fd4c0522f60>: Failed to establish a new connection: [Errno 111] Connection refused',))

My googlefu is failing and I’ve ran out of ideas here. Any suggestions?

If you have changed the name of your site from “default”, you need to specify the site_id. I struggled to make it work and that solved the issue for me. Have you changed the name of your site?

Here is my configuration.yaml setting:

device_tracker:

  • platform: unifi
    host: 192.168.1.2
    port: 8443
    username: !secret UnifiUser
    password: !secret UnifiPW
    site_id: !secret SiteID
    verify_ssl: false
    detection_time: 120
    track_new_devices: false
    hide_if_away: true
    monitored_conditions:
    • name
    • mac
    • rx_bytes
    • rx_bytes-r
    • rx_rate
    • uptime
    • last_seen

Thanks for the reply Zoriontsu. I read the docs and pulled my site out of the URL (shows up as default on the URL: https://xxxxx.duckdns.org:8443/manage/site/default/dashboard) and added that to my config:

device_tracker:
  - platform: unifi
    host: xxxxx.duckdns.org
    port: 8443
    site_id: default
    username: !secret unifi_username
    password: !secret unifi_password
    track_new_devices: yes
    verify_ssl: False
    ssid_filter: 
      - 'SSID1'
      - 'SSID2'

I get this error in the logs:

Log Details (ERROR)
Mon Nov 12 2018 12:28:07 GMT-0600 (Central Standard Time)

Error setting up platform unifi
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 159, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 80, in create_connection
    raise err
  File "/usr/local/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 "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 839, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 301, in connect
    conn = self._new_conn()
  File "/usr/local/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 0x7f75e3b285f8>: 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 "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/local/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='tehan.duckdns.org', port=8443): Max retries exceeded with url: /api/login (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f75e3b285f8>: 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 "/usr/local/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/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/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 "/usr/local/lib/python3.6/site-packages/pyunifi/controller.py", line 89, in __init__
    self._login(version)
  File "/usr/local/lib/python3.6/site-packages/pyunifi/controller.py", line 148, in _login
    r = self.session.post(login_url, params)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 572, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 524, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 637, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='tehan.duckdns.org', port=8443): Max retries exceeded with url: /api/login (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f75e3b285f8>: Failed to establish a new connection: [Errno 111] Connection refused',))

With those 4 entries about “connection refused”, it just seems to me that it can’t hit the login page or it’s failing at login. I’ve verified that I can login with the read-only account I built. And there are no special characters in the username/password. Any other ideas?

Thanks!

Your config looks fine. I would try to login first directly using the IP address of your controller. I was never able to make it work with duckdns. But if you can connect to it from using DNS (https://xxxxx.duckdns.org:8443/), there is no reason why your session of HA would not be OK connecting.
My setup is a bit different. I am running on Raspberry PI and Hassbian, but it should make no difference.

I seem to recall the user for the home assistant needs to have admin rights.

Check the docs and double check your rights.

Yep, I did:

### CONFIGURING USERS

The Unifi controller allows you to create multiple users on it besides the main administrator. It is recommended that you create a limited user that has  `read-only`  permissions for the Unifi device tracker.

Yeah, I think yer right. I’ll work on that part next. Thanks sir!

I second this issue. Cannot get it set up at all.

So, I finally got this going and it was an authentication issue. I originally was using secrets.yaml to store my username/pwd but I had better luck just putting them right in the configuration.yaml. I also had to delete the read only account that I setup and make a new one. Then once it got logged in (I could see it in the events within the unifi controller) it’s been working great, until I reboot hassio and it has trouble logging in again. blah…