An Intelligent, Secure, and Smart Home Automation System

Faculty of Computer Science and Information Technology, Universiti Tun Hussein Onn Malaysia (UTHM), Batu Pahat, Parit Raja 86400, Johor, Malaysia Department of Information and Communication Engineering, Yeungnam University, Gyeongsan 38541, Republic of Korea Department of Information Technology, Khwaja Fareed University of Engineering and Information Technology, Rahim Yar Khan 64200, Pakistan Department of Computer Science, Khwaja Fareed University of Engineering and Information Technology, Rahim Yar Khan 64200, Pakistan


Introduction
In this age of technology, the Internet of ings refers to the idiosyncratically identifiable objects and their virtual representation in cyberspace [1][2][3][4]. IoT is a pristine information processing and accretion method encompassing RFID [5] sensor machinery, smart technology, nanotechnology, and other technological advancements. IoT is not alone noble technology; instead, it circumvents considerable complementary technical development and provides capabilities that are appropriated together and aid to bridge the gap between the virtual and physical world [6]. Everyone is living a very busy life, and they want to get ease in every aspect of life. e Internet of ings (IoT) is a very vast field, and this research cannot cover up the whole thing to automate. But, the ease of people Home Automation is the first domain that comes in mind. Home Automation [7][8][9][10] is a term used to describe the working of all home appliances together, and we are controlling things by using an Android smartphone [11,12], tablet, or computer having internet connectivity. e popularity of home automation is increased rapidly during the recent years. People like the comfort of maintaining and changing the status of appliances from any part of the world using remote access. It is eventually becoming the need of every person.
IoT provides more flexible and low-cost solutions for daily life problems which ultimately improve the user's life [13]. Although many previous researchers proposed many home automation systems by using different sensor combinations [14][15][16][17][18], as shown in Table 1, with the detailed description of previous studies provided, we may conclude that there are some reasons for the motivation to design an efficient home automation system.
(i) Previously proposed home automation systems are expensive and complex (ii) Previously proposed Bluetooth home automation systems required intrusive installation (iii) Previously proposed home automation systems use the connectivity of the Internet which may be not useable in those areas where the internet is not available (iv) Previously proposed home automation systems have not focused on security and safety problems that may arise from their implementation (v) e previously proposed home automation system has no intelligent decision-making ability To assure home automation continues in a normal fashion, it is necessary to check all important parameters that may complicate the system, one of which is no GUI environment for the users. Users cannot understand the working of the system due to the lack of a GUI environment. Secondly, there is no device restoration which is harmful to home appliances.
irdly, there is no prediction of the electricity bill for the users, and all the previous home automation solutions are very expensive. So, we provide an effective solution to overcome all these problems by undertaking the following objectives.
(i) e proposed solution is low cost because it did not use IP-based devices such as bulb and light. (ii) e proposed solution provides electricity bill prediction to the users. e proposed solution uses GSM technology which means a Global System for Mobile Communication (GSM) modem to control home appliances such as light, conditional system, and security system via Short Message Service (SMS) text messages. (iii) e proposed solution provides device restoration which means when you restore a computer or other electronic device, you return it to a previous state.
(iv) e proposed solution is a cloud-based solution which means it controls home appliances through the Internet.
(v) e proposed solution provides Arduino and Raspberry implementation. For those who love to tinker with electronics, the Raspberry Pi and Arduino have become invaluable tools. ey are both extremely popular options but are also very budget-friendly. Arduino is best used for real-time applications of hardware and software, and Raspberry Pi easily connects to the Internet.
(vi) e proposed solution provides a prototype home design for the ease of the users. (vii) e proposed solution has an intelligent decisionmaking ability to classify the status of IoT devices used in the smart home automation system. (viii) e proposed solution ensures secure identification and authentication of users using blockchain technology.
e rest of the paper is structured as follows: Section 2 highlights the related work and key contributions in the area of smart home and smart buildings. Section 3 discusses the used approach, and Section 4 presents the implementation details of the used approach along with used hardware and software. Section 5 presents the results of the experiments along with the discussion. e paper is concluded in Section 6.

Related Work
e research gap identified in previous studies in the domain of smart homes and smart buildings is reported in Table 1.

Used Approach
In this paper, a smart home automation system is presented that allows the user to check and change the status of electronic home appliances and the working state of sensors. Appliances include common lighting, heating, ventilation, and air-conditioning electronic devices.
is product not only saves time but also provides energy-efficient solutions which let you know which device of your home consumes more power. is cost-efficient and the energy-saving system can also be installed in hotels and industrial/domestic places. Easy GUI icon-based interface and notifications of application let you be in touch with your home even if you are on a trip far away from your home. e concept of automating ordinary available installed devices of the home costs much less than special IP-based (RJ-45) [27] devices giving uniqueness and providing a solution that is affordable to people of middle-class families. e working of the proposed home automation system is shown in Figure 1.
In the admin side of the app, the user will able to draw the complete structure of his/her home using easy drag and drop interface. Firstly, the user adds floors of the house and, then, selects any added floor to add rooms inside it. After selecting the room, the user will be able to add appliances and can set the position of each device according to the real structure of a home. ere is also an option available to add custom floors, rooms, and devices inside the home structure. After completing the setup of home from the admin application user sync database in the form of JSON [28] to our server, when a user logs in using credentials, he will able to see the complete structure of home the same as he made in the admin side as complete data are fetched from the server and get updated using VOLLEY [29,30] service after 30 sec. At the main screen of the application, the user can see the number of total devices installed at home, and the floor details are shown. ree more tabs lie on the lower bottom of the application. e 2nd tab contains the complete information of sensor status. e third tab contains the history of each device status along with the name of the user who changes status and on which time. e fourth tab is logout from the application. Shared preferences are managed for credentials, and the information is saved.
Moreover, the SVM classifier is applied to classify the status of home appliances used in the smart home automation system. It classifies the status of home appliances into two categories, i.e., "ON" and "OFF"according to the use of these appliances. We have also compared the used prediction model with other models and choose the best one. Furthermore, blockchain technology is used to secure the whole communication and authentication between IoT devices and users that request to make "ON" or "OFF" any home appliances. Blockchain technology also ensures the security of data transfer between IoT devices, servers, applications, and users of the smart home automation system.

SVM-Based Classification.
e proposed smart home automation system has ability to make an intelligent decision regarding the status of home appliances. To accomplish it, we used a linear SVM classifier. SVM was initially proposed by Vapnik [31]. SVM is a supervised machine learning  Scientific Programming algorithm that can be used for both classification and regression challenges [32]. In the proposed system, we have employed it for classification purposes. Moreover, many techniques can be used for the classification of data such as decision tree, neural network, and K-nearest neighbor. We have preferred to use SVM for intelligent decision making in the proposed solution due to the following reasons.
(i) SVM is a suitable choice where binary output classes are required as in our case. Our proposed system needs to classify the status of devices into one of two classes, i.e., "ON" and "OFF." (ii) It is required to find the best hyperplane using a kernel function to classify the data point of one class from another class in classification problems. SVM finds the optimal hyperplane by separating the data points of both classes. (iii) When classification was performed using the SVM classifier, the resultant hyperplane has maximum margin between data points of target classes. However, the hyperplane generated by other classifiers does not achieve maximum margin [33].
To mathematically describe the SVM hyperplane and max hyperplane, we used equations (1) and (2) given by [34].
where y has the value of either −1 or +1 and to represent whether the data points ← x1 belong to which class, the value of y is used. Equation (2) is used to obtain the maximum margin hyperplane used by SVM.

Max Hyperplane
(2) In our problem, the input dataset contains the readings of sensors that include temperature, smoke, and light sensor. e output of the problem is status classes, i.e., "ON" or "OFF." e value of y � 0 represents that the device is "OFF," and y � 1 represents that the device is "ON." SVM is a classic two-type classifier for segregating the two classes by determining an optimal hyperplane in a twodimensional plane, as shown in Figure 2. e green color dots represent class 1 and the red color dots represent class 2, the optimal separating line denotes by H, the H1 line is parallel to H and linking samples in class 1, and the H2 line is also parallel to H and linking samples in class 2, as shown in Figure 2. w denotes that the distance between the H1 and H2 is called the margin, i.e., equal to 2/‖w‖.
It is needed to separate the two classes in such a way that misclassification error becomes zero and maximize the margin. is can be achieved by using optimal separating line H that becomes the optimal separating hyperplane through spreading two-dimensional space into higher dimensional space. e equation of a separating hyperplane to separate the two classes using the optimal separating hyperplane is given as follows: In equation (3), w is the weight vector and the offset of the separating hyperplane is b. A linearly separable hyperplane between class 1 and class 2 is shown in Figure 3.

Blockchain for Security of Smart Home.
A key objective of the smart home automation system is to provide a trusted, secure identification and authentication of IoT devices. To ensure these objectives, we have used blockchain technology. Blockchain technology was introduced by Nakamoto in 2008 [35]. e main features of blockchain technology are security, anonymity, and decentralization [36]. ese features can be fruitful to IoT by providing more security and reduced dependency on the central server. Moreover, blockchain technology also ensures tempered resistance data structure by utilizing data encryption and timestamp. In the proposed approach, the implementation of the blockchain module is accomplished in Java by defining the block's contents in a hash that is a unique identifier. Using each block, a block hash is computed, and a hash SHA-256 is, then, computed from it. On achieving a threshold, requests for connectivity are granted through managing blockchain, and then, a block is created. To validate the complete blockchain, a block of the chain is looped-over that verify a current block's hash to its corresponding previous block's hash.
Whenever a connectivity request is generated by a user, it will be authenticated using a sequence of steps described in the flowchart given in Figure 3.
We have also designed an algorithm to explain the working of blockchain technology in the proposed approach given as follows. e whole process of blockchain implementation is also depicted in a flowchart shown in Figure 3 and Algorithm 1.
First of all, a block is created using a block class implemented in Java calculating a hash using a previous hash, timestamp, and data string. After creating a block, a hash will be generated using the SHA256 algorithm implemented in Java. When a hash is created, the next step is to store the generated blocks. At the final step, validation of the blockchain will be performed to check whether the hash is equal to the calculated hash. If it is true, then the block is valid and access is granted; otherwise, the whole process is repeated.

Implementation Details
To understand the working of the project, Figure 1 explains the complete working structure and integration of different devices with each other. e arrows show the flow of projects starting from user smartphones to changing the state of electronic devices. ere are two network modes in which the user can interact with our Raspberry [37][38][39][40][41]. If the user is sitting inside the home (home local network), then the user will be able to use all of the IoT services at the local network without connecting to the internet cloud. is will also result in faster communication of devices with the user as everything is happening locally. e second network mode is used if the user is residing outside the home anywhere in the world. en, the user first connects to the internet. e processed request is sent to the Microsoft Azure Cloud [42,43]. Based on credentials provided by the user matched with the Azure cloud database, the user request is sent to the respective Raspberry for processing. e account of each user is maintained individually at the Microsoft Azure Cloud Database. Services of each user are handled based on credentials from which the request is being generated. APIs are called from the cloud if the user is outside the home network. en, the same APIs are also residing inside the Raspberry Pi server if the user is in the home network.
Data sharing between application and server database is performed in the form of JSON. APIs are secured using multiple hashing techniques. e change in the state of any device is performed using Raspberry Pi GPIO [44] pins. Raspberry Pi receives the request from the server. According to the request from the user, Raspberry Pi responds to devices. e database of each request generated by the individual user is maintained at cloud servers. e user can check the complete history of processed requests on his smartphone by setting the duration. Sensors installed inside the home update its state continuously after 30 sec and respond to the change to the Raspberry Pi server. In response, the Raspberry Pi server syncs all data to the cloud database, and the values of the mobile application are updated.

Hardware Components.
Many electronic components, as well as sensors, are used in this project. Our working structure diagram Figure 1 shows a few of the components used in this project. A complete description of components along with description is shown in Table 2.

Raspberry Pi 2B.
e Raspberry Pi is a series of small single-board computers to promote the teaching of basic computer science in schools and developing countries. It contains a 900 MHz quad-core ARM Cortex-A7 CPU processor along with 1 GB of RAM. It supports 100 MBPS Ethernet. It also contains 4 USB ports along with 40 GPIO pins, full HDMI support with camera, and card interface and supports a micro SD card. It contains a 3.5 mm audio jack and composite video support too.

5 V Relay Circuit.
A relay is an electrically operated device. It has a control system and (also called input circuit or input contactor) and a controlled system (also called output circuit or output contactor). It is frequently used in the automatic control circuit. To put it simply, it is an automatic switch to controlling a high-current circuit with a low-current signal.

L293D Motor Shield. L293D [49]
is a monolithic integrated, high-voltage, high-current, 4-channel driver. is means that using this chip, you can use DC motors and power supplies of up to 16 Volts, that is, some pretty big motors, and the chip can supply a maximum current of 600 mA per channel; the L293D chip is also what is known as a type of H-Bridge. e H-Bridge is typically an electrical circuit that enables a voltage to be applied across a load in either direction to an output, e.g., motor.
is means that you can read the temperature with a very simple circuit setup. It communicates on a common bus, which means that you can connect several devices and read their values using just one GPIO pin of the Raspberry Pi.

LM393 LDR Sensor.
e LM393 [51] is a simple photoresistor light sensor that has both analog and digital outputs. e digital output has a trim potentiometer that can be used to set a trigger light level. In the following example, we will use the analog output to measure the light level. If you are interested in reading the digital output, please refer to the pulse sensor example sketch. [52] is one of the commonly used gas sensors in the MQ2 sensor series. It is a Metal Oxide Semiconductor-(MOS-) type gas sensor also known as chemiresistor as the detection is based upon the change of resistance of the sensing material when the Gas comes in contact with the material. Using a simple voltage divider network, concentrations of the gas can be detected. An MQ2 Gas sensor works on 5 V DC and draws around 800 mW. It can detect LPG, smoke, alcohol, propane, hydrogen, methane, and carbon monoxide concentrations anywhere from 200 to 10000 ppm.

GSM Module.
is module can be mostly used for developing IoT (Internet of ings) and embedded applications. It is a dual-mode module that works on frequencies 900 MHz and 1800 MHz. It has a feature of multislot class, i.e, class 10/class 8. e pins RXD and TXD are used to receive and transmit data. It works on a voltage of 3.4 V to 4.5 V, and any higher voltage may damage the module. e GSM module also requires low power consumption.

Software Components.
For the development of the mobile application, there are many platforms available such as Symbian, Android, IOS, and Windows Mobile.
In our research paper, the Android platform is used for the development of the whole project. e main reason for the use of the Android platform is that it is the most widely used platform all over the world. e Android operating system is supported by almost every brand device. Java language with an Android software development kit (SDK) has been used for the development and implementation of home automation application. [53,54] is used for the development of Android apk as it supports all development tools such as debuggers, libraries, and a handset emulator. e Volley library is used for all sensor services. Material design library is used to make the application more interactive.

Server-Side Scripting.
For the development of the server-side on cloud and inside Raspberry Pi, LAMP (Linux, Apache, MySql, PHP) is used to provide all backend functionality.
(1) At the first step, a block is created with the help of the block class (2) A hash is created using the SHA-256 algorithm on the successful creation of an already created block otherwise repeat step 1 (3) After the generation of hash, the next step is to store the blocks (4) At the last step, the validity of the blockchain will be accomplished. If the block is valid, then request for connectivity is granted (5) If the block is not valid, steps 1 to 4 are repeated ALGORITHM 1: Working algorithm of blockchain technology.  [45] Supply-voltage range: 4.5-36 V; output current: 600 mA/channel Smartphone mobile Android supported DS18B20 temperature sensor [46] Temperature range: −55 to 125°C (−67°F to +257°F) LM393 LDR sensor [47] Digital switching outputs (0 and 1), external 3.3 V-5 V vcc MQ2 smoke sensor [48] Combustible gas, smoke 6 Scientific Programming

Mobile Applications for Smart Home.
Mobile Application consists of two modes of operation. In the admin mode, the user able will be able to draw his/her complete home prototype using an easy drag and drop interface. Each device is assigned with a Raspberry Pi pin number which controls the actual working of electronic devices on the backend. If we look at the user side of the mobile application from which the user will not only be able to see the complete prototype of the home which is designed but also can control the working of each appliance on basis of pin configuration that he did on the admin side, as shown in Figure 4. e main screen contains the number of devices installed in the house along with floor names and the number of rooms inside it. Tab layout is used for switching between app services.
A nice and interactive GUI-based interface with attractive icons lets the user know about its working easily, as shown in Figure 5. Icons changing are used to let the user know about the current state of an electronic device with a touch active button to change state. ere is also an intensity bar to let the user maintain its fan speed and light brightness according to its choice. e status of devices is shown with the active state of working and active ago with the passive state.
In the second tab of the main screen, the state of each sensor is shown along with current values. e values of sensors get updated using backend services which refresh themselves after every 30 seconds, as shown in Figure 6. Currently, we are dealing with the live status of two sensors such as temperature and light, as shown in Figure 7. e light sensor value 0.0 shows that currently, daylight is active and the sensor is in off state. e third tab on the main screen gives us complete details about the history of the device. e complete log with the details of the user who changes the status of appliances is maintained with time-stamped details. e user can check the on and off duration of appliances from history as well. Another interesting feature of this application is that the user will receive a notification on his smartphone if any device is working for more than two hours. It is similar to an alarm or reminder to the user to check and balance the power consumption of each appliance whether a person is sitting in a particular room or there is electricity wastage, as shown in Figure 8.
ere is also a billing calculation system based on device electricity consumption and the time duration in which the device remains in the working state.

Results and Discussion
e functional behavior of this project can be further understood using Figure 9. e complete workflow of the project comprises two ways as we discussed earlier. In the first scenario, the functional behavior of the project assumes that the user is outside the home and accessing each device remotely. is scenario assumes the involvement of using the Microsoft Azure cloud database. Each request from the user is firstly received on the cloud, and according to the credentials provided by the user, APIs are called.
In the second scenario, we assume that the user is inside the home and connected to the same network to which Raspberry Pi is connected. All the requests generated by the user do not go to the internet or cloud rather than operateing Scientific Programming on Raspberry Pi server internally, as shown in Figure 10. is will lead to the processing of requests more quickly than the involvement of the cloud. We have also stored data taken from the history tab of the developed App and stored it in a Microsoft Excel sheet (see Figure 11) and further used it to show the relationship between data that are discussed in this section. e excel sheet contains the values of temperature, smoke, and light. ere is a status column where 0 represents the "OFF" status of smoke and light while 1 represents the "ONN" status of smoke and light. We have also drawn a joint plot between temperature and smoke, as shown in Figure 12 where each observation of temperature is shown along the x-axis and smoke values are shown along the y-axis. e histogram along the x-axis represents the different readings of temperature, and the histogram along the y-axis represents the different readings of smoke.
In Figure 11, the joint plot is drawn that shows the relationship between light and temperature. e values of light are shown along the x-axis, and temperature is shown along the y-axis. e histogram of light and temperature is also shown in Figure 13 along the x-axis and y-axis, respectively.
A scatter plot is also drawn to show the relationship between smoke and light (see Figure 14). e smoke values are shown along the x-axis, and light values are shown along the y-axis. e histogram of smoke is also represented along the x-axis, and the histogram of light is represented along the y-axis as shown in Figure 14.
We have shown the status of light from taken readings using the two-dimensional kernel density plot in Figure 15. It shows the status of light when it is "ON" and "OFF." e values of light fall between zero and six hundred, and the   Scientific Programming status of values lie between 0 and 1 that shows "OFF" and "ONN," respectively. e kernel density plot for smoke is shown in Figure 15 that shows the status of smoke along the x-axis and its values along the y-axis. e presence of smoke is represented as zero and absence as one in Figure 16.
One of the most common types of graphics that are used to show the numeric values of variables is the box plot. It divides the dataset into three quartiles. e line that divides the box into two parts represents the median of the data, and the end of the corner shows the upper and lower quartiles. e extreme lines represent the highest and lowest values excluding outliers. It also hides the number of the values that lie behind the variable. We have also drawn a box plot of light, temperature, and smoke, as shown in Figures 17-19.
To make intelligent decisions about the status of home appliances, we have used a linear SVM classifier. First of all, we divided the recorded data into training and test data sets using the built-in function tain_test_split (·) of Scikit learn in Python. Figure 20 shows the confusion matrix of trained SVM classifiers that shows% of truly predicted and wrongly predicted classes.
In the confusion matrix, the instances of the true class are represented horizontally while instances of the predicted class are represented vertically. ere were a total 49 predicted "OFF" classes out of which only one class was wrongly predicted as "ON" that was actually "OFF" while the total "ON" classes were 17 out of which only 2 classes were wrongly predicted as "OFF" that was actually "ON." We have also plotted the ROC curve of the proposed linear SVM classifier, as shown in Figure 21. In the ROC curve, the true positive rate of a linear SVM classifier was shown on the yaxis and the false positive rate was represented along the xaxis.
e ROC of the linear SVM classifier showed an AUC � 0.957, as shown in Figure 21.
We have also compared linear SVM classifiers with other available classifiers such as KNN, Decision Tree, and Random Forest. Among all these classifiers, SVM outperforms, as shown in Figure 22. erefore, the presented approach uses a linear SVM classifier for decision making about the status of home appliances.
In Figure 22, the accuracy of the SVM classifier is 95.73% that is greater than that of all other machine learning classifiers, i.e., K-Nearest Neighbour (KNN), Naïve Base (NB), Random Forest (RF), and Decision Tree (DT) having accuracy 94.32%, 93.80%, 93.24%, and 94.73%, respectively. e implementation is performed in a way that if the Raspberry Pi restarts or any mishap happens in electricity, then all the devices are set again to the state before the restart.
is involves the use of a database server that maintains the state of each device. e last state record of each device is being fetched and set again to each device accordingly. e application will get its details from the server too.
Sensors are installed to get the updates at regular intervals. ere is a condition set out for user comforts that if    the temperature of the home rises up to the threshold set by the user, then all ventilation fans will start working automatically and vice-versa. Light sensors controlled the state of lights installed outside the home automatically in daylight and on the night. A comparison of the old and the proposed system is shown in Table 3.
All the features and functionality comparisons described in the table above will make this project unique from the rest. Designing the prototype of your own house and setting each device according to the room design will make it easier for a user to operate the electronic device with more ease.

Conclusions
In this research paper, the complete design scheme and working methodology of a home automation project are explained. e reason behind the paper is to get enhancement ideas to make it better and user friendly. is proposed system comprises two modes, the admin side in which the user able to design the complete prototype of the home and the user side in which the user able to control each device of the home with an easy GUI-based interface. e proposed system also has decision-making ability about the status of each device of the home. A machine learning algorithm SVM with a linear kernel is applied for decision making about the status of home appliances either ON or OFF. e presented approach also ensures secure identification and authentication of IoT devices using blockchain technology, while the existing systems which have not copped with intelligent decision making and analytical abilities are the need of time.
e existing system also does not provide secure communication between IoT devices. Moreover, this project is user acceptance tested verified and operational in many homes. It provides simplicity, flexibility, reliability, and a low-cost system that is affordable to middle-class families too.

Data Availability
e data used to support the findings of the study are available from the corresponding author upon request.