Getting Started with OpenHAB & Raspberry Pi: Install Add-ons, Read 1-Wire Sensor Data

Getting Started with OpenHAB

In the era of the Internet of Things, more and more devices are interconnected. But every device uses a different communication protocol that makes it hard to control them from a single device. Fortunately, there is a solution for this - OpenHAB. The open Home Automation Bus (OpenHAB) is an open-source, technology-agnostic home automation platform that runs as the center of your smart home. OpenHAB communicates with smart and not-so-smart devices, performs user-defined actions, and provides web pages with user-defined information as well as user-defined tools to interact with all devices. It allows users to control all devices from well-known manufacturers using one interface. To achieve this, the OpenHAB segments and compartmentalizes certain functions and operations.

 

So in this tutorial, we are going to install and setup OpenHAB on Raspberry Pi. In our previous tutorials, we have covered other smart home platforms like Home Assistant, ESPHome, and Tasmota, check them out if you are interested.

 

Components Required

Hardware

  • Raspberry Pi
  • Micro SD Card
  • SD Card Reader

 Software

  • OpenHAB Image file
  • Balena Etcher

 

Installing OpenHAB on Raspberry Pi

Step 1: For installing OpenHAB on Raspberry Pi, first, download the appropriate OpenHabian Disk Image for your Raspberry Pi from the OpenHAB page. We will be using the Raspberry Pi 4B for this project.

Raspberry Pi OpenHAB Tutorial - Download OpenHabian Disk Image

 

Step 2: Then download balenaEtcher for flashing image file on Raspberry Pi. Etcher is a free and open-source utility that helps in burning image files such as .iso, .img files, and zipped folders to create live SD cards and USB flash drives.

Download balenaEtcher

 

Step 3: Once the installation is done, open the Etcher app. Etcher installs the operating system in three steps; the first step is to select the image. To select an image file, click on Select Image in Etcher and select the OpenHabian image file. Then select the right SD card and click Flash.

balenaEtcher Setup

The most reliable networking setup for your Raspberry Pi is to connect it using an Ethernet cable; however, if you want to configure Wi-Fi, you can try this. Navigate to your SD card i.e. openhabian boot and open a file called ‘openhabian.conf’. Now, inside the file, uncomment and complete the lines reading wifi_ssid="" and wifi_psk="" and enter the Wi-Fi name and password.

Networking Setup for Raspberry Pi

 

Step 4: Now, unmount the SD card, remove it from your card reader and insert it into Raspberry Pi. Connect your power supply to the Raspberry Pi and wait until the installation is done. It will take 20 to 30 minutes. After that, you should be able to access OpenHAB web UI from any device on the same local network. To access the OpenHAB page, navigate to the browser, and type http://your-pi-ip-address:8080. If the page doesn’t open, wait for another 10 minutes.

After this, you will be asked to create an administrator OpenHAB account. Enter a User name, Password, and click on “Create Account”.

Create OpenHAB Account

 

After creating the account, on the next screen, set your language, region, time zone, and location. You can skip the location setting step and complete it later.

OpenHAB Account Setup

You now have the option to install OpenHAB add-ons. If you prefer to install add-ons later, click on ‘Install Add-ons Later’. You can always install/remove add-ons in the future, enabling you to modify and improve your system over time.

Install OpenHAB Add-ons

 

After finishing the setup, you will be redirected to your OpenHAB dashboard.

OpenHAB on Raspberry Pi

OpenHAB Dashboard

With this, the OpenHAB setup is complete. On the left side, you will find the menu. From here you can change the system setting and install Bindings.

OpenHAB Setting

 

Reading 1-Wire Sensor (ds18b20) data on OpenHAB

Install OneWire & Exec Bindings:

To be able to use certain modules such as MQTT or one-wire, the necessary bindings must first be installed. In this example, we start with OneWireGPIO binding. This binding is used to read temperature values from OneWire sensors connected to the Raspberry Pi GPIO. 

To install OneWireGPIO binding, click on ‘Settings’ from the sidebar, then click on ‘Things’. Then click on the blue "+" button located at the bottom-right corner.

OneWireGPIO binding

 

On the next screen, click on ‘Install Bindings’. Now, search for the ‘OneWireGPIO’ binding. Click on the binding, then on Install.

Install OneWireGPIO binding

Now, in the next step, follow the same procedure to install ‘Exec Binding’. This binding is used to execute arbitrary shell commands.

 

Connect Raspberry Pi with DS18B20 Temperature Sensor

Raspberry Pi DS18B20 Temperature Sensor Circuit Connections

Connect DS18B20 GND [Pin 1] to the GND of the Raspberry Pi. Connect DS18B20 VDD [Pin 3] to the 5V pin of the Raspberry Pi. Then connect DS18B20 DQ [Pin 2] to GPIO 4 of Raspberry Pi. Finally, place a 4.7k pull-up resistor between the DS18B20 DQ pin and 5V.

 

Enable the One-Wire Interface:

Now, we need to enable the One-Wire interface before the Pi can receive data from the sensor. Once you’ve connected the DS18B20, SSH into your OpenHABian, and navigate to the boot folder and open the config.txt file using the below commands:

cd /boot
sudo nano config.txt

 

Add the line given below at the end of the file and save the changes.

dtoverlay=w1-gpio,gpiopin=4

 

Reboot the Raspberry Pi, and then navigate to the 1-Wire device folder and list the devices to ensure that the sensor has loaded correctly.

cd /sys/bus/w1/devices/
ls

Raspberry Pi Command

The 1-wire temp sensor has a UID (28-xxxxxxxxxxxx) as displayed in the above image. If the w1 directory does not exist, the 1-wire driver was not loaded, and you need to check config.txt and make sure it is correct.

Now, enter cd 28-XXXXXXXXXXXX (change the X’s to your address). For example:

cd 28-0119398d3802

 

Then use the command given below to read the sensor data;

cat w1_slave

Command to Read the Sensor Data

In the above image, the temperature reading is t=22250, which means a temperature of 22.2500C

 

Creating the OpenHAB Items, Things, and Sitemap

In this final step, we will create OpenHAB modules to show temperature data. For that, we will add Items, Things, and Sitemaps.

 

First, we will create a .thing. For that go to the things directory using the below command:

cd /etc/openhab/things

 

Now, create a new file in the things directory using the command given below:

nano onewiregpio.things

 

And paste the below lines

Thing onewiregpio:sensor:livingroom "Living room" [gpio_bus_file="/sys/bus/w1/devices/28-0119398d3802/w1_slave",refresh_time=30] 

 

Now, in the next step create a new .items file. For that go to the items directory using the below command:

cd /etc/openhab/items

 

Now, create a new file in the items directory using the below command:

nano onewiregpio.items

 

And paste the below lines

Number LivingRoomTemperature "Temperature: [%.2f °C]" <temperature> {channel="onewiregpio:sensor:livingroom:temperature"}

 

Now in the next step create a new .sitemap file. For that go to the items directory using the below command:

cd /etc/openhab/sitemaps

 

Now, create a new file in the items directory using the below command:

nano demo.sitemap

 

And paste the below lines

sitemap demo label="My home automation" {
    Frame label="Date" {
        Text item=Date
    }
    Frame label="Demo" {
        Text item=LivingRoomTemperature label="Livingroom [%.1f °C]"     
    }
}

 

With this done, you should now have a fully functioning 1-wire temperature sensor network, displaying live temperature. To access the Web UI click on the ‘Other Apps’ icon on the top right corner and then click on ‘Basic UI’.

Web UI

You will be redirected to Web UI:

Home Automation

This is how you can install OpenHAB on Raspberry Pi. Hope you’ve found this tutorial useful. Share your views and queries (if any) in the comment section below. 

Video

23 Comments

Greetings! Very useful advice in this particular article! It is the little changes that will make the most important changes. Many thanks for sharing!|

I'm also commenting to make you know what a perfect discovery my cousin's daughter enjoyed using your web site. She discovered a good number of issues, which include how it is like to possess a marvelous coaching heart to get the others clearly fully understand specified impossible issues. You truly surpassed our own desires. Thanks for producing such useful, healthy, explanatory not to mention unique thoughts on the topic to Mary.

I wanted to post a small message to thank you for all of the wonderful steps you are writing at this website. My time consuming internet look up has at the end of the day been compensated with awesome concept to exchange with my co-workers. I would mention that we visitors actually are unquestionably endowed to exist in a really good network with many wonderful individuals with beneficial tricks. I feel somewhat blessed to have used the site and look forward to plenty of more enjoyable moments reading here. Thanks once more for all the details.

I as well as my buddies came analyzing the nice hints located on your web site and before long I got a horrible suspicion I had not thanked you for them. The guys had been stimulated to read through them and have in effect absolutely been taking advantage of those things. I appreciate you for getting well helpful and for getting variety of fantastic topics millions of individuals are really needing to understand about. My personal sincere apologies for not expressing gratitude to earlier.

I simply needed to say thanks yet again. I'm not certain the things I could possibly have implemented in the absence of the type of tactics provided by you regarding my concern. It seemed to be a very alarming condition in my position, nevertheless viewing this professional avenue you managed it forced me to cry for delight. Now i am happy for your support and thus hope you find out what a great job you have been getting into educating some other people using your blog. Most likely you have never come across any of us.

I truly wanted to write a quick message to appreciate you for all of the splendid recommendations you are giving out at this website. My extensive internet research has finally been compensated with pleasant strategies to write about with my close friends. I would claim that we visitors are very fortunate to exist in a decent website with so many wonderful professionals with good points. I feel pretty grateful to have encountered the webpages and look forward to so many more amazing moments reading here. Thank you once more for everything.

I really wanted to send a brief message to express gratitude to you for all of the great tactics you are placing here. My considerable internet search has now been honored with sensible points to write about with my friends. I would express that most of us visitors actually are undoubtedly endowed to live in a useful site with very many awesome individuals with insightful principles. I feel extremely privileged to have used the webpages and look forward to many more awesome times reading here. Thanks again for all the details.

Needed to draft you one little observation just to say thanks as before with your magnificent advice you've featured at this time. It's quite particularly generous with people like you to make publicly precisely what many of us would've distributed as an electronic book in order to make some cash for their own end, mostly considering that you could possibly have done it if you desired. These advice likewise served to be the good way to fully grasp that most people have the same fervor the same as mine to figure out a whole lot more in regard to this issue. Certainly there are a lot more pleasant occasions up front for many who examine your website.

I simply had to thank you very much all over again. I'm not certain the things I would've achieved without the actual creative ideas contributed by you over such subject. It was actually a real depressing condition for me personally, however , discovering the very skilled technique you dealt with that took me to leap over fulfillment. I am grateful for this service and thus have high hopes you recognize what an amazing job that you're putting in training most people using a web site. Most likely you've never come across all of us.

I want to express my thanks to this writer for bailing me out of this type of issue. Just after looking out throughout the online world and seeing methods which are not beneficial, I assumed my life was well over. Existing devoid of the solutions to the difficulties you have solved by way of this site is a crucial case, and the ones that might have negatively affected my entire career if I had not discovered the website. The know-how and kindness in controlling all the details was valuable. I don't know what I would have done if I hadn't come upon such a step like this. I'm able to at this time look ahead to my future. Thanks very much for the reliable and amazing help. I will not hesitate to endorse the website to anyone who would need tips about this matter.

I have to get across my respect for your kind-heartedness for individuals who really need help with your study. Your special dedication to getting the message all through appears to be amazingly insightful and has in most cases allowed somebody just like me to arrive at their desired goals. Your amazing informative guide can mean much to me and much more to my office colleagues. Warm regards; from all of us.

I and also my guys came digesting the nice solutions from your web site while unexpectedly came up with a horrible suspicion I never thanked you for those strategies. Most of the women ended up as a consequence warmed to see them and have in effect actually been enjoying these things. Appreciation for simply being well helpful and then for making a decision on varieties of excellent issues most people are really needing to be informed on. Our sincere regret for not expressing gratitude to you sooner.

Thanks a lot for giving everyone an extraordinarily marvellous opportunity to read from this site. It really is very brilliant plus packed with fun for me personally and my office mates to visit your site nearly thrice per week to learn the newest stuff you have got. And indeed, I'm also usually fulfilled concerning the astonishing ideas you serve. Selected 4 tips in this posting are essentially the most beneficial we have ever had.

Thank you for all your valuable hard work on this blog. My mum take interest in making time for research and it's really easy to see why. Most of us notice all concerning the powerful mode you produce very important guidance by means of your web site and in addition inspire response from some other people on that content plus my child has been discovering a lot of things. Take advantage of the remaining portion of the year. You are always performing a terrific job.

Thanks so much for providing individuals with an exceptionally splendid chance to discover important secrets from here. It is always very cool and as well , jam-packed with a great time for me and my office peers to search the blog not less than 3 times in one week to see the fresh items you have. And indeed, we are actually astounded considering the brilliant secrets you serve. Selected two points on this page are indeed the best we have all had.

I wish to express my appreciation to you for rescuing me from this type of crisis. Right after checking through the online world and obtaining ways which are not pleasant, I believed my entire life was well over. Existing devoid of the strategies to the problems you've solved by means of the article is a critical case, as well as the ones which could have badly damaged my entire career if I had not noticed your blog post. Your good understanding and kindness in touching all the things was very helpful. I don't know what I would've done if I had not come across such a step like this. I can also now look ahead to my future. Thanks so much for this impressive and result oriented help. I won't hesitate to refer your web page to anyone who needs and wants counselling about this problem.

I really wanted to write down a brief comment to be able to thank you for some of the unique steps you are posting here. My prolonged internet research has at the end been honored with reputable information to write about with my friends. I would claim that most of us website visitors are really blessed to exist in a really good site with many wonderful individuals with good secrets. I feel extremely grateful to have used your webpage and look forward to many more cool moments reading here. Thanks a lot once again for all the details.

I in addition to my friends ended up viewing the great secrets and techniques on your web blog while before long got an awful suspicion I never expressed respect to the web blog owner for those secrets. All the young men were definitely so very interested to read them and already have unquestionably been making the most of them. We appreciate you actually being well considerate and for making a decision on this sort of magnificent subject matter millions of individuals are really desperate to understand about. My sincere regret for not expressing appreciation to sooner.

I have to express appreciation to you just for bailing me out of such a instance. As a result of researching throughout the the web and meeting ideas that were not helpful, I was thinking my entire life was well over. Existing without the approaches to the issues you have solved through your main guideline is a serious case, as well as those which could have in a negative way damaged my entire career if I hadn't encountered your site. Your actual skills and kindness in touching every part was important. I don't know what I would've done if I hadn't come across such a subject like this. I can at this time look forward to my future. Thanks for your time so much for your expert and results-oriented guide. I will not hesitate to refer the blog to anybody who would need recommendations on this subject.

I am only writing to let you know what a notable encounter our girl experienced checking the blog. She noticed so many details, with the inclusion of how it is like to have an ideal helping heart to get a number of people very easily learn about some complex topics. You really did more than my expected results. Thank you for supplying the helpful, trustworthy, revealing and fun guidance on that topic to Julie.

I have to point out my love for your kind-heartedness giving support to persons that should have assistance with this one concern. Your real dedication to passing the solution throughout had become astonishingly good and has in every case permitted ladies just like me to achieve their targets. Your entire informative guide indicates a great deal a person like me and extremely more to my office colleagues. Regards; from all of us.

I simply wanted to appreciate you once again. I am not sure the things I could possibly have gone through in the absence of those suggestions discussed by you regarding my area of interest. It was actually a very distressing matter in my position, however , encountering a new specialized tactic you managed that forced me to jump for joy. Now i'm thankful for this assistance and in addition have high hopes you realize what a powerful job you are always doing training the mediocre ones all through your website. Most probably you've never got to know any of us.

I have to get across my admiration for your kind-heartedness supporting those people that actually need help on this important theme. Your special dedication to passing the solution all around ended up being rather valuable and have in every case made many people like me to arrive at their ambitions. Your amazing informative key points can mean a whole lot to me and even more to my fellow workers. Thanks a lot; from all of us.

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.