UniFi Security Gateway

Any issues running this on hassio?

Nope. Works for me…

I’d like to echo the earlier request for CPU utilization and and WAN capacity.

My USG 3P loves to sit at 100% CPU usage for seemingly no reason and a component like this would make it easy to track and alert on.

Here are a few template sensors for CPU, memory and WAN IP.

In configuration.yaml:

- platform: template
  sensors:
    unifi_gateway_wan_cpu:
      friendly_name: 'CPU'
      value_template: "{{ states.sensor.unifi_gateway_wan.attributes['gw_system-stats']['cpu'] }}"

    unifi_gateway_wan_mem:
      friendly_name: 'Memory'
      value_template: "{{ states.sensor.unifi_gateway_wan.attributes['gw_system-stats']['mem'] }}"

    unifi_gateway_wan_ip:
      friendly_name: 'WAN IP'
      value_template: '{{ states.sensor.unifi_gateway_wan.attributes.wan_ip }}'

The CPU and Memory look pretty good in a Lovelace horizontal stack of 2 or 3 “gauge” cards, at least in a desktop -sized browser.

1 Like

Hi,
I got everything succesfully configured and the sensors are available with the correct information - BUT they’re not updating…

I’m running 86.4 and all my other sensors are updating their info at regular intervalls. What am I missing?

Upgraded my CloudKey Controller version to 5.10.12-11629-1 and this seems to have broken the custom component.

The initial login attempt from HomeAssistant results in the following:
Failed to connect to Unifi: Login failed - status code: 400

I have not updated to the latest firmware myself but read that the PyUnifi library has had to be updated to support the latest login process. Therefore the component has updated its requirements to PyUnifi 2.16, the latest version should propagate through shortly. Please let me know how you get on with it.
(The login process is the same as the Unifi device tracker, so if that is working ok, so should this component)

Requirement already satisfied: pyunifi in /srv/homeassistant/lib/python3.7/site-packages (2.16)

Thanks for replying so quickly. I updated unifigateway.py, checked my pyunifi version and still get the HTTP 400 error. My device tracker component is working without issue.

@jchasey I wonder if you can help me ?

I am getting the following error … what does this mean

[custom_components.sensor.unifigateway] Failed to access health info: api.err.NoSiteContext

here is my sensor settings

  • platform: unifigateway
    host: ‘192.168.1.17’
    username: ‘user’
    password: ‘password’
    port: ‘8443’
    site_id: ‘Ferry Village’
    verify_ssl: false
    monitored_conditions:
    • www
    • wan
    • lan
    • wlan
    • alerts
    • firmware

The login details are for the controller software not the USG itself.

Thanks in adavnce

It appears that sometimes you can successfully login to the controller, but when you try and make the API call for the health information nothing is returned. In that situation the Failed to access health info error message is reported. Restarting HA generally sorts the problem.
Intention is to update the startup code to login, check the API is available, and if not, logout and try again, just havn’t had time to update the code to do this.

No matter how many times I reboot keep failing … below is the full log

2019-02-11 14:20:21 WARNING (MainThread) [homeassistant.loader] You are using a custom component for sensor.unifigateway which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-02-11 14:20:27 WARNING (SyncWorker_16) [pyunifi.controller] Failed to perform <function Controller._read at 0x72c76468> due to api.err.NoSiteContext
2019-02-11 14:20:28 ERROR (SyncWorker_16) [custom_components.sensor.unifigateway] Failed to access health info: api.err.NoSiteContext
2019-02-11 14:20:28 WARNING (SyncWorker_19) [pyunifi.controller] Failed to perform <function Controller._read at 0x72c76468> due to api.err.NoSiteContext
2019-02-11 14:20:29 ERROR (SyncWorker_19) [custom_components.sensor.unifigateway] Failed to access health info: api.err.NoSiteContext
2019-02-11 14:20:30 WARNING (SyncWorker_1) [pyunifi.controller] Failed to perform <function Controller._read at 0x72c76468> due to api.err.NoSiteContext
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/components/device_tracker/init.py”, line 183, in async_setup_platform
disc_info)
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/google_maps.py”, line 46, in setup_scanner
scanner = GoogleMapsScanner(hass, config, see)
File “/usr/local/lib/python3.6/site-packages/homeassistant/components/device_tracker/google_maps.py”, line 66, in init
self._update_info()
File “/usr/local/lib/python3.6/site-packages/homeassistant/components/device_tracker/google_maps.py”, line 78, in _update_info
for person in self.service.get_all_people():
File “/usr/local/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py”, line 439, in get_all_people
people = self.get_shared_people() + [self.get_authenticated_person()]
File “/usr/local/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py”, line 400, in get_shared_people
for info in output[0]:
TypeError: ‘NoneType’ object is not iterable
2019-02-11 14:20:31 ERROR (SyncWorker_1) [custom_components.sensor.unifigateway] Failed to access health info: api.err.NoSiteContext
2019-02-11 14:20:31 WARNING (SyncWorker_0) [pyunifi.controller] Failed to perform <function Controller._read at 0x72c76468> due to api.err.NoSiteContext
2019-02-11 14:20:32 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform unifigateway is taking over 10 seconds.
2019-02-11 14:20:32 ERROR (SyncWorker_0) [custom_components.sensor.unifigateway] Failed to access health info: api.err.NoSiteContext
2019-02-11 14:20:32 WARNING (SyncWorker_16) [pyunifi.controller] Failed to perform <function Controller._write at 0x72c76540> due to api.err.NoSiteContext
2019-02-11 14:20:33 ERROR (SyncWorker_16) [custom_components.sensor.unifigateway] Failed to access alerts info: api.err.NoSiteContext
2019-02-11 14:20:33 ERROR (MainThread) [homeassistant.components.sensor] unifigateway: Error on device update!
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py”, line 248, in _async_add_entity
await entity.async_device_update(warning=False)
File “/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py”, line 349, in async_device_update
await self.hass.async_add_executor_job(self.update)
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/util/init.py”, line 315, in wrapper
result = method(*args, **kwargs)
File “/config/custom_components/sensor/unifigateway.py”, line 143, in update
for index, alert in enumerate(unarchived_alerts,start=1):
UnboundLocalError: local variable ‘unarchived_alerts’ referenced before assignment
2019-02-11 14:20:33 WARNING (SyncWorker_7) [pyunifi.controller] Failed to perform <function Controller._read at 0x72c76468> due to api.err.NoSiteContext
2019-02-11 14:20:34 ERROR (SyncWorker_7) [custom_components.sensor.unifigateway] Failed to scan aps: api.err.NoSiteContext
2019-02-11 14:20:34 ERROR (MainThread) [homeassistant.components.sensor] unifigateway: Error on device update!
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py”, line 248, in _async_add_entity
await entity.async_device_update(warning=False)
File “/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py”, line 349, in async_device_update
await self.hass.async_add_executor_job(self.update)
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/util/init.py”, line 315, in wrapper
result = method(*args, **kwargs)
File “/config/custom_components/sensor/unifigateway.py”, line 159, in update
for devices in aps:
UnboundLocalError: local variable ‘aps’ referenced before assignment
2019-02-11 14:20:38 ERROR (MainThread) [homeassistant.components.sensor.template] Could not render template CPU: UndefinedError: ‘mappingproxy object’ has no attribute ‘gw_system-stats’
2019-02-11 14:20:38 ERROR (MainThread) [homeassistant.components.sensor.template] Could not render template Memory: UndefinedError: ‘mappingproxy object’ has no attribute ‘gw_system-stats’
2019-02-11 14:20:59 WARNING (SyncWorker_2) [pyunifi.controller] Failed to perform <function Controller._read at 0x72c76468> due to api.err.NoSiteContext
2019-02-11 14:21:00 ERROR (SyncWorker_2) [custom_components.sensor.unifigateway] Failed to access health info: api.err.NoSiteContext

What is your config for the component?

@jchasey Below is in my configuration.yaml

sensor:

  • platform: unifigateway
    host: ‘192.168.1.17’
    username: ‘user’
    password: ‘password’
    port: ‘8443’
    site_id: ‘Ferry Village’
    verify_ssl: false
    monitored_conditions:
    • www
    • wan
    • lan
    • wlan
    • alerts
    • firmware

The file is located in the following location:

\config\custom_components\sensor\unifigateway.py

I think it is your site_id. Rather than plain text, this is an encoded string. If you log into the Unifi controller, the default site uses the name ‘default’ within the URL:

https://unifi.ubnt.com/5.9.29.1/unifi/site/default/dashboard

However, then switch to your alternate site, and instead of the english site name, there is an encoded string in the URL, e.g.:

https://unifi.ubnt.com/5.9.29.1/unifi/site/t5unereb/dashboard

That is the string you need to use for site_id config:

site_id: 't5unereb'

1 Like

Thanks I will give that a go …. don’t know where it comes up with the ids but below is the url

manage/site/abjk0pl2/dashboard

I will change site to ‘abjk0pl2’ and see how that works out

This component seems to be broken since 0.92 and the “Great migration” can anyone confirm if they have it working?

it’s working. you need to add a manifest.json file (see below) in the unifigateway folder. So the folder will contain the sensor.py and this.

{
  "domain": "unifi_sensor",
  "name": "Unifi",
  "documentation": "https://github.com/custom-components/sensor.unifigateway",
  "requirements": [],
  "dependencies": [],
  "codeowners": []
}
1 Like

Can confirm that adding the manifest.json makes the component work.

same here… working now… thanks for your help

Thank you for this. I’ve got this working with your given attributes:

Also, I would like to make a CPU temperature sensor but sadly it doesn’t work if I try this:

  • platform: template
    sensors:
    unifi_gateway_wan_cpu_temp:
    friendly_name: ‘CPU temperature’
    value_template: “{{ states.sensor.unifi_gateway_wan.attributes[‘gw_system-stats’][‘CPU’] }}”

Value in new sensor stays empty. Maybe because of the space in the value? e.g. 75 C (%value%|space|C)

I would also like to see this with my UniFi switch but haven’t found any solution yet.

Any ideas/thoughts about this?