You learn with this How To Install UniFi on OpenHABian how you can get the UniFi Controller running on your OpenHAB 3 openhabian Raspberry. If you have the UniFi Controller on your OpenHAB system running, then it allows you to better combine with your Homeautomation. You have both, the strength of the UniFi controller and OpenHAB in one. No additional energy consumption, no additional maintenance, etc. for you. If you leverage on a strong Raspberry 4, then this should be running really smooth. In my case it runs really smooth! I like to say I have quite a complex OpenHAB SmartHome solution.
Index:
- Background
- How To Install UniFi Controller on OpenHABian
- Additional Information
Background
For this how to I am leveraging on the following infrastructure:
- Raspberry Pi 4 8GB
- OpenHAB 3 Openhabian
- Corsair USB 512GB USB stick which had in several benchmarks that I found in the Internet a great performance
I do not use a SD card for my Raspberry Pi 8GB.
How to Install UniFi Controller on OpenHABian
To get the UniFi Controller running on your Raspberry with openhabian on it is actually quite simple, but it requires you to execute a couple of installation steps. You will be able to install the UniFi Controller by the below step by step guide.
Update the system
Get your Raspi updated by executing the necessary commands
sudo apt update && sudo apt full-upgrade -y && sudo apt autoremove -y && sudo apt-get autoclean -y
Install Java openjdk 8 – next to Java openjdk 11
The Unifi Controller requires JDK 8 (as of June 2022). Since this is pre-installed with openhabian that most likely is JDK 11, you will have to action. Should this change in the future, you do not need to install anything on for JDK. To run Java JDK 8 and 11 in parallel, execute the following:
sudo apt update sudo apt install openjdk-8-jdk sudo update-alternatives --config java
You set the default Java version to 11:
/usr/lib/jvm/java-11-openjdk-armhf/bin/java
Next step, you set now the Java Home Path (JAVA_HOME). For this, you should note down what the next command is telling you:
sudo update-alternatives --config java
Now lets set the environment paths. You edit the /etc/environment file.
sudo nano /etc/environment
You add the following line. By this JDK 11 is the default version
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-armhf/bin/java"
To ensure all is fine, you do
sudo reboot
After reboot you check whether your configuration is correct:
echo $JAVA_HOME
Install MongoDB
Also the UniFi Controller needs Mongo DB. Depending on your OpenHAB installation, you maybe have not installed MongoDB. If you haven’t, you like to get it installed.
You most likely will find out that the MongoDB package is not available in the official OpenHAB 3 openhabian repository. For this reason we add it in a first step.
echo "deb http://archive.raspbian.org/raspbian buster main contrib non-free rpi" | sudo tee /etc/apt/sources.list.d/raspbian-archive.list sudo apt update
Once you have available the package, you continue with installing the mongodb.
sudo apt install mongodb
Once you have MongoDB is installed, you like to ensure it automatically starts at startup
sudo systemctl enable mongodb sudo systemctl start mongodb
Now you like to check whether the Mongo DB service is running as expected
sudo systemctl status mongodb
How to Install UniFi Controller on OpenHABian
Most likely the UniFi Controller package is not available in the official openhabian package repository, hence you like to add it. But first you install required packages
sudo apt install ca-certificates apt-transport-https gnupg sudo wget -O /etc/apt/trusted.gpg.d/unifi-repo.gpg https://dl.ui.com/unifi/unifi-repo.gpg sudo echo 'deb https://www.ui.com/downloads/unifi/debian stable ubiquiti' | sudo tee /etc/apt/sources.list.d/100-ubnt-unifi.list sudo apt update
Since you now added the prerequisites to install the UniFi Controller package, you finally start to install the UniFi Controller
sudo apt install unifi
After successful installation, you like to check whether the service is running
sudo systemctl status unifi.service
If it is not running, you like to start it by
sudo systemctl start unifi.service
After all of this, you like to ensure the UniFi Controller is started automatically after reboot
sudo systemctl enable unifi
Note: Your UniFi installation and your openHAB installation are most likely in conflict in terms of http and https ports. For this reason its key to adjust the http and https ports of the UniFi Controller and/or the OpenHAB. In this Install UniFi Controller on OpenHABian you will adjust the http and https ports of the UniFi Controller.
sudo vi /var/lib/unifi/system.properties
Now you search within the system.properties file for “unifi.http.port” and “unifi.https.port”. Adjust them in the file as the below. If you do not find it, than you add the below to the file.
unifi.http.port=8081 unifi.https.port=8444
As a result the UniFi Controller will run on the HTTP port of 8081 and on the HTTPS port of 8444. This means, the standard ports for OpenHAB that are 8080 for http and 8443 for https are still free.
To make this effective, you need to restart the service. You can get this done by hacking the below into your terminal.
sudo systemctl restart unifi.service
Now, go to your webbrowser and type:
https://<IPAdress of your system>:8081
Here you go. Enjoy it!
Additional Information
OpenHAB
I like to share that I think OpenHAB is a fantastic smart Home solution! You are allowed to combine different things into a one solution by it. If you don’t know it, then you definitely like to check out the OpenHAB website! I think the solution can simplifies life.
OpenHAB provides an own operating system called “openhabian”. I am using it on a Raspberry Pi 8GB. For me it works perfectly. The OpenHAB community is continuously growing and it continuously adds more features to OpenHAB. Typically features are added via so called “Bindings”. Again, its really worth you look at this!
I also like to share that OpenHAB has a binding for Unifi. This is on top of having the UniFi controller running on your OpenHAB openhabian Raspberry. It allows you to further integrate your Unifi environment into your house automation. You like to check out the OpenHAB Unifi Binding.
Change OpenHAB instead of UniFi Controller default http and https ports
In the above Install UniFi Controller on OpenHABian you have changed the http and https ports of the UniFi controller. You maybe decide to keep it as is, but to change the http and https ports of OpenHAB. If this is the case, than you can leave the above step out but instead change the openHAB configuration.
sudo vi /etc/default/openhab
Change the HTTP and HTTPS ports to your preferred ports.In this example we changed to 8888 for http and 8444 for https.
OPENHAB_HTTP_PORT=8888 OPENHAB_HTTPS_PORT=8444
Once done, you like to restart the service by
sudo systemctl restart openhab