Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.
/ unifi-led-api Public archive

An unofficial Python API to control LED status on UniFi devices (access points) via the UniFi Device REST API.

License

Notifications You must be signed in to change notification settings

elNino0916/unifi-led-api

Repository files navigation

Python Version UniFi OS UniFi Network

Note

This project is no longer actively maintained. The same functionality can now be easily achieved using the official Home Assistant UniFi integration.

image

Control UniFi Access Point LEDs via internal API — perfect for night mode scheduling and automation.

UniFi has never implemented a proper night mode scheduler for Access Points — despite users requesting it for years. This project fills that gap with a lightweight, reliable Python-based API that sends PUT requests to the internal REST API of the AP. Tested on U7 Pro and U6+.

Note

This project might seem very hard to set up at first, but if set up correctly, it should not be that hard anymore to maintain. Refer to the wiki for more information here. Consider opening an issue if you need help.

Note

Modern UniFi APs (U6/U7 series) support LED override ON/OFF only.
Color and brightness overrides are ignored by firmware.

Features

  • Turn device LEDs on or off programmatically
  • Works with UniFi OS and legacy controllers
  • Simple command-line interface
  • Configurable via environment variables
  • Suitable for cron jobs and automation

Why this does NOT use SSH

Many existing UniFi LED control solutions rely on SSH access to the access point and manual modification of LED-related settings or scripts.

⚠️ SSH-based approaches have been observed to cause firmware corruption and device instability, sometimes requiring recovery via TFTP.

UniFi access points are not designed for persistent or repeated SSH access. Running SSH-based automation can:

  • Increase CPU and memory usage on the AP
  • Interfere with UniFi’s internal configuration management
  • Cause device instability, reprovisioning loops, or unexpected reboots
  • Break silently after firmware updates

This project avoids SSH entirely and instead uses the same internal REST API mechanism the UniFi controller itself uses to manage device configuration. As a result, it is significantly more stable, safer, and closer to how UniFi intended devices to be managed. This makes it suitable for long-term automation, cron jobs, and unattended operation.

Requirements

  • Python 3.6+
  • requests library
  • A UniFi Controller with API access
  • A local UniFi user account (no 2FA)

Installation

  1. Clone this repository:

    git clone https://github.com/elNino0916/unifi-led-api.git
    cd unifi-led-api
  2. Install dependencies:

    pip3 install requests

Configuration

Instructions can be found in the wiki.

Usage

Turn LED On

source set_env.sh
python3 start.py led on

Turn LED Off

source set_env.sh
python3 start.py led off

Inline Environment Variables

UNIFI_USER=USERNAME UNIFI_PASS='PASSWORD' UNIFI_CONTROLLER='https://192.168.1.1' UNIFI_DEVICE_ID='your_device_id' python start.py led off

Cron Example

Turn off LEDs every night at 10 PM:

0 22 * * * bash -c 'source /path/to/set_env.sh && /usr/bin/python3 /path/to/start.py led off'

Turn on LEDs every morning at 7 AM:

0 7 * * * bash -c 'source /path/to/set_env.sh && /usr/bin/python3 /path/to/start.py led on'

LED Payload Configuration

The led_on.json and led_off.json files contain the device configuration payloads. You need to customize these files to match your device settings:

  • led_override: "on" or "off"
  • led_override_color: LED color in hex format (e.g., "#0000ff") (Only older APs)
  • led_override_color_brightness: Brightness percentage (e.g., "100") (Only on some newer APs if it even works in the first place.)

Caution

Do NOT modify anything in the JSON files except the LED fields.
Changing other values can break your device configuration.

Troubleshooting

Authentication Issues

  • Ensure you're using a local UniFi account, not a Ubiquiti cloud account
  • The account should not have 2FA enabled
  • Check that the controller URL is correct and accessible

SSL Certificate Errors

If you're using a self-signed certificate, set UNIFI_VERIFY_SSL=false

CSRF Token Errors

The API automatically handles CSRF tokens. If you encounter issues, ensure your controller is running a compatible version.

Other errors / config changes

You have not updated your json files after a config change / update. Please check out Step 1 to recreate the json files.

License

This project is provided under the MIT License.

Disclaimer

This project is an unofficial tool and is not affiliated with, endorsed by, or supported by Ubiquiti Inc. or any of its subsidiaries in any way. This software interacts with internal and undocumented UniFi controller and access point APIs, which are subject to change without notice. As a result, functionality may break at any time due to firmware updates, controller updates, configuration changes, or other modifications made by Ubiquiti. Use this tool only if you understand what it does and have verified it in a safe or non-production environment first. If you are unsure whether this tool is appropriate for your setup, do not use it.