UniFi Security Gateway

any idea?
i really want this to work, but im stuck

Given that your params are correct, are you running your controller and HA on separate VLANs? Are there any firewall rules that you have setup that would block HA from accessing your controller? Are you using a self-created SSL certificate?

Also, have you tried the official Unifi integration (https://www.home-assistant.io/integrations/unifi/)?

hey,
@code-in-progress

no im not running controller and ha on separate vlans
no no firewall rules that would block ha accessing controller (both are on same raspberry pi using hass.io and docker for unifi controller)
no dont use ssl certifacte

yes im using official unifi integration, but with that i cant do the same, i can only do presence detection with it (which is working)

Hmmm, I wonder if that might actually be the issue. When you access the site in a browser, do you get a certificate warning?

no
i dont get a warning

for the host, where do i begin and where do i stop?

do i need to include http://
do i need to include the “:” before the port number?

Nope. Host should be JUST the ip address/dns name. Port should be just a number (no “:”). You might be able to actually leave port out and just use host and site.

Can you post your config?

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

frontend:
  themes: !include_dir_merge_named themes
  
# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
packages: !include_dir_named packages

sensor:
  - platform: unifigateway
    host: !secret unifi_host
    site_id: !secret unifi_site
    username: !secret unifi_username
    password: !secret unifi_password

Ok, in your config, try the sensor without using !secret (as a test) for the properties. That’s the first thing I do when I can’t get something working.

Remove the site_id then it will work.
You can also added the monitored conditions

    monitored_conditions:
      - www
      - lan
      - wan
      - wlan
      - alerts
      - firmware
1 Like

i tried what code in progress said, now my hassio gui is unreachable

Did you replace the host: !secret unifi_host as host: unifi_host or did you change it to host: [ip_address]? It should be the latter.

ok gui back up
now i get these erors

Failed to access health info: api.err.NoSiteContext

16:30 custom_components/unifigateway/sensor.py (ERROR) - bericht kwam voor het eerst om 16:29 en verschijnt 6 malen

Failed to perform <function Controller._read at 0x723f57c8> due to api.err.NoSiteContext

16:30 custom_components/unifigateway/sensor.py (WARNING) - bericht kwam voor het eerst om 16:29 en verschijnt 7 malen

unifigateway: Error on device update!

16:29 custom_components/unifigateway/sensor.py (ERROR)

Failed to scan aps: api.err.NoSiteContext

16:29 custom_components/unifigateway/sensor.py (ERROR)

unifigateway: Error on device update!

16:29 custom_components/unifigateway/sensor.py (ERROR)

Failed to access alerts info: api.err.NoSiteContext

16:29 custom_components/unifigateway/sensor.py (ERROR)

Failed to perform <function Controller._write at 0x723f58a0> due to api.err.NoSiteContext

16:29 custom_components/unifigateway/sensor.py (WARNING)

Still not working here…

```
Failed to access health info: api.err.NoSiteContext
21:23 custom_components/unifigateway/sensor.py (ERROR) - bericht kwam voor het eerst om 15:27 en verschijnt 2106 malen
Failed to perform <function Controller._read at 0x7212f150> due to api.err.NoSiteContext
21:23 custom_components/unifigateway/sensor.py (WARNING) - bericht kwam voor het eerst om 15:27 en verschijnt 2104 malen
Failed to perform <function Controller._read at 0x7212f150> due to api.err.LoginRequired
18:27 custom_components/unifigateway/sensor.py (WARNING) - bericht kwam voor het eerst om 15:27 en verschijnt 2 malen
Failed to access health info: HTTPSConnectionPool(host='x.x.x.x', port=8443): Max retries exceeded with url: /api/login (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x70568ed0>: Failed to establish a new connection: [Errno 111] Connection refused'))
18:26 custom_components/unifigateway/sensor.py (ERROR)
Failed to perform <function Controller._read at 0x7212f150> due to HTTPSConnectionPool(host='x.x.x.x', port=8443): Max retries exceeded with url: /api/s/default/stat/health (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x70568b70>: Failed to establish a new connection: [Errno 111] Connection refused'))
18:26 custom_components/unifigateway/sensor.py (WARNING)
```

It looks like something with your connection to the unifi controller. Maybe it’s something with your SSL?
Try to add:
verify_ssl: true

for now , i dont use ssl

And you are using the standard port? 8443?
username/password is okay?

yes user , password , port all is ok

And you are using the IP of the device where the controller is running (cloudkey or RPI) ?
And you used an USG I hope?

The controller is running on the same device as home assistant, which is RPI
the RPI has hass.io installed
Yes i use USG lol
yes i use the ip of the RPI