Monitoring your Unifi AP

This looks great…but pretty complicated…is there any appetite to get this turned into a HACS integration? That would make this much more accessible…

9 Likes

Sorry for only replying now, not that active on this site.

I unfortunately have no idea how to get it in hacks. I basically take bits an pieces from other people and just made it work.

If there is anyone that can assist with this, please dm me.

This saved my ass from another 24 hours of troubleshooting.

TYVM

How did you guys get a total count of clients on 5G and 2.4GHz?
My sensor lists the mac addresses individually (which looks ugly in a card :slight_smile: )
image

had another read through of the thread, got it now, for others:
used w1t0lf’s repository “unifi_ap.py” GitHub - w1tw0lf/Unifi-Device-info: Unifi AP Device info via API for home assistant
and everything looks great.

TYVM all

I haven’t been able to get this working on an HAOS installation (Proxmox VM). Following one of the posts from @revin above, I ran pip install unificontrol from another server, and then copied the files to /config/python_scripts/modules. I also added the two new lines to each python script:

import sys
sys.path.append('/config/python_scripts/modules/')

Here’s my command line sensor:

  - platform: command_line
    command: 'python3 /config/python_scripts/unifi_ap_nanohd.py'
    command_timeout: 60
    name: unifi_ap
    value_template: '{{ value_json.Clients }}'
    unit_of_measurement: Clients
    scan_interval: 60
    json_attributes:
      - Guests
      - Clients_wifi0
      - Clients_wifi1
      - Score  
      - CPU
      - RAM
      - Uptime
      - Score_wifi0
      - Score_wifi1
      - Activity
      - Update

And here’s the configuration from the unifi_ap_nanohd.py file:

host = '192.168.1.3'
username = 'user'
password = 'pwd'
version = 'UDMP-unifiOS'
#### version ####
## the base version of the controller API [v4|v5|unifiOS|UDMP-unifiOS] ##
## this would be for the version of the controller you are running ##
#################
site_id = 'default'
port = '443'
verify_ssl = True
target_mac = 'xx:xx:xx:xx:xx:xx' ## the mac address of your AP device

target_mac is the actual mac, I just put xx’s here.

Here’s the errors from the log:

2022-06-15 16:25:07 ERROR (SyncWorker_4) [homeassistant.components.command_line] Command failed: python3 /config/python_scripts/unifi_ap_nanohd.py
2022-06-15 16:25:07 WARNING (SyncWorker_4) [homeassistant.components.command_line.sensor] Empty reply found when expecting JSON data

Since I’m running HAOS, I can’t run the python command from the terminal window to test this. Does anyone know where my issue might be? I have a USG with CK2.

Change this line to

verify_ssl = False

You using an ip as the host, it will fail to validate the ssl

1 Like

Thanks very much, that did it!

Would you happen to know if there’s any issue with this working on a USW Flex Mini? I had tried to add that switch first but was getting the same generic empty JSON error. Then I tried with my 16 and 24 port switches, those worked right away.

And thanks for your work on this, exactly what I was looking for.

Double check you mac address for the mini. Only thing that I can think of. I have the flex and works for me. Might also be that the mini doesn’t support it.

1 Like

Just an update for anyone else that has the Flex Mini. It doesn’t support the CPU and RAM sensors so I had to comment those out and then it worked.

Awesome, glad you managed to solve it.

This script is not working since the latest HA update:

Logger: homeassistant.components.command_line
Source: components/command_line/__init__.py:44
Integration: command_line (documentation, issues)
First occurred: 1. Juli 2022 um 18:27:37 (462 occurrences)
Last logged: 09:49:40

Command failed: python3 /config/scripts/unifi_ap.py

Any ideas how to fix this?

Not experiencing any issue on my side. On the latest version as well.

Did you perhaps change anything on unifi side, maybe changed password ?

Have you updated to a beta ? I see that python is updated to 3.10. Maybe that?

Actually not. I’m unsure what breaks the script, the HA core or UDM OS, I updated both the some days before.
Did not change anything on Unifi except OS update. Unifi DM reboot not helping.

Core 2022.6.7
Supervisor 2022.05.3
OS 8.2
Unifi Network 7.1.66
UniFi OS UDM 1.12.22

Ah ok, not sure then, still working here on 2022.6.6

Have you tried running the script from a terminal ?

I already used the terminal for other things, but I have no clue how to run a python script there.
I’d suppose it’s something with python /pathtoscript/unifi_ap.py, but the ha cli does not know this command.

Here is how I tested it.

Must have addon, portainer installed with protection mode disabled.
log in to portainer, select the container, homeassistant, open console, then run python3 /pathtoscript/unifi_ap.py

Will show you the error.

I don’t find this in the addon store.
Btw. it’s not the only python related error/warning I get since 2022.6, so I will wait for 2022.7, maybe the next update fixes this.