Making a Simple Open Smart Home using raspberry pi with OpenHAB-for Beginners

Hi Everyone,
                 Today most of us have heard about the Term Internet of Things(IoT) i.e., connected devices.This is my first blog I am writing just to share my works on IoT related stuffs.It may be useful for someone really who has a passion to start building their smart home with minimum investment.Here I have used a complete Open Source solution to build a smart home system. Just as an Introduction, OpenHAB stands for Open Home Automation Bus specially designed for enthusiasts who are passionate to build a smart home with the existing infrastructure.

Open HAB basically provides several bindings which we are going to use according to our need.The list of OpenHAB supporting devices can be found in the following website http://www.openhab.org/features/supported-technologies.html.Since I am a beginner to OpenHAB I have tried automating my home only using few items viz., Wemo Smart Switch, DS18B20 Temperature sensor and an IP camera(In my case i have used my old android smart phone as an IP camera connected permanently to a power supply).You can also add RGB Leds and more if you would like to make a complete smart solution to your home. 

The gateway which we are going to use in this mini project is Raspberry Pi 2. you can use RasPi 3 just to remove some external hardwares like wifi adapter and bluetooth adapter since they have these inbuilt. 

Note: I have considered here that users have a working raspberry pi with raspbian OS running in it. 
If you are new to raspberry pi kindly follow the link to proceed with installation

Step1: Installing OpenHAB in Raspberry Pi

There are many resources available online to install openhab in raspberry pi.I followed these steps to make my installation process successful but a small change you have to do kindly install the addon version 1.6 in your Pi instead of 1.5.1 because wemo devices can be controlled from the version 1.6 and above ...:)

To check whether you have installed openHAB correctly in your Raspberry pi,Kindly type this in your browser and check for the default openhab's dashboard.

http://192.168.X.XXX:8080/openhab.app?sitemap=demo

  • Here the ip must be the ip of your raspberry pi.

  • Here the sitemap name is demo and you can find this in the folder /opt/openhab/configurations/sitemaps/...I will tell you how to create sitemaps according to you below.


Note: certain devices may require bindings of higher version so make sure you are installing the latest binding version in your raspberry pi.All of your bindings can be found in the raspberry pi /opt/openhab/addons/..


Step2: To Bind wemo devices with OpenHAB for our control 

make sure your addons folder contains this jar file org.openhab.binding.wemo-1.6.1.jar before you process further...

Here I have created item file named as OSH.items and a sitemap file named as OSH.sitemap

put this line of code in your OSH.items file

Switch sensor "Switch 1" {wemo="WemoHAB"} // you can change the switch name accordingly

put this line of code in your OSH.sitemap file

sitemap default label= "OSH Panel"
{
    Frame label="Wemos"{              //you can change the label names accordingly
        Switch item=sensor
    }
 }
Now save and run this script http://192.168.X.XXX:8080/openhab.app?sitemap=OSH 
you can see a wemo switch displayed in the browser you can toggle the switch and control your device.Very Simple na..!!!!!!

Step 3: To Bind DS18B20 in OpenHAB

You can refer the below link to connect your temperature sensor with rasapberry pi and to know how to read its data


Note: cat /sys/bus/w1/devices/28-00000xxxxx/w1_slave.Here, 28-00000xxxxx is the id of each sensor and it varies for each sensor so note it down for our future use.

Once you are done with the process and successful with your connections lets bind the temperature data with OpenHAB

Now i am going to add few more lines of code in my OSH.items and OSH.sitemap files

Add the following in OSH.items file

Number ROOM_TEMP"Temperature[%.2f °C]" <temperature> { exec="<[/opt/openhab/bin/onewiretemp.sh 28-00000xxxxxx:60000:REGEX((.*?))]" }

Note: Make sure you type the id of the sensor correctly.Here 60000(1 min) represents the time of refreshing the sensor value,you can make this according to your need.

Add the following in OSH.sitemap file

sitemap default label= "OSH Panel"
{
    Frame label="Wemos"{              //you can change the label names acordingly
        Switch item=sensor
    }
 Frame label="Temperature"{

Text item=ROOM_TEMP 
    }

}

That's it just go and access the page http://192.168.X.XXX:8080/openhab.app?sitemap=OSH you can see two icons one showing toggle switch to control your wemo and below you can see your temperature value displayed.More Interesting na....!!!

Step4: To display IP camera in your OpenHAB page

Note: All your wemo devices and your mobile phones are connected to same wi-fi network in your home.

As mentioned before here i have used an old smart phone installed with an app IP webcam


Just click the start server inside the app which is at the bottom of the list menu.Now your mobile phone is turned into an IP camera.Just note down the IP which is displayed at the bottom of the screen.

Just few more lines in OSH.sitemap file

sitemap default label= "OSH Panel"
{
    Frame label="Wemos"{              //you can change the label names accordingly
        Switch item=sensor
    }
 Frame label="Temperature"{

Text item=ROOM_TEMP
    }

Frame label="Camera" {

Video icon="video" url="http://192.168.X.XXX:8080/video"        //give your camera ip
encoding="mjpeg"

}}

That's it save it and refresh the browser you can see a beautiful dashboard which you created completely using OpenHAB............like this...


Now just port forward your router to monitor and control your home from anywhere in the world.......cooooooool...:)
Feel free to ask any questions and also tell your suggestions to make this system even more optimized...................Thanks!!!


Comments

Post a Comment

Popular posts from this blog

LED control using Web Technologies(HTML, Node.js, Express.js)

Setup your own localhost tunneling service for your Mozilla Web Things gateway