UniFi Security Gateway

HI all,

Am trying to utilize this plugin for my UDM-P, managed to get it configured. Utilized some sensor config templates (with the attributes) above but realised some of them were tagged as Unavailable. The data is available when inspected via Developer Tools. Any idea why?

Have attached my template code here.

      unifi_gateway_www_upload:
        friendly_name: 'UDM-Pro Upload'
        unit_of_measurement: Mbps
        value_template: "{{ states.sensor.unifi_gateway_www.attributes.tx_bytes-r }}"
        icon_template: mdi:upload

      unifi_gateway_www_download:
        friendly_name: 'UDM-Pro Download'
        unit_of_measurement: Mbps
        value_template: "{{ states.sensor.unifi_gateway_www.attributes.rx_bytes-r }}"
        icon_template: mdi:download

If this helps, this is my plugin config:

  - platform: unifigateway
    host: <ip>
    username: xxx
    password: xxx
    version: UDMP-unifiOS
    port: 443
    monitored_conditions:
      - www
      - wlan

If the attribute is really called tx_bytes-r (and not tx_bytes_r), then you should use:

        value_template: "{{ state_attr('sensor.unifi_gateway_www', 'tx_bytes-r') }}"

…and similarly for the rx one. See the warning box in this section.

Your version of the template is being parsed as “get the tx_bytes attribute and subtract r from it” — as neither of those exists, the template is failing.

If that doesn’t solve it, please paste a screenshot of Developer Tools / States for sensor.unifi_gateway_www showing the State and Attributes columns.

Many thanks @Troon, this works. it was indeed -r and not _r.

Separately, any idea on the update frequency of these values? Am comparing the stats vs the UPnP stats and they seem to be updating at a slower frequency.

Has anyone managed to get a temperature value for the UDM Pro? Everything except temp works perfectly for me, but temp value shows as unavailable for me.

1 Like

@mattbedit Temperature is literally the only thing I need to set all of this up for. I’m getting all of the other stats via the Unifi UPNP integration…

I have a USG router and have the Unify Controller within home assistant as addon. I use the following config:

  # Unify gateway
  - platform: unifigateway
    host: !secret unifygateway_host
    port: !secret unifygateway_port
    username: !secret unifygateway_username
    password: !secret unifygateway_password
    monitored_conditions:
      - www
      - wlan
      - alerts
      - firmware

Allot of times when I check the log I get the following error:

ERROR (SyncWorker_15) [custom_components.unifigateway.sensor] Failed to access health info: Expecting value: line 1 column 1 (char 0)

How can I fix this?

Try add version to your config?

Did you fix this?

Sometimes a reboot fixed it.

Currently I run Unify controller as container in unraid, now I don’t have the problems anymore.

This is what I have at my secrets for unify:

# Unify Gateway
unifygateway_host: 192.168.1.XXX
unifygateway_port: 8443
unifygateway_username: username
unifygateway_password: password

Maybe you can check this with your config?

Yes, I should probably switch from the addon… Thanks for the reply :+1:

Has anyone figured out how to create a sensor for availability and latency?

Untitled

I have tried this with no success:

      unifi_gateway_latency:
        friendly_name: 'Unifi Latency'
        value_template: "{{ states.sensor.unifi_gateway_wan.attributes['WAN']['latency_average'] }}"
        icon_template: mdi:rotate-right

      unifi_gateway_availability:
        friendly_name: 'Unifi Availability'
        value_template: "{{ states.sensor.unifi_gateway_wan.attributes['WAN']['availability'] }}"
        icon_template: mdi:arrow-up-circle-outline

Edit: fixed (I didn’t notice the uptime_stats:)

      unifi_gateway_latency:
        friendly_name: 'Unifi Latency'
        value_template: "{{ states.sensor.unifi_gateway_wan.attributes['uptime_stats']['WAN']['latency_average'] }}"
        icon_template: mdi:rotate-right

      unifi_gateway_availability:
        friendly_name: 'Unifi Availability'
        value_template: "{{ states.sensor.unifi_gateway_wan.attributes['uptime_stats']['WAN']['availability'] }}"
        icon_template: mdi:arrow-up-circle-outline

Are the sensor.py and controller.py files by @grantc still valid? I still can’t get it to work with my UDM Pro…

Anyone ? I’m having the same issues here

Hi,

For a whole week I’ve been trying to setup te integration without luck. I constantly get messages that my sensors (unify gateway wan and others) are not available. I’m using a physical UDM Pro as gateway, tried using a local username and password, tried using port 443 and 8443… but without any success…

One thing I do encounter, when I log in to my console from Unifi, I got an ssl error, has this something to do with it ?

Can you confirm right port to use ? 443 or 8443 ? Version : unifiOS, …

Kr,

Bart

Hi,

Example of my config, hope this sort your issue.

 -  platform: unifigateway
    host: 192.168.1.1
    verify_ssl: false
    version: UDMP-unifiOS
    port: 443
    username: !secret unifi_dmp_username
    password: !secret unifi_dmp_password
    monitored_conditions:
      - www
      - wlan
      - alerts
      - firmware
      - vpn
      - lan
      - wan

Hi I had this working before and now it is not working at all? I get the same error as others:
Error while setting up unifigateway platform for sensor

It seems to be problem with the login:

Error while setting up unifigateway platform for sensor
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/connection.py", line 95, in create_connection
    raise err
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/connection.py", line 85, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

But I just want to know hwo to set it up correctly. SO here is how I have set up my network in a simple description:
internet → USG → Ubiquiti US-8-150W → RPi3 with CLoudKey + Controller

there is of course more stuff but here is my question:
When I set this one up should I connect to the USG or the Controller? I think it is Controller but what ever user I am using or have set in the conroller software I cant get it to work now? Coudl someone point med in the right direction? I have set it up according to the latest input from @grantc and I am connecting it directly to the ip.

I have tried both USG and the Controller. Everything is up to date, i.e the latest possible firmware on everything…

Best regards
Jonas
ps/ i had it working before I had to reset my whole network an rebuild it BUT i cant remember how it was set up and now when I have tried I cant remember the working version of the setup…

It was working on my old setup but not my new one.
I had been using HA on a PI for a long time and after it died, I switched to using HomeAssistant Core on on UnRaid setup.
Now it does not seem to work as it did before.
Below is my sensor that I had used on the PI
What might I need to change to get it to work.
Do I need to go back and use 192.168.1.1 instead of the the cloud key IP?

platform: unifigateway
host: 192.168.1.7 #cloudkeygenII
verify_ssl: false
#version: UDMP-unifiOS
port: 443
username: !secret unifi_user
password: !secret unifi_pass
monitored_conditions:
  - www
  - wlan
  - alerts
  - firmware
  - vpn
  - lan
  - wan

Thanks

This integration works fine for months.
However I keep having the following warnings about ssl :

/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host '192.168.1.51'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(

I tried setting verify_ssl: false but this dit not change anything.
With verything_ssl: true, I had different errors.

Hi all, I am trying to get HA to show me my WAN utilisation from my Unifi USG. My Unifi devices are hosted by unificloud (I dont have a cloud key). Will this still work and am I able to show my upload and download realtime utilisation figures using this integration. Any help really appreciated. thanks

No I don’t think download and upload bandwidth meter is realtime. It doesn’t match with router’s data.