Skip to content

Instantly share code, notes, and snippets.

@jak119
Created April 6, 2020 14:35
Show Gist options
  • Save jak119/ecbe9c6113675ce666cc3d06dbf3fbdf to your computer and use it in GitHub Desktop.
Save jak119/ecbe9c6113675ce666cc3d06dbf3fbdf to your computer and use it in GitHub Desktop.
Schedule turning on / off the LED on a Unifi APs

How to schedule LED on / off for Unifi APs

Inspired by this blog post but found the scipt didn't work quite right because it used single quotes (') instead of double inside the JSON body. The tweaked scripts look like this:

Turn On

#!/bin/sh

username=admin
password=changeme
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

Turn Off

#!/bin/sh

username=admin
password=changeme
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

The rest of the post is still accurate and I encourage you to check it out for more details on exactly how to schedule using cron.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment