Openhab is a great application running on your Raspberry Pi if you want to build home automation. In this tutorial, we will install Openhab2 on Raspberry Pi 3 using the Manual Method
What we need:
- Raspberry Pi 3 with Raspbian installed
- Connect your Raspberry Pi3 on the Wifi
Set a Static IP on Raspberry Pi
We need to set a static IP on Raspberry Pi first. You can visit my other post to see the two different methods on setting a static IP
sudo nano /etc/network/interfaces
Go down and you should see the code below.
auto eth0
iface eth0 inet manual
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Lets set the IP
sudo nano /etc/dhcpcd.conf
Go down and paste this code, but change the IP according to your network. My Network is 192.168.2.x. Yours maybe different:
interface wlan0
static ip_address=192.168.2.200/24
static routers=192.168.2.1
static domain_name_servers=192.168.2.1
sudo systemctl enable dhcpcd
sudo systemctl enable networking
We have to reboot
sudo reboot
Installing OpenHab2 – Manual Method
Update and Upgrade the system first. This may take some time.
sudo apt-get update
sudo apt-get upgrade
Add OpenHab user, group, directory, change the ownership and set password:
sudo adduser --system --no-create-home --group --disabled-login openhab
sudo mkdir /home/openhab
sudo chown -R openhab:openhab /home/openhab
sudo passwd openhab
Download the package
cd /tmp
wget -O openhab-download.zip https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab%2F2.0.0%2Fopenhab-2.0.0.zip
Unzip the package
sudo apt-get install unzip
sudo unzip openhab-download.zip -d /opt/openhab2
Delete the zip file
rm openhab-download.zip
Take the ownership
sudo chown -hR openhab:openhab /opt/openhab2
Finally, launch the OpenHab runtime
sudo su -s /bin/bash -c '/opt/openhab2/start.sh' openhab
Go to your browser and open the url: http:// [your raspberrypi ip address]:8080
In my case its: http://192.168.2.200:8080
The initial setup page will show:
Select Standard (recommended setup)
Then you will be waiting for about 25 minutes while UIs are being installed. I recommend you to use a timer and set to 25 minutes. Because in some cases I waited for 45 minutes and the installation screen still not change. What I do is to force it to stop after 25 minutes and re-run again just to speedup the process.
After 25 minutes, go back to your console and type logout.
logout
If you check your browser you will see 404 page, don’t worry about it. Now re-run the runtime on console by typing:
sudo su -s /bin/bash -c '/opt/openhab2/start.sh' openhab
After few seconds, go back and refresh the webpage, keep re-trying after a minute if it still not showing. The image below will show if the installation is successful:
Creating a Service for Openhab2
If you logout from the runtime, you will notice the Openhab will not run. We can make a service file so Openhab will automatically run every boot up without launching the runtime.
On console, type:
logout
Creating the Service file:
sudo nano /lib/systemd/system/openhab2.service
Paste this code:
[Unit]
Description=The openHAB 2 Home Automation Bus Solution
Documentation=http://docs.openhab.org
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=openhab
Group=openhab
GuessMainPID=yes
WorkingDirectory=/opt/openhab2
#EnvironmentFile=/etc/default/openhab2
ExecStart=/opt/openhab2/start.sh server
ExecStop=/bin/kill -SIGINT $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
Save it and exit
Make the file as a Service
sudo systemctl daemon-reload
sudo systemctl enable openhab2.service
sudo systemctl start openhab2.service
sudo systemctl status openhab2.service
Reboot your Raspberry Pi and try the page again
Thats it, you just install OpenHAB2 on a Raspberry Pi 3 using the manual method.
Directory Information
DIRECTORIES of Manual Method
openHAB application /opt/openhab2
Additional add-on files /opt/openhab2/addons
Site configuration /opt/openhab2/conf
Log files /opt/openhab2/userdata/logs
Userdata like rrd4j databases /opt/openhab2/userdata
Service configuration /lib/systemd/system/openhab2.service
hello , im struggling to login to new user openhab on the pi via ssh? any help will be much appreciated