Control UniFi AP status LED

I wanted a way to control the light on my Ubiquiti access point from Home Assistant.
Since it’s not entirely straightforward, here’s a write-up of how I got it to work.

I got it to work by creating a a shell_command entity which uses SSH to connect to the AP and edit a config file there. Changes you make to the AP over SSH are not persistent, so if something unexpected happens, you can just reboot the AP.

You’ll need to make sure your Home Assistant instance can connect to your AP over SSH. I generated an SSH key pair on my local computer and added the public key in the AP’s setting on the UniFi controller under “Device Authentication”. I’m running HA in Docker, so in order to add the private key, I had to enter the container and paste it in /root/.ssh/id_rsa. Make sure you run chmod 600 /root/.ssh/id_rsa as well, for the right permissions. Still in the container I tested if I could SSH to the AP (you’ll have to do this at least once, to accept the new SSH host).

The next step is to add the command to change the status LED to Home Assistant. I used the following config:

shell_command:
  unifi_led_off: >-
    ssh [email protected] "sed -i '/mgmt.led_pattern_override/d' /var/etc/persistent/cfg/mgmt 
    && echo 'mgmt.led_pattern_override=0' >> /var/etc/persistent/cfg/mgmt"
  unifi_led_blue: >-
    ssh [email protected] "sed -i '/mgmt.led_pattern_override/d' /var/etc/persistent/cfg/mgmt
    && echo 'mgmt.led_pattern_override=1' >> /var/etc/persistent/cfg/mgmt"
  unifi_led_white: >-
    ssh [email protected] "sed -i '/mgmt.led_pattern_override/d' /var/etc/persistent/cfg/mgmt 
    && echo 'mgmt.led_pattern_override=2' >> /var/etc/persistent/cfg/mgmt"
  unifi_led_whiteblue: >-
    ssh [email protected] "sed -i '/mgmt.led_pattern_override/d' /var/etc/persistent/cfg/mgmt 
    && echo 'mgmt.led_pattern_override=3' >> /var/etc/persistent/cfg/mgmt"

You’ll need to change the “[email protected]” to the username and IP address of your AP.
I figured out how to change the status light from the command line thanks to this thread: https://community.ui.com/questions/Change-LED-brightness-or-color/cc7c4fc9-6c4a-4913-960b-130a0bb44fc4

Final note: The light on your AP will not change instantly, but after a couple of seconds.

EDIT: Found a way to make the change instant, by adding another line to the command:

shell_command:
  unifi_led_blue: >-
    ssh [email protected] "echo '1' >/proc/gpio/led_pattern
    && sed -i '/mgmt.led_pattern_override/d' /var/etc/persistent/cfg/mgmt 
    && echo 'mgmt.led_pattern_override=0' >> /var/etc/persistent/cfg/mgmt"

The line echo '1'>/proc/gpio/led_pattern changes the the pattern to 1 instantly, but the change only lasts a few seconds. By chaining the commands, the light changes instantly and then keeps its state by adding it to /var/etc/persistent/cfg/mgmt .

EDIT 2: With the latest firmware version of my AP, I found I only needed the first half of the command, like this:

shell_command:
  unifi_led_blue: >-
    ssh [email protected] "echo '1' >/proc/gpio/led_pattern"
8 Likes

Awesome !
I posted asking if there was a way to pull how many clients are connected to the AP, as my 2.4 randomly drops chasing all my sensors and lights stop working.

I could use this to alert me when key sensors/lights drop, can you also set the brightness ?

Unfortunately there’s no way to change the brightness, as far as I know.

You can create patterns for your alerts. For instance, changing the value to mgmt.led_pattern_override=012, will cycle the LED off, blue, white.

And here’s a YAML snippet that I used to easily test out different patterns from the UI:

shell_command:
  unifi_led_pattern: >-
    ssh [email protected] "echo '{{ states('input_text.unifi_led_pattern') }}' >/proc/gpio/led_pattern"

input_text:
  unifi_led_pattern:
    name: Change Pattern
    initial: '1'

script:
  unifi_led_pattern:
    alias: UniFi LED Pattern
    sequence:
      - service: shell_command.unifi_led_pattern

2 Likes

Hi @Roman, I recently updated firmware on my nanoHD AP that seems to have broken my ability to turn on/off the LED and keep the change persisting. Is your process still working?

Yeah, it still works for me, using
echo 1 >/proc/gpio/led_pattern

I’m using an AP Lite, firmware 4.3.24.11355.

Thanks. This happened on new 5.43.19.12493. Downgraded to 4.3.21.11325 and all is well again. Seems to be a lot of users with issues on the release thread on the Ubiquiti forum. Not necessarily regarding the LED though.

i have udm with version 1.8.5. apparently there is no /var/etc forlder, and no sed program. and first command is not persistent. do you know any solution yet?

SOmeone tried this : https://github.com/patagonaa/homeassistant-unifi-led I cannot build it… it fails see issue:

This issue has been closed :slight_smile: works really nice. Now I can control the LEDs of each AP in my setup :slight_smile:

@Roman - Nice! Works like charm. Any thoughts on how one could use this approach to enable/disable an access point via SSH? I.e. to turn off the radios.

You can disable POE output from switch, directly from homeassistant gui, if thats an option for you.

Anyway, can someone update script for release 5.43.XX ?
No “/var/etc/persistent/” path in ssh =/

Just got this working on my 5.43
change /var/etc/persistent/cfg/mgmt
to
/etc/persistent/cfg/mgmt

1 Like

Hi all,

Has anyone had any joy with this working with the latest firmware?

I can’t get it to stay persistent :frowning:

I have tried all the above suggested methods but none of them make the action stick.

I got it working in 5.60.19 on AP 6 Lite with those commands:

"echo 1 >/proc/gpio/led_pattern && echo mgmt.led_pattern_override=1 >> /var/etc/persistent/cfg/mgmt"

Is there someone who was able to integrate the different colors/effects into a template light?
Currently I use an input select in combination with a template light (off → shell command with parameter 0, on → shell command with parameter input select state).
2021-11-25_10h04_30

In template lights you can set effect lists and trigger effect changes but can’t get it to work. Any ideas?

works for me too, but only for the access points. i need it for the dreammachine too.
on the usg on/off works but not staying is there any different path?

I created python script to control “location blinking” mode. Calling it using

shell_command:
  unify_ap_locate_on: python3 python_scripts/unify_ap_led_control.py
  unify_ap_locate_off: python3 python_scripts/unify_ap_led_control.py --off

My usage is that when nobody is home (based on device connection to AP) and motion is detected then it starts blinking to “emulate” warning light to possibly scare away possible intruder. Also to remind me my device didn’t connect to WiFi yet and thus other security measures are ON.

Mine broke… I’m guessing that it was after a firmware update, or a controller update. This command is now working:

ssh -o UserKnownHostsFile=/config/.ssl/known_hosts -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa -i /config/.ssl/unifi_ap_id_rsa [email protected]

Awesome, thanks for these SSH commands! I set up some flows with switch entities in Node-RED, and turned them into lights in Home Assistant.


Not sure what I’ll do with these. Will probably just turn them off at night and leave them on during the day. But mostly just because I’m a completionist and want to automate as much as possible.

So coming in a bit later here in this thread and I know there have been quite a few updates since these posts. Is anyone able to confirm if this is still working? I’ve attempted as the first post says just the one liner, but the config gets reset pretty quickly (within about 5 secs max). I then tried adding the mgmt.led_patther_override=1 into the persistent config, and it had no affect on the reset. So it would seem there is some other mechanism resetting/altering this led config. Was hoping to use this as a subtle notifier in the house, but can’t seem to make the config stick at all.

Just try to test the python script but it is not working for me, but this is my first run of python script in HA.