Control UniFi AP status LED

I recently bought a U6+ and turning on/off LED with above shell command didn’t work properly (it reset after few seconds). Also Python script didn’t work for me. This might be due to latest firmware version.
I was able to make it work with the following commands (added as shell commands to configuration.yaml)

shell_command:
  unifi_ap_led_on: ssh -o StrictHostKeyChecking=no -i ./.ssh/id_rsa USER_NAME@AP_IP "echo 1 >/proc/gpio/led_pattern ; sed -i '/mgmt.led_enabled=false/c\mgmt.led_enabled=true' /var/etc/persistent/cfg/mgmt"
  unifi_ap_led_off: ssh -o StrictHostKeyChecking=no -i ./.ssh/id_rsa USER_NAME@AP_IP "echo 0 >/proc/gpio/led_pattern ; sed -i '/mgmt.led_enabled=true/c\mgmt.led_enabled=false' /var/etc/persistent/cfg/mgmt"

Replace USER_NAME with your actual ssh user name and AP_IP with the IP address of your access point. Create an ssh key in your config/.ssh/ directory and register the public key in your Unifi Console.

Once HA is restarted, you can use service shell_command.unifi_ap_led_on or *off.

3 Likes

Hopefully this helps somebody else. I recently wanted to make it so that our upstairs AP flashes when our security is armed for an easy visual cue. I followed the guide here:

for setting up the SSH keys but I didn’t see anywhere else that if you are running a Unifi controller you have to copy and paste your public key into the controller by logging in and going to Settings > System > Advanced tab > paste your pub key to the SSH keys section of device authentication.

I was able to get the device to flash by using the SSH commands given in this thread but I didn’t like the fact that in order for it to flash I was having to continuously send it commands and authenticating.

I didn’t see anybody else that did this so I made a few scripts, one that automatically checks and then creates the flashing script prior to running, the actual script itself, and then one that kills the script from running on the AP.

The reason for the first script is that even though the directory is called persistent, anything in it is wiped out after a reboot. Here are the scripts I used and if anybody found a better way of doing this feel free to let me know :stuck_out_tongue:

Config file:

shell_command:
  u6lr_blue: ssh -i /config/.ssh/id_rsa -o 'StrictHostKeyChecking=no' <USER>@<AP IP or HOSTNAME> 'echo -n 0,0,255 > /proc/ubnt_ledbar/custom_color'
  u6lr_color_change_script_create: ssh -i /config/.ssh/id_rsa -o 'StrictHostKeyChecking=no' <USER>@<AP IP or HOSTNAME> 'test -e /etc/persistent/scripts/colorchange.sh || (mkdir -p /etc/persistent/scripts && echo -e "#!/bin/ash\n\nwhile true; do\n    echo -n 255,0,0 > /proc/ubnt_ledbar/custom_color\n    sleep 1\n    echo -n 255,255,255 > /proc/ubnt_ledbar/custom_color\n    sleep 1\ndone" > /etc/persistent/scripts/colorchange.sh && chmod +x /etc/persistent/scripts/colorchange.sh)'
  u6lr_color_change_script_run: ssh -i /config/.ssh/id_rsa -o 'StrictHostKeyChecking=no' <USER>@<AP IP or HOSTNAME> 'nohup /etc/persistent/scripts/colorchange.sh &'
  u6lr_kill_color_change_script: ssh -i /config/.ssh/id_rsa -o 'StrictHostKeyChecking=no' <USER>@<AP IP or HOSTNAME> 'pkill -f "/etc/persistent/scripts/colorchange.sh"'

Automation action I used:

action:
  - if:
      - condition: trigger
        id:
          - "1"
    then:
      - service: shell_command.u6lr_color_change_script_create
        data: {}
      - service: shell_command.u6lr_color_change_script_run
        data: {}
  - if:
      - condition: trigger
        id:
          - "2"
    then:
      - service: shell_command.u6lr_kill_color_change_script
        data: {}
      - service: shell_command.u6lr_blue
        data: {}
mode: single

Feel free to edit the config for whatever color / delay you need. I made it so that when the house is armed it runs the first command which creates the script and then runs the newly created script. When the house is disarmed it kills the script and returns the normal color back to blue. I attempted to do it with two commands using && or ; but the AP just refused to run multiple commands in sequence.

For anyone wandering in here, wondering why they can’t get the LED color to persist, here’s what I did wrong for many attempts.

  1. The payload written down by @FPro seems to be up to date for me, on 6.6.65 on an AP AC Lite.
  2. HOWEVER, go to your Unifi console and make sure that the AP LED you want to modify via SSH is actually turned on there:
    grafik
    I had that box unchecked. This led (haha) to the LED being deactivated after ten seconds.
    Now I have that box checked, and the LED reacts exactly as I’d expect it to.

Thanks god this work for my U6+ too!

I just added this plugin via homebridge via homekit.

Would love for this to be added to the native Unifi Integration.

1 Like

Any update on controlling the LED with Unifi Network v9?

Can we enable / disable etherlighting on unifi Switch Pro POE via SSH and then Home Assistant?

So using some of the info on this post and other places I am able to control the Unifi E7 AP RGB LEDs:

From the ‘Advanced SSH & Web Terminal’ Add-On (Protection mode: Off) I ran:
docker exec -it homeassistant bash
ssh-keygen -t rsa -b 2048
set identity location to /config/.ssh_unifi/id_rsa ( or anywhere in the /config dir, just need to call it out in the ssh command with -i)
In the Unifi Controller under ‘controller/settings/system/advanced/ssh keys’ add add contents of the /.ssh_unifi/id_rsa.pub file.

In my configuration.yaml I have:
shell_command: !include shell_command.yaml

In the shell_command.yaml I added this: (had to full restart HA to get them to show up)

# AP-MASTER LED Colors
  ap_master_led_red: ssh -i /config/.ssh_unifi/id_rsa -o 'StrictHostKeyChecking=no' admin@ap-master 'echo -n 255,0,0 > /proc/ubnt_ledbar/color'
  ap_master_led_green: ssh -i /config/.ssh_unifi/id_rsa -o 'StrictHostKeyChecking=no' admin@ap-master 'echo -n 0,255,0 > /proc/ubnt_ledbar/color'
  ap_master_led_blue: ssh -i /config/.ssh_unifi/id_rsa -o 'StrictHostKeyChecking=no' admin@ap-master 'echo -n 0,0,255 > /proc/ubnt_ledbar/color'
  ap_master_led_white: ssh -i /config/.ssh_unifi/id_rsa -o 'StrictHostKeyChecking=no' admin@ap-master 'echo -n 255,255,255 > /proc/ubnt_ledbar/color'
  ap_master_led_off: ssh -i /config/.ssh_unifi/id_rsa -o 'StrictHostKeyChecking=no' admin@ap-master 'echo -n 0,0,0 > /proc/ubnt_ledbar/color'
# AP-MASTER LED Brightness
  ap_master_led_bright_100: ssh -i /config/.ssh_unifi/id_rsa -o 'StrictHostKeyChecking=no' admin@ap-master 'echo -n 255 > /proc/ubnt_ledbar/brightness'
  ap_master_led_bright_75: ssh -i /config/.ssh_unifi/id_rsa -o 'StrictHostKeyChecking=no' admin@ap-master 'echo -n 192 > /proc/ubnt_ledbar/brightness'
  ap_master_led_bright_50: ssh -i /config/.ssh_unifi/id_rsa -o 'StrictHostKeyChecking=no' admin@ap-master 'echo -n 128 > /proc/ubnt_ledbar/brightness'
  ap_master_led_bright_25: ssh -i /config/.ssh_unifi/id_rsa -o 'StrictHostKeyChecking=no' admin@ap-master 'echo -n 64 > /proc/ubnt_ledbar/brightness'
  ap_master_led_bright_1: ssh -i /config/.ssh_unifi/id_rsa -o 'StrictHostKeyChecking=no' admin@ap-master 'echo -n 3 > /proc/ubnt_ledbar/brightness'
# AP-MASTER LED Breath
  ap_master_led_breath_on: ssh -i /config/.ssh_unifi/id_rsa -o 'StrictHostKeyChecking=no' admin@ap-master 'echo -n 1 > /proc/ubnt_ledbar/breath'
  ap_master_led_breath_off: ssh -i /config/.ssh_unifi/id_rsa -o 'StrictHostKeyChecking=no' admin@ap-master 'echo -n 0 > /proc/ubnt_ledbar/breath'

Can create a command for any of the 16777216 colors just specifying the RGB color codes in the 255,0,0 part of the commands.

Hopefully this can be added to the HA integration or via the API

1 Like

I setup some commands to change the brightness of the etherlighting
I have to run ‘desk_pro_max_led_brightness_1’ followed by ‘desk_pro_max_led_config_set’

  desk_pro_max_led_brightness_1: ssh -i /config/.ssh_unifi/id_rsa -o 'StrictHostKeyChecking=no' admin@USW-PRO-MAX-16-PoE 'echo 1 > /proc/led/led_brightness'
  desk_pro_max_led_brightness_50: ssh -i /config/.ssh_unifi/id_rsa -o 'StrictHostKeyChecking=no' admin@USW-PRO-MAX-16-PoE 'echo 50 > /proc/led/led_brightness'
  desk_pro_max_led_brightness_100: ssh -i /config/.ssh_unifi/id_rsa -o 'StrictHostKeyChecking=no' admin@USW-PRO-MAX-16-PoE 'echo 100 > /proc/led/led_brightness'
  desk_pro_max_led_config_set: ssh -i /config/.ssh_unifi/id_rsa -o 'StrictHostKeyChecking=no' admin@USW-PRO-MAX-16-PoE 'echo 2 > /proc/led/led_config'

I also saw I could read and set some of the of the other values but didn’t see to directly turn etherlighting off or change the mode

cat /proc/led/led_etherlight_mode #(seems to be read only)
0=speed 1=vlan

cat /proc/led/led_config
Config LED: [0=Cold reset 1=Warm reset 2=Boot done]
while ssh'd to the switch run these commands
echo 0 > /proc/led/led_config
echo 1 > /proc/led/led_config
echo 2 > /proc/led/led_config

I used the info above to to create a scripts that I use in an automation as an action:

sequence:
  - action: shell_command.desk_pro_max_led_brightness_1
    metadata: {}
    data: {}
  - action: shell_command.desk_pro_max_led_config_set
    metadata: {}
    data: {}
alias: Desk Switch LEDs - OFF
description: ""