Unifi sensor custom component

Hi,

If you rename it should work, or just wait until tomorrow and I will fix my code :slight_smile: .

I’ll wait until you release a new version. Then we’ll confirm that it works to avoid future issues.

thanks!

Hi,

Just sent a new version for github. May you try it, please?

It works!

image

would be possible to obtain another values that are available from the unifi AP?

image

Thanks!!

Hi,

hm… I think it is possible. What you want?

Hi all,

The custom entity-attribute-card is a good match to the unifi sensor. You may use it by adding something like this to ui-lovelace.yaml:

- type: entities
       title: Unifi
       entities:
        - sensor.unifi
        - type: custom:entity-attributes-card
          entity: sensor.unifi
          filter:
            include:
             - key: sensor.unifi.*

of course, you need to install it…

1 Like

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

And here is my config:

- platform: unifi
  username: Hass
  password: HassPass
  url: https://192.168.0.7:8443
  verify_ssl: false

I’m also using the Unifi device tracker, would that make a difference?

Thanks,

Denny

Hi @dennyreiter, the setup you’re describing is working fine for me; I also have the Unifi device tracker component running:

- platform: unifi
  name: Unifi AP Details
  username: !secret unifi_user
  password: !secret unifi_pass
  url: https://192.168.7.16:8443

Hi @dennyreiter,

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?

Hi @clyra,

great hint there with the the entity-attributes-card :+1:

I got it working the way you describe it, but I cannot get rid of the last wo entries:
image

I’ve tried this as well as including only specific entries:

      - type: custom:entity-attributes-card
        title: Unifi Status
        heading_name: Name
        heading_state: Value
        filter:
          include:
            - key: sensor.unifi.*
          exclude:
            - sensor.unifi.unit_of_measurement
            - sensor.unifi.friendly_name

Any hints?

1 Like

Yes. I have a separate yaml file for sensors, but it’s in with the rest of them.

I found a little more info by not using grep:

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’

Hi,

Entity-attributes-card accepts either include or exclude but not both. Try this:

 filter:
   include:
     - sensor.unifi.ap*
     - sensor.unifi.739*
     - sensor.unifi.gerstmeyers

Thanks for the hint - got it working now, but it doesn’t display the attribute unless I add a * at the end of the string :confused:

Hi @dennyreiter,

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.

My bad… should be - key: sensor.unifi.ap*. Anyway… you got it working :-).

1 Like

Actually, it works without the key:
Maybe I’d only need that if I wanted to give the attribute a specific name - will play with it when I have some time,

I have wired devices that show up as connected to my PoE switch and not an AP, is that what you mean?

yes! I didn’t thought about that as I don’t have other “wired” devices! I put a python script here that will print your devices information in json. At the bottom of the file you should edit your user/pass/ip at the line “api = API(username=“admin”, password=“your_password”, baseurl=“https://your_ip:8443”, verify_ssl=False)”.

You may run it with “python3 unifi_helper.py” or “python3 unifi_helper.py > output.txt” to save the output to a file. If you share the output (edit/change sensitive information, of course) I should be able to correct my code.

output.yaml (78.1 KB)
Here is the output. It’s a txt file, but those don’t seem to be allowed, so I changed the extension to .yaml. I hope that will work.
Thanks for looking at this, If I can’t contribute code yet, I’m more than happy to break things :slight_smile:

Thanks,

Denny