Building a Home Automation System

December 4th, 2020

01

 

Convenience and Comfort are two things that people have always been looking for. Every invention throughout history was to facilitate this. From light bulbs to air conditioners, the intent to develop them was to provide convenience and comfort to people.

Technology also is used to make the standard of living better for people. In order to increase the work efficiency and comfort of people, automating their environment is a good option. Automating or easier interfacing of the environment is a step closer to integrating technology into different aspects of our life.

Home Automation is a trending technology nowadays. Most of the luxurious homes have an inbuilt home automation system or a smart home concept using IoT. Home Automation technology enables users to control lights, fans, air-conditioners and other appliances at home using an application or voice commands.

Home Automation can also include a digital assistant that takes commands regarding control of the home. Smart home devices are getting used widely in the last few years. Since the launch of Amazon Alexa and Google Home, a lot of home appliances that can be controlled by them have been made by different companies.

kickstart

In this post, I will discuss the different aspects of building a home automation system. Each aspect will be detailed such that beginners also can understand and develop a prototype of their own. Students and researchers already with some experience in automation can develop a similar system with some new and exciting features. This home automation project discusses two main concepts - home automation using IoT and chatbots for home automation.

kickstart

Home automation - controlling the fans, lights and other electrical appliances in a house using the Internet of things. IoT devices and other IoT sensors can also be added to the mainframe so that they also can be controlled. The gist of a home automation system or similar automation projects is to remotely control lights, fans and other IoT devices using a mobile phone. In this post, a basic web application control and chatbot based control (with Natural Language Processing) are discussed. These are the softwares and hardware used to build this home automation application.

Software Requirements

Raspbian - OS for Raspberry Pi. (comes installed on Raspberry Pi or easily installable)

Python - It is an open-source programming language that is supported on Raspberry Pi. Python is used to control the GPIO pins of the Raspberry Pi and also for Natural Language Processing.

WebIOPi - It is a software for Raspberry Pi that enables GPIO control over Local Area Network using a Web Application.

HTML and Javascript - To create the web application

Android Studio -To develop a chatbot application

Hardware Requirements

Raspberry Pi - Raspberry Pi is a single-board computer which runs on a Linux based operating system and is best suited for IoT since it has inbuilt Wi-Fi. The Raspberry Pi acts as the control system for the home automation system.

Relay Board connected to lights, fans and appliances of the home

This projects mainly involves different aspects like:

1) Automation: Automation is controlling devices or machines without human effort or reduced human effort. Here we are using a brain or control system (Raspberry Pi) to control the lights, fans and appliances at home.

2) Internet of Things: IoT is basically controlling devices through the internet. IoT is a very demanding feature nowadays in most automation and embedded systems based applications. Here we are using the Internet of Things for the user to communicate with the Raspberry Pi. There are many IoT devices and IoT sensors available in the market that can be interfaced into the home automation system. The devices connected to the home automation system can be controlled using a basic application.

3) Natural Language Processing: NLP is basically getting information or meaning of sentences. In this application, the user can send text messages to switch on lights or fans and using NLP we can identify the device and the action.

4) Firebase Cloud: Firebase cloud helps to implement the chatbot for home automation. Firebase Cloud is used to get inputs from the user through the android app. The python script reads the input from the Firebase Cloud database. The android app is a basic chatbot style application developed using Android Studio.

Basic Control - Using Web Application

kickstart

The lights, fans and other electrical devices in a home can be controlled using a web application hosted on the Local Area Network through wireless communication. This is a relatively simple application to start with home automation. The lights and fans are connected to a Raspberry Pi over relays and these can be controlled using a simple app developed using javascript. The app can be accessed by any device on the Local Area Network of the home with a simple password-based login.

The lights, fan and electrical devices are interfaced by the Raspberry Pi through relays. A suitable circuit diagram can be made accordingly based on the devices to be interfaced. The web application gives the command to the Raspberry Pi over the LAN and the Raspberry Pi controls the lights through the relays. A step by step guide to implement this is discussed below.

Step 1: Setting up Raspberry Pi

Connecting the Raspberry Pi and getting it set up. Connect the Raspberry Pi to any display. I have installed NOOBS on the Raspberry Pi. It runs on Raspbian which is a Linux-based OS for Raspberry Pi.

Step 2: Installing WebIOPi

Open Terminal and run the below codes for installation

kickstart

You can also start/stop Webiopi service

kickstart

To setup your system to start webiopi at boot :

kickstart

To remove webiopi start from boot :

kickstart

Step 3: Access WebIOPi over local network

Connect Raspberry Pi to your network and open a browser to http://network_ip:8000/ with any device of your network

The Default user is "webiopi" and password is "raspberry"

By choosing the GPIO Header link on the main page, you will be able to control GPIO using a web UI which looks like the board header.

  • Click/Tap the OUT/IN button to change GPIO direction. GPIO direction is to define the state of GPIO as input/output.
  • Click/Tap pins to change the GPIO output state. This toggles the GPIO between OFF/ON state.

 

kickstart

Step 4: Changing the webpage displayed

We need to display our webpage instead of this standard webpage. Testing a basic LED control webpage initially.

Type the code( html with javascripts) for the webpage and save it.

Sample code for a single LED (connected on pin 6 of Raspberry Pi)

kickstart

Type sudo nano /etc/webiopi/config in the terminal and change the root directory and welcome file. Save the changes and restart webIOPi

Step 4: Testing

Open the URL on a device in the same network and once the webpage appears enter the id and password. See if the LED connected to pin 6 glows.

kickstart

Using the webpage the LED can be controlled from any device connected to the LAN same as the Raspberry Pi. This is a simple LED control application.

Step 5: Installing Weaved (for controlling raspberry pi from another network)

Just with WebIOPi the webpage will only work on devices connected to the same LAN. For getting access from a device on another network, another plugin software - Weaved is used.

To install Weaved, create a weaved account and copy the following commands in the terminal

kickstart

Make the installer executable and launch the installer

kickstart

Enter the email address and password for your Weaved account. Choose the HTTP service on port 8000, then enter an alias, or nickname for your device.

Step 6:Test your setup

To test the connection to your Raspberry Pi from your browser, open the Weaved account and go to the device list, find the line with your Raspberry Pi's alias, and click on “Connect”. Enter the id and password to access the webpage to control the raspberry pi. Control the raspberry pi’s GPIO pins using the webpage displayed.

kickstart

Step 7: Setup Home Automation Template

Now to extend this application to the Home Automation application, the webpage code needs to be edited accordingly. Add more buttons in the webpage code for the lights and fans as per needed. The circuit for the lights needs to be interfaced with GPIO pins of the Raspberry Pi through relays. Once all the connections and the webapp code is ready, then access the web page on LAN on any device. Real-time status of the lights and fans also can be seen on the application.

kickstart

kickstart

kickstart

For a more detailed implementation of Web Application based Home Automation, please refer to this research paper.

Advanced Control - using Chatbot Application

Another approach is by using a chatbot application. Using the chatbot algorithm, the user can text information to control the functioning of the lights, fans and electrical appliances at home. The messages sent using the chatbot are processed using Natural Language processing techniques. The NLP part is done using a simple Python script that converts the text from the chatbot app into a command to the devices connected to the Raspberry Pi. The chatbot application just relays the messages from the user to the python script and also relays back the output from the python script and displays it as a reply to the message.

First, let us discuss the chatbot application. The chatbot application is a simple application where the user enters some message and this message is sent to the Raspberry Pi. The chatbot application is developed using Android Studio along with using firebase so that the messages or command can be sent to the Raspberry Pi. Create a basic messaging interface based application on Android Studio and add Firebase to the application. Firebase will act as a backend for the application and Raspberry Pi can access the messages or commands from the application through a simple python script.

The chatbot application has a basic welcome message hardcoded and just passes the messages from the user to the Firebase database. The chatbot application is a pretty simple application and the interface is shown in the image below.

kickstart

The messages from the chatbot application are read by a python script on the Raspberry Pi. To use firebase on raspberry pi, you need to install the firebase python library.

kickstart

After installing python-firebase a simple python script can be used to get the messages from the database.

kickstart

In the dictionary the latest message from the chatbot application is stored as the last entry. So, the message is retrieved by using the key of the last entry. Once we get the message, we need to understand the message. To do this we are using Natural Language Processing. Various Natural language processing techniques are used to process the instructions provided by the user. Once the user gives the chatbot an instruction, the following techniques are applied to the text:

I. Tokenization: The sentence is split into words by using a function named word_tokenize from the Natural Language Toolkit (NLTK).

II. Conversion into lowercase All words in the given text are converted into lowercase to maintain uniformity and make further processing easier.

III. Removal of stop-words: Stop-words are words that do not contribute to the meaning of a sentence individually such as a, the, an, and all. All words are checked with a predefined list of stop-words, and they are removed if there is a match.

IV. Defining keyword and action lists: Two lists namely keywords and actions are defined in the algorithm. The keywords list contains all possible keywords relevant to this case such as light, fan, room, door, temperature, and so on. The actions list contains all possible words that denote an action in this setup. For example: increase, decrease, switch, set, open, close, and so on.

V. Understanding keyword and action: Now, the processed words are matched to the keyword and action lists to identify the keyword and action specified in the instruction.

VI. Actuation Based on the keyword and action identified in the previous step, the relevant action is taken. For example, if the keyword is door, and the action word is close, then the door variable will be set to false, which in turn will send a signal to the Raspberry Pi to close the door.

Implementation of the above techniques is done in python using the Natural Language ToolKit (NLTK) library in python.

kickstart

The word_tokenize function is imported and used to split the message into tokens. The stopwords list is imported to find the stopwords in the message. Once the message is tokenized and the stopwords are removed, we need to find out the keywords and actions. Here keywords refer to the devices like lights, fans, etc. and actions refer to on/off. The below code snippet extracts the keyword and action from the message.

kickstart

Below shown is an example output of the above code

kickstart

This code given above is just for the understanding of how the Natural Language Processing techniques work. For a home automation system, there has to be more keywords and actions included other than these. Once the keyword and action is extracted from the message then the respected GPIO pin of the Raspberry Pi is toggled on/off according to the action extracted.

For a more real-life implementation, it is better to introduce different rooms. For this then apart from keyword and action, we also need to find the position (room number, appliance number) of the device. This is a better implementation if there are multiple rooms and more than one lights or fans in a room.

kickstart

This implementation is a prototype of chatbot based home automation. For a more detailed implementation please refer to this research paper.

Other Features

We have discussed web application control and chatbot application implementation. There are a few other additional features that can also be clubbed along with to make the home automation more robust and efficient.

  • Rather than just a chatbot application, an API for speech-to-text can be added to the application. So, voice commands can be given for home automation. This adds a feature of voice control to the home automation system.
  • Instead of having all of the lights, fans and other electrical devices controlled through an application, some crucial lights at least can be made automatic. A PIR motion sensor can be integrated with any microcontroller to the light for motion-based control. Any activity detected in the room will switch on the light for a fixed time period.
  • Various other appliances and control settings also can be added to the application. Settings such as timer-based control for ACs or automated night mode to switch off lights at night can be explored.
  • Instead of using Wi-Fi for control of the home automation system, a simpler Bluetooth communication protocol can be designed using a Bluetooth module.
  • An intruder alert system can be used by setting a camera. This can be implemented as a security system. If an intruder is detected a mail with live stream link can be shared to the owner of the home. This can be done on python using an SMTP server and IFTTT recipes. If This Then That (IFTTT) is a web-based service that allows users to create chains of conditional statements triggered by changes that occur within other web services such as Gmail, Facebook, Telegram, Instagram, or Pinterest. Various other recipes also can be created using IFTTT to facilitate better home automation.

kickstart

There are many features that can be added to the home automation system explained in the blog. You can try out different features apart from the ones discussed. Building a home automation system or a project like this will help anyone explore concepts of the Internet of Things and Automation. Such projects are first steps to contributing to the innovation and developments in the respective fields. I really hope many of you find this as a motivation to work on a prototype similar to this. For any further queries you can contact me at cyrilbabyjoe@gmail.com.

 

 

 

ABOUT THE AUTHOR

Camilla

Cyril Joe Baby is an Entrepreneur, Developer and Researcher. Co-founder and Chief Technical Officer of Fupro Innovation Private Limited, a high-tech research company in prosthetic and rehabilitation devices.

Cyril has worked on various projects and research works during the past years. (Google Scholar link) His fields of interest and expertise include Artificial Intelligence, Robotics and Embedded Systems. Cyril continues to contribute to these fields by working on various exciting projects and guiding beginners to work on their projects. For any further information, you can contact him at cyrilbabyjoe@gmail.com.

1
No votes yet

Alumni Speaks

It started off in a more hectic manner than I could expect. ... read more

- Priyanshi Somani, Manipal Institute of Technology

“GAIP is perfectly aligned with someone's goal who wishes to experience an outburst of academic challenges while working on projec ... read more

- Sukriti Shaw, SRM Institute of Science and Technology

“Combining different characters and skillset from different institutes and domains in a new country and fantastic institute, it wa ... read more

- Shaolin Kataria, VIT, Vellore

“An enriching and enthralling experience. The course was extensive but worth every penny. ... read more

- Arudhra Narasimhan V, SASTRA DEEMED TO BE UNIVERSITY

“I personally learned quite a bit here but the 6-month project or LOR aren't as easy to get as was portrayed before. ... read more

- Dwait Bhatt, BITS PILANI

“It was a great experience for me, and far beyond my expectations. ... read more

- Shrikant Tarwani, LNM Institute of Information Technology

“This Internship is the perfect balance of theory and practical application. ... read more

- Mahima Borah, Manipal Institute of Technology

“This Internship has strengthened my concepts on Artificial Intelligence and Deep learning which are the hot words of today’s t ... read more

- Mansi Agarwal, Delhi Technological University

Please login to post comment, like the blog and its associated comments as well