Hi shbatm this is amazing! I’ve been having so many issues with random macs showing up and the Tier 3 at UniFi was not very helpful. I’m running the latest version for everything right now but unfortunately I’m not very familiar on how to implement your script. Would you be kind to share like a step-by-step tutorial so I can add the script to the Cloud controller and automated? Let me know if you can help.
Error is: Traceback (most recent call last):
File “/home/pi/Desktop/purge_clients.py”, line 13, in
cloud_key_ip=cloud_key_ip, controller_port=controller_port
IndexError: tuple index out of range
I had to modify your script because I am running on the UDM-Base (’/api/auth/login’ for login, ‘/proxy/network’ added in front of the other API calls). I am able to retrieve macs, but when I call the
Traceback (most recent call last):
File "/Users/mieszko/GitHub/unifi-cleanup/unifi-cleanup.py", line 2, in <module>
import asyncio,async_timeout
ModuleNotFoundError: No module named 'async_timeout'
After installing the missing dependency (pip3 install async_timeout) it fails with:
Starting aioUniFi
Traceback (most recent call last):
File "/Users/mieszko/GitHub/unifi-cleanup/unifi-cleanup.py", line 106, in <module>
asyncio.run(
~~~~~~~~~~~^
main(
^^^^^
...<5 lines>...
)
^
)
^
File "/opt/homebrew/Cellar/[email protected]/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/runners.py", line 195, in run
return runner.run(main)
~~~~~~~~~~^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete
return future.result()
~~~~~~~~~~~~~^^
File "/Users/mieszko/GitHub/unifi-cleanup/unifi-cleanup.py", line 59, in main
controller = await unifi_controller(
^^^^^^^^^^^^^^^^^^^^^^^
...<8 lines>...
)
^
File "/Users/mieszko/GitHub/unifi-cleanup/unifi-cleanup.py", line 14, in unifi_controller
controller = aiounifi.Controller(
host,
...<6 lines>...
callback=callback,
)
TypeError: Controller.__init__() got an unexpected keyword argument 'username'
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x106bbb380>
sorry @spitf1r3 , looks like aiounifi has diverged too much, and it’s more than just a quick fix. i believe the home assistant unifi integration has some sort of option to not include these entities now, though? i recall seeing some option to “filter phantom (or something) clients” the last time i added the unifi integration, and i don’t see these any more
Well for now I’ve removed the integration (with 17000 entities!) and re-added it which fixed the issue (I was conservative with enabling the options now). For some reason I’ve seen 3000 (!) devices with some random MAC addresses (most of them starting with 00:00:00:00:00:00) and no IPs/zero traffic. I have no idea where they came from. I was hoping I could get rid of them in Unifi’s UI too.