First, you’ll need to get SSH access to your server: https://support.hostifi.net/en/articles/3437198-how-to-ssh-or-sftp-into-your-unifi-server
Log in via SSH, then use wget to download the script from GitHub:
Run the script:
It will output the UniFi device count to the terminal.
Alternatively, you can check UniFi device count from network.unifi.ui.com: