UniFi Security Gateway

Any info regarding my question?

I have an anomaly which is making me twitch…

I’m using the following to get memory utilization:

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

When I load my Template Entities the value populates…but then after a few minutes it disappears, and only comes back if I reload or if the value changes. Unfortunately I have pretty low usage which means a steady utilization - so I go hours with no reporting.

This is a problem because even tho HA is just happy to report the previous value, I’m actually dumping all my data into an InfluxDB to use in a Grafana dashboard, and it’s just blank.

What’s funny is if I pull the table in InfluxDB I can see the parent sensor.unifi_gateway_wan updates every minute - and includes the mem value, but parsing out the mem value comes up blank

The screenshot below is a 1hr period and the top mem measurement only has 7 entries from when I was reloading…but further down are 3.5 pages of the parent

Does anyone know a way to reload this integration automatically? My Unifi controller and Home Assistant are on the same Docker instance and sometimes Unifi takes a few minutes to startup and Home Assistant won’t retry the connection. Thanks.

go to settings–> Integrations → Find the Unifi Integration, click on the 3 dots and then click on reload

I cannot configure this integration. No mater what im doing it won’t work:
“Failed to connect to Unifi Security Gateway: Login failed - status code: 400”

my config:

- platform: unifigateway
  host: 192.168.1.254
  port: 443
  username: xxxxx
  password: xxxxxx
  verify_ssl: false
  monitored_conditions:
    - www
    - wlan
    - alerts
    - firmware
    - wan

Hey everyone,

I have a problem with my templates. I used the here suggested methods to get the badwidth thats used at the moment. But i get an error in the logs (other data works):

TemplateError('UndefinedError: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'tx_bytes'') while processing template 'Template("{{ states.sensor.unifi_gateway_www.attributes.tx_bytes-r }}")' for attribute '_attr_native_value' in entity 'sensor.unifi_gateway_www_upload'
TemplateError('UndefinedError: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'rx_bytes'') while processing template 'Template("{{ states.sensor.unifi_gateway_www.attributes.rx_bytes-r }}")' for attribute '_attr_native_value' in entity 'sensor.unifi_gateway_www_download'

my templates in the ‘configuration.yaml’ look like this:

sensor:
  - platform: unifigateway
    host: 10.1.0.1
    username: X
    password: X
    monitored_conditions:
      - www

  - platform: template
    sensors:
      unifi_gateway_www_upload:
        unique_id: usg_up
        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:
        unique_id: usg_down
        friendly_name: 'UDM-Pro Download'
        unit_of_measurement: Mbps
        value_template: "{{ states.sensor.unifi_gateway_www.attributes.rx_bytes-r }}"
        icon_template: mdi:download

there is no difference when i try to use

states.sensor.unifi_gateway_www.attributes['rx_bytes-r']
...
or
...
states.sensor.unifi_gateway_www.attributes.rx_bytes

maybe someone can help me#

best regards
Jonas

Could someone help me how I can access the Latency for the different services? Like Facebook, Google and so on:

The Attributetree looks like this:
WAN:
availability: 100
latency_average: 17
monitors:
- availability: 100
latency_average: 22
target: facebook.com
- availability: 100
latency_average: 15
target: google.com
- availability: 100
latency_average: 17
target: twitter.com
time_period: 86400
uptime: 701626

The value template should look like this… somehow:
{{ states.sensor.unifi_gateway_wan.attributes[‘WAN’][‘monitors’][’???’] }}

Is this integration still managed? Seems a real shame that it seems to have fallen the side (looking at github).

Is this still working for anyone? I’m currently trying to install it to connect to my UDM, however am getting the following error in the logs:

Logger: custom_components.unifigateway.sensor
Source: custom_components/unifigateway/sensor.py:91
Integration: unifigateway (documentation)
First occurred: 12:53:33 (1 occurrences)
Last logged: 12:53:33

Failed to connect to Unifi Security Gateway: Login failed - status code: 401

Below is my code:

  - platform: unifigateway
    host: 10.10.20.1
    port: 443
    verify_ssl: false
    version: unifiOS
    username: xxxx
    password: xxxx
    monitored_conditions:
      - www
      - wlan
      - alerts
      - firmware

Does anyone have any suggestions?

It still works fine. Try port 8443

  - platform: unifigateway
    host: 192.161.1.1
    port: 8443
    verify_ssl: false
   #site_id: default
    username: !secret UnifiControllerUser
    password: !secret UnifiControllerPW
    monitored_conditions:
      - www
      - wlan
      - wan
      - lan
      #- alerts
      - firmware

Thanks for the suggestion @Zoriontsu, unfortunately that isn’t working either.

Not sure what the issue is then

Many thanks to the developer and to all who helped take this forward and provided help here. I just got this to work on my UDM. I am running a basic setup with Home Assistant OS running on a RPi. Here is my config.

- platform: unifigateway
host: 192.168.70.1
username: user
password: pwd
port: 443
version: UDMP-unifiOS
monitored_conditions:
- www
- wan
- lan
- wlan
- alerts
- firmware

Thanks for sharing @bestwhenunsupervised … that version seemed to do the trick for my UDM!

I could have sworn I tried doing that value before, but maybe not!

:+1:

Hi friends I’m getting Unverified HTTPS request is being made to host Warning

This error originated from a custom integration.

Logger: py.warnings
Source: custom_components/unifigateway/sensor.py:171
Integration: unifigateway (documentation)
First occurred: 9:16:16 PM (3 occurrences)
Last logged: 10:02:16 PM

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

configuration.yaml

sensor:
  - platform: unifigateway
    host: 192.168.xxx.xx
    port: 443
    version: UDMP-unifiOS
    verify_ssl: false
    username: !secret u_unifi
    password: !secret p_unifi
    monitored_conditions:
      - www
      - wan

I tried reinstalling the component and also tried with and without verify_ssl. I don’t know what to do, I’m getting so many warning Log. Can anyone help me with this

1 Like

I Have the same problem, I guess it’s time to remove this unsupported HACS intergration, shame as it was very handy while it worked.

The warnings are not in the custom_component, but in the pyunifi library instead. I don’t know enough about how the components pull in python packages, but if the code were modified there, it should stop the errors: Advanced Usage - urllib3 1.26.16 documentation (I might get my husband, who’s an actual developer in Python, to help me figure it out).

3 Likes

Did you had a fix by any chance?

Some news regarding that? Another thing, the integration stops after a couple of hours

I suggest using this SSH integration instead: GitHub - zhbjsh/homeassistant-ssh: Control and monitor devices in Home Assistant by executing commands via SSH
It can be used to add sensors and commands.

Note that you don’t need to add a Host key, you can just use password authentication.
Everything is configured in the HA interface once you’ve downloaded it through HACS and have added the integration in the integrations menu.

In case you installed HA as a container and want to access its host, just use host.containers.internal for the Host (instead of the IP) for podman or host.docker.internal for Docker.
Don’t forget to check “Automatically add key to host keys file”.

I’m moving on from this too but…

How do you remove the sensors created by this?