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

55 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 must voice my admiration for your kindness giving support to those who actually need guidance on this particular idea. Your special commitment to passing the solution around turned out to be remarkably effective and have surely permitted those just like me to attain their dreams. Your entire interesting publication means a lot to me and even further to my peers. Warm regards; from everyone of us.

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.

My spouse and i ended up being absolutely fulfilled that Michael managed to finish up his analysis through the entire precious recommendations he discovered when using the site. It's not at all simplistic just to always be giving away procedures which often people today could have been making money from. And we keep in mind we have the blog owner to give thanks to because of that. The most important explanations you've made, the easy site navigation, the friendships you can assist to engender - it's got most impressive, and it's aiding our son in addition to us understand the topic is interesting, and that's wonderfully vital. Thanks for the whole thing!

I wish to express thanks to the writer for rescuing me from this particular challenge. Just after researching throughout the online world and getting techniques which are not helpful, I figured my entire life was over. Living without the answers to the problems you've solved through your good guide is a serious case, as well as ones that might have adversely damaged my entire career if I hadn't encountered your web page. The skills and kindness in controlling all areas was helpful. I am not sure what I would have done if I hadn't come upon such a step like this. I am able to at this moment relish my future. Thanks a lot very much for the expert and amazing help. I won't think twice to propose your web sites to anybody who needs direction about this subject.

I together with my friends have already been viewing the good helpful hints found on your website and all of a sudden got a horrible suspicion I never expressed respect to the web site owner for them. Most of the boys appeared to be absolutely warmed to learn all of them and have absolutely been enjoying these things. I appreciate you for actually being really accommodating and for picking this form of nice things millions of individuals are really needing to understand about. My very own sincere regret for not saying thanks to you earlier.

I would like to show some appreciation to the writer just for bailing me out of this particular difficulty. As a result of searching throughout the online world and seeing proposals which are not productive, I figured my life was done. Living without the answers to the problems you have sorted out by means of the short article is a serious case, and ones that would have adversely damaged my entire career if I hadn't encountered the website. That talents and kindness in touching almost everything was precious. I am not sure what I would've done if I hadn't come upon such a step like this. I can also now relish my future. Thank you very much for your high quality and effective help. I will not be reluctant to refer the blog to anybody who requires guidance on this topic.

I enjoy you because of every one of your hard work on this web page. Debby take interest in doing investigation and it's really easy to understand why. Most people notice all concerning the lively means you present helpful tips by means of the web site and in addition foster contribution from other people on that topic then our own child is studying so much. Have fun with the rest of the year. You're performing a terrific job.

I precisely wanted to appreciate you again. I'm not certain what I might have sorted out in the absence of those advice shared by you directly on this subject. It seemed to be the challenging condition in my view, but seeing a specialised mode you handled that made me to weep with happiness. I am just happier for this service and as well , hope that you recognize what an amazing job you are undertaking instructing the rest through your blog. More than likely you have never got to know any of us.

Thank you a lot for giving everyone such a brilliant chance to read articles and blog posts from this web site. It is always so brilliant and also jam-packed with a good time for me and my office colleagues to search your site a minimum of three times every week to study the latest stuff you have got. And of course, we are at all times fulfilled with your cool tips and hints served by you. Some two facts in this article are unquestionably the very best we have all had.

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'm just commenting to make you be aware of of the incredible discovery my girl had using the blog. She noticed some issues, which include what it is like to have an awesome coaching spirit to have the mediocre ones quite simply know just exactly some multifaceted topics. You really surpassed people's expected results. Many thanks for showing these insightful, healthy, revealing and as well as easy thoughts on this topic to Julie.

I together with my guys happened to be looking at the excellent points on your web page and so instantly developed a horrible feeling I never expressed respect to you for those strategies. All of the guys ended up for this reason warmed to read through them and already have pretty much been having fun with them. Thanks for really being quite kind and for finding this form of quality areas millions of individuals are really needing to learn about. My personal honest apologies for not expressing appreciation to you sooner.

Thanks so much for providing individuals with a very wonderful opportunity to read in detail from this blog. It is always so pleasing and also packed with a great time for me personally and my office friends to visit your site a minimum of 3 times weekly to read the latest items you will have. Of course, I'm just always contented with your very good tips and hints you serve. Selected 2 facts in this article are undeniably the most effective I have had.

Thank you for all your effort on this web page. Debby takes pleasure in conducting investigation and it's really simple to grasp why. I notice all relating to the powerful mode you make practical guidelines by means of the web blog and even invigorate participation from other individuals on that subject plus our princess is without question becoming educated a whole lot. Take advantage of the rest of the year. Your doing a powerful job.

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 just wanted to post a brief word so as to thank you for all the wonderful tips and tricks you are sharing here. My prolonged internet search has at the end been recognized with beneficial know-how to share with my neighbours. I 'd repeat that most of us readers actually are unquestionably fortunate to exist in a perfect site with many marvellous professionals with interesting strategies. I feel very grateful to have seen your entire web page and look forward to tons of more exciting times reading here. Thank you again for a lot of things.

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.

Thanks a lot for giving everyone remarkably marvellous possiblity to read in detail from this blog. It is often so pleasant and stuffed with fun for me and my office fellow workers to search the blog really thrice per week to read the new tips you will have. And lastly, I am just actually happy concerning the striking tips and hints you serve. Some 2 points on this page are really the very best we have ever had.

I would like to express my gratitude for your kind-heartedness in support of visitors who should have assistance with your niche. Your very own commitment to passing the solution across has been rather helpful and has regularly permitted many people just like me to achieve their targets. The informative tutorial indicates much a person like me and substantially more to my office colleagues. Regards; from all of us.

Good post. I be taught one thing more challenging on different blogs everyday. It can all the time be stimulating to learn content material from different writers and apply just a little something from their store. I抎 choose to use some with the content material on my blog whether or not you don抰 mind. Natually I抣l provide you with a link in your internet blog. Thanks for sharing.

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.

Thank you so much for giving everyone a very breathtaking chance to read articles and blog posts from here. It really is very pleasing plus full of a great time for me personally and my office co-workers to search the blog at the very least three times in one week to see the latest tips you will have. And lastly, I am also always impressed with your cool guidelines you serve. Selected two facts in this article are really the most suitable I've ever had.

I intended to put you this tiny observation to be able to say thank you again with the incredible basics you've provided on this website. This is so extremely open-handed with you to offer extensively just what some people could have offered for sale as an e-book to help make some dough on their own, principally seeing that you could possibly have done it if you considered necessary. These smart ideas additionally worked to be the good way to be aware that the rest have the same desire the same as mine to know significantly more in terms of this condition. I believe there are a lot more fun moments ahead for individuals who scan your website.

|Fashion is more than about just the clothing and accessories. These people fail to understand that bad hair can very easily ruin a great outfit. Make sure you keep your hair looking at its best and use the best products that you can afford to do this.

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.