Skip to content

Instantly share code, notes, and snippets.

@UBNT-cmb
Created March 8, 2018 05:25
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UBNT-cmb/7bbb329db577ee84067de3d42ff9f438 to your computer and use it in GitHub Desktop.
Save UBNT-cmb/7bbb329db577ee84067de3d42ff9f438 to your computer and use it in GitHub Desktop.
Enable UniFi LED
#!/bin/sh
username=username
password=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
@ryanschmidt
Copy link

This stopped working with a recent UniFi update. Any idea why?

@JacekDob
Copy link

#!/bin/sh

username=username
password=password
baseurl=https://ip:8443
site=default
device=$2
cookie=/tmp/unifi_cookie
state=$1

if [ $# == "0" ]; then
        echo "site configuration:"
        echo "USAGE: $0 true|false"
        echo "or device configuration:"
        echo "USAGE: $0 on|off|default deviceId"
        exit 1
fi

curl_cmd="curl --tlsv1 --silent --cookie ${cookie} --cookie-jar ${cookie} --insecure "
${curl_cmd} --data "{\"username\":\"$username\", \"password\":\"$password\"}" $baseurl/api/login

if [ "$#" -eq "2" ]; then
        ${curl_cmd} -X PUT --data "{\"led_override\":\"$state\"}" $baseurl/api/s/$site/rest/device/$device
elif [ "$#" -eq "1" ]; then
        ${curl_cmd} --data "{\"led_enabled\":\"$state\"}" $baseurl/api/s/default/set/setting/mgmt/
fi

@jokerigno
Copy link

#!/bin/sh

username=username
password=password
baseurl=https://ip:8443
site=default
device=$2
cookie=/tmp/unifi_cookie
state=$1

if [ $# == "0" ]; then
echo "site configuration:"
echo "USAGE: $0 true|false"
echo "or device configuration:"
echo "USAGE: $0 on|off|default deviceId"
exit 1
fi

curl_cmd="curl --tlsv1 --silent --cookie ${cookie} --cookie-jar ${cookie} --insecure "
${curl_cmd} --data "{"username":"$username", "password":"$password"}" $baseurl/api/login

if [ "$#" -eq "2" ]; then
${curl_cmd} -X PUT --data "{"led_override":"$state"}" $baseurl/api/s/$site/rest/device/$device
elif [ "$#" -eq "1" ]; then
${curl_cmd} --data "{"led_enabled":"$state"}" $baseurl/api/s/default/set/setting/mgmt/
fi

Hi @JacekDob,

I tried to run this script but nothing changes. Does it still work?

@JacekDob
Copy link

For me it works, but I'm using 6.0.36 version.

@JacekDob
Copy link

I tried also 6.1.71 and it is still working.

@jokerigno
Copy link

Great!

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