I just wrote a custom component for monitoring my unifi controller. The state of the sensor shows the number of devices connected. It also shows the number of devices per essid and per AP as attributes. Like this:
This is my first attempt to write a custom component and I’m sure there’s a lot of room to improve. You can grab it at my github.
Nice job @clyra looks interesting, and an easy way to keep tabs of how many clients are connected without having to worry about accessing the unifi webpage. I will have a play around with it when I get a chance
2018-09-10 20:06:06 ERROR (MainThread) [homeassistant.components.sensor] unifi: Error on device update!
Traceback (most recent call last):
File “/usr/src/app/homeassistant/helpers/entity_platform.py”, line 251, in _async_add_entity
await entity.async_device_update(warning=False)
File “/usr/src/app/homeassistant/helpers/entity.py”, line 353, in async_device_update
yield from self.hass.async_add_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 “/config/custom_components/sensor/unifi.py”, line 107, in update
self._data.update()
File “/config/custom_components/sensor/unifi.py”, line 250, in update
self.update_ap_list(ap)
File “/config/custom_components/sensor/unifi.py”, line 224, in update_ap_list
self.ap_list[newmac] = "AP" + device_info[0][‘name’]
KeyError: ‘name’
Hi,
I’m pretty new to Home Assistant, and this is my first attempt at using a custom component, so I might be missing something obvious. I have it placed under custom_components/sensor and it’s found but it errors out on updating. I thought maybe it was ssl and tried adding “verify_ssl: false” to my configuration to no avail. I also tried it using the username & password in my secrets file and also directly in my config. Here is what is logged:
2018-09-12 16:24:41 ERROR (MainThread) [homeassistant.components.sensor] unifi: Error on device update!
File “/home/denny/.homeassistant/custom_components/sensor/unifi.py”, line 107, in update
File “/home/denny/.homeassistant/custom_components/sensor/unifi.py”, line 241, in update
Did you put the config under the right yaml? I mean, under “sensor:”? I assume you can correctly log on https://192.168.0.7:8443 using your browser with the provided password and access the unifi controller interface, it that right?
2018-09-12 19:25:36 WARNING (MainThread) [homeassistant.loader] You are using a custom component for sensor.unifi 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.
2018-09-12 19:25:38 ERROR (MainThread) [homeassistant.components.sensor] unifi: Error on device update!
Traceback (most recent call last):
File “/home/denny/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py”, line 251, in _async_add_entity
await entity.async_device_update(warning=False)
File “/home/denny/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity.py”, line 353, in async_device_update
yield from self.hass.async_add_job(self.update)
File “/usr/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/home/denny/.homeassistant/custom_components/sensor/unifi.py”, line 107, in update
self._data.update()
File “/home/denny/.homeassistant/custom_components/sensor/unifi.py”, line 241, in update
if device[‘essid’] in devices_per_essid.keys():
KeyError: ‘essid’
It seems that there are few (i hope) special cases that I was not expecting, like having a device which is not associated to any essid/network. May you check in your “clients” page on unifi interface if this is the case? I should put a few tests in the code to prevent that from happening.