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"