As you may or may not know by now, I am passionate Unifi user, and all of my networking equipment is based on their products. Recently, my son told me that LED light that was coming from LR Access Point mounted on the hallway wall is bothering him during night and that he can not sleep.
Of course, that was just lame attempt to not go to sleep 🙂 , but it got me thinking that it would definitely be cool feature to have in Unifi controller. My controller is running in Ubuntu virtual machine in Azure, so this was a case of creating two scripts that would use Cron to run and turn off and on all LED light on all APs.
My controller is set up to control LED status of all devices and devices are set up to obey controllers settings.
After some time on tinkering and searching I came up with viable solution that works, until UBQT exposes it in GUI of the controller. You can vote for this feature here.
Script to turn OFF LED lights:
#!/bin/sh
username=Admin username
password=Admin password
baseurl=https://localhost:8443
site=default
cookie=/tmp/unifi_cookie
curl_cmd="curl --tlsv1 --silent --cookie ${cookie} --cookie-jar ${cookie} --insecure "
${curl_cmd} --data "{'username':'$username', 'password':'$password'}" $baseurl/api/login
${curl_cmd} --data "{ 'led_enabled': false}" $baseurl/api/s/$site/set/setting/mgmt
Script to turn ON LED lights:
#!/bin/sh
username=Admin username
password=Admin password
baseurl=https://localhost:8443
site=default
cookie=/tmp/unifi_cookie
curl_cmd="curl --tlsv1 --silent --cookie ${cookie} --cookie-jar ${cookie} --insecure "
${curl_cmd} --data "{'username':'$username', 'password':'$password'}" $baseurl/api/login
${curl_cmd} --data "{ 'led_enabled': true}" $baseurl/api/s/$site/set/setting/mgmt
Notice the only difference is in line 12, true or false. If you want this to run on your first created site, value for variable site should default. If you want it to run on different site in controller, use site name for value.
I have created two files on Ubuntu and saved them as .sh so they can be executed. Nano is my preferred editor although I have been seen using vi editor in extreme situations :).
Do not forget to use chmod command so the file can be executed.
chmod +x filename.sh
After that, by simple editing Crontab with
Crontab -e
and adding these lines in it
0 21 * * * /PathToYourFiles/unifi_led_disabled.sh >/dev/null 2>&1
0 8 * * * /PathToYourFiles/unifi_led_enabled.sh >/dev/null 2>&1
I have scheduled LED lights to go off every day at 21:00 and to turn on every day at 08:00.
If you are not familiar with Cron syntax I can recommend you this easy to use online Cron generator. For some of these action you will need root privileges. Script can also be set at user level instead of root which is the recommended way.
Scripts could definitely be modified to turn on or off selected APs and not all of them, but I do not have that many so this works for me. Feel free to comment and add your input.
Does this method still work?
To be honest I did not re-test this. I do not see a reason that it should not work.
Thanks for the script, any idea why why the login call could fail ? anything obvious that I’m missing is welcome as I’m a noob here (well, besides username and password being wrong 🙂 )
sorry I even forgot to give you the error:
{“meta”:{“rc”:”error”,”msg”:”api.err.Invalid”},”data”:[]}
Hi, sudo as root and try the script manually. If that works than the issue may be crontab. It is also possible that some Unifi Controller update changed some API calls. 🙁
It seems I’ve somehow nailed it down and I don’t know exactly how, but still can be useful to share.
I’ve swapped the double tick ” and the single ‘ in the json body as below:
${curl_cmd} –data ‘{“username”:”myusername”,”password”:”mypassword”}’ $baseurl/api/login
${curl_cmd} –data ‘{“led_enabled”: false}’ $baseurl/api/s/$site/set/setting/mgmt
and then replaced variable $username and $password with their value, since I don’t know how to escape in bash.
I’ve experienced the same behavior on both my Linux-On-Windows bash and the resinOs on my raspberry with hass.io
Thanks for helping!
Thank you Marco for your contribution!
Does it needs a controller to be online always ?
Yes. It is run on controller.
Never had the blue light turn off. After the firmware update the blue led turned off at 10 pm. It was distressing as it was always on so we restated. Cleaned it. The next night it turned off so I unplugged and air dusted. Finally I found this article and realized this probably swayed them to make a blanket assumption everyone want the light off. We feel the blue light is assurance its working. Otherwise the dream machine is dark and silent without fan giving no indication its on.
I write this in hopes another novice like myself searching for answers about the LED that has been on for years and is now a forced timer that turns off leaving the dream machine seemingly dead but it’s not.