This is a small guide to set up Unifi AP LED Control using Home Assistant.
These scripts have been tested as working on the following hardware:
- U7 Pro FW version 8.0.19
- U6 Lite FW version 6.6.77
- UAP AC Mesh FW version 6.6.78
My Home Assistant setup runs in docker compose (see setup guide) and so this doc is written with that in mind.
I have stored my home assistant config in /opt/homeassistant
, and so my docker compose file is at /opt/homeassistant/docker-compose.yaml
. All paths mentioned in this tutorial assume this setup, but you should alter it to match your filesystem configuration.
These commands use ssh to connect to each AP in order to configure them. With this in mind, we must do a little bit of legwork to get our ssh configured.
My approach to this has been to generate keys outside of home assistant and mount them inside, this ensures that the keys survive a rebuild of the home assistant container.
First, we must create a directory and generate ssh keys in said folder. Perform this command on the container host itself:
mkdir /opt/homeassistant/dotssh
ssh-keygen -t rsa -f /opt/homeassistant/dotssh/id_rsa
Next, we must set up the config for each access point, referencing the below ssh_config file, create a file at /opt/homeassistant/dotssh/config
with each Access Point that you want to connect to, including the SSH user defined in the Unifi Network Application (see Unifi Network Application settings for further details).
You should now have a folder with content as follows:
dotssh
|-- config
|-- id_rsa
`-- id_rsa.pub
Next we must mount this directory in the home assistant container, see Mounting SSH Directory.
Now an SSH key has been generated, we must mount the ssh config in home assistant such that it uses these credentials to connect to access points. See the volumes
key in docker-compose.yaml. The folder should be mounted within the home assistant container at /root/.ssh
.
See the shell_command
key in configuration.yaml. Two shell commands are included, one to control LEDs, the other to reboot the access point, both use ssh to connect.
See scripts.yaml. These scripts use the shell_command
keys defined in configuration.yaml to manage the LEDs on your AP. You should adjust this to your liking by replacing the names of my access points (e.g. garage.mydomain.mytld) with your own hostname or IP address.
See automations.yaml. These automations depend on the sun & meteoalarm home assistant integrations for LED scheduling & Weather Warning alerts respectively, you must install and configure these integrations for your location before copying any of these automations.
I do not recommend blindly merging these automations with your own, as I cannot guarantee the IDs wont collide. Instead, I recommend using the Automation Editor, then at the top-left click the three-dot menu & choose 'Edit in YAML'. You can then copy each automation you would like by copying one, removing it's ID & de-indenting, e.g.:
- id: '1742025250691'
alias: Wifi pre-dawn
description: ''
triggers:
- event: sunrise
offset: -01:00:00
trigger: sun
conditions: []
actions:
- action: script.unifi_led_white
data: {}
Becomes:
alias: Wifi pre-dawn
description: ''
triggers:
- event: sunrise
offset: -01:00:00
trigger: sun
conditions: []
actions:
- action: script.unifi_led_white
data: {}
Finally we need to add the public key from the SSH Config section to our Unifi Application. Copy the contents of dotssh/id_rsa.pub
to your clipboard, and follow this UI Knowledgebase article to trust this new key. Additionally, ensure the ssh user is configured to match the usernames defined in dotssh/config
.
Before testing any automations, we should make sure that home assistant can successfully connect to our access point. Referencing a Host
defined in dotssh/config
, we can get a shell in our container and attempt to ssh to one of our access points:
docker exec -it homeassistant bash
ssh garage.mydomain.mytld
This should then launch a shell on your access point like so:
BusyBox v1.25.1 () built-in shell (ash)
___ ___ .__________.__
| | |____ |__\_ ____/__|
| | / \| || __) | | (c) 2010-2023
| | | | \ || \ | | Ubiquiti Inc.
|______|___| /__||__/ |__|
|_/ https://www.ui.com
Welcome to UniFi UAP-AC-Mesh!
********************************* NOTICE **********************************
* By logging in to, accessing, or using any Ubiquiti product, you are *
* signifying that you have read our Terms of Service (ToS) and End User *
* License Agreement (EULA), understand their terms, and agree to be *
* fully bound to them. The use of SSH (Secure Shell) can potentially *
* harm Ubiquiti devices and result in lost access to them and their data. *
* By proceeding, you acknowledge that the use of SSH to modify device(s) *
* outside of their normal operational scope, or in any manner *
* inconsistent with the ToS or EULA, will permanently and irrevocably *
* void any applicable warranty. *
***************************************************************************
Garage-BZ.6.6.77#