Smart Home Energy Management System based on the Internet of Things (IoT)

The global increasing demand for energy has brought attention to the need for energy efficiency. Markedly noticeable in developing areas, energy challenges can be attributed to the losses in the distribution and transmission systems, and insufficient demand-side energy management. Demandoriented systems have been widely proposed as feasible solutions. Smart Home Energy Management Systems have been proposed to include smart Internet of Things (IoT)-capable devices in an ecosystem programmed to achieve energy efficiency. However, these systems apply only to already-smart devices and are not appropriate for the many locales where a majority of appliances are not yet IoT-capable. In this paper, we establish the need to pay attention to non-smart appliances, and propose a solution for incorporating such devices into the energy-efficient IoT space. As a solution, we propose Homergy, a smart IoT-based Home Energy Management Solution that is useful for any market – advanced and developing. Homergy consists of the Homergy Box (which is an IoT device with Internet connectivity, an in-built microcontroller and opto-coupled relays), a NoSQL cloud-based database with streaming capabilities, and a secure cross-platform mobile app (Homergy Mobile App). To validate and illustrate the effectiveness of Homergy, the system was deployed and tested in 3 different consumer scenarios: a low-consuming house, a singleuser office and a high-consuming house. The results indicated that Homergy produced weekly energy savings of 0.5 kWh for the low-consuming house, 0.35 kWh for the single-user office, and a 13-kWh improvement over existing smart-devices-only systems in the high-consuming house. Keywords—Internet of things; energy efficiency; home control; smart home


I. INTRODUCTION
Energy efficiency has gained as much importance as (if not more than) energy capacity growth. A significant increase in population has resulted in severe electricity supply challenges costing a country like Ghana an average of US $2.1 million in loss of production daily, despite her increase in generation capacity from 1,730 MW in 2006 to 3,795 MW in 2016 [1]. This has resulted in a call for efficient and sustainable energy usage. Efficient energy consumption provides a balance between available energy supply and demand. Energy conservation refers to efforts made to reduce energy consumption which can result in increased financial capital, environmental quality, human comfort, among others [2].
Most processes in place for energy management have been from the side of the supply/distribution, but it is recommended by works like that of [3] that allowing users to manage their electricity usage in an informed manner is a better method. According to [4], a modern view of energy efficiency now requires that low-income economies re-orient themselves toward sustainable energy practices and advanced technology to achieve better energy efficiency. This paper explores the common use of the Internet of Things (IoT) in achieving energy efficiency. IoT technology makes it possible to integrate all devices in the home over networks (including the Internet) for data-sharing (monitoring) and actuation (control). IoT devices are typically integrated with the functionality to enable them communicate over networks and execute certain tasks, and as such are sometimes marketed as being "smart". Non-IoT ("non-smart") devices, despite their proliferation in markets, are not (or have not been made) integrable into the internetconnected IoT space, leaving them out of the general effort to conserve energy.
The novelty in this paper is the integration of both smart and non-smart electrical appliances into the IoT space by designing an IoT device (the Homergy Box) as an intermediary between the smart internet-connected side and all other appliances (including the "non-smart"), such that all devices can be controlled over the internet (in this case, through an internet-connected Android/iOS mobile app).
The architecture of the system will be discussed in Section IV of this paper. Section V describes the communication protocols and hardware/software technologies utilized in this research work, as well as the implementation of the system. The results obtained are described Section VI and conclusions are made in Section VII with avenues for future work.

A. Related Works
It is posited by most works that demand-oriented solutions and management systems provide better energy efficiency than (IJACSA) International Journal of Advanced Computer Science and Applications, Vol. 12, No. 2, 2021 supply-side management systems. The authors in [5] demonstrate that demand-side solutions provide higher efficiency, extra capital cost avoidance, failure probability reduction, risk management improvement, to name a few. Reference [3] bases on such demand-oriented architecture and proposes "a smart domestic energy management system" that connects local appliances to a user interface over the Internet. This was made possible by installing an internet-capable mote on each appliance.
There is general consensus that user inclusion is necessary to achieve better energy management and efficiency [2]. Accordingly, various approaches have been suggested for the implementation of demand-oriented home energy management solutions. The authors in [6] developed and analyzed a 'smart home scheduling scheme' using simulation software, and developed an end-user application interface used for visualizing and controlling energy usage in the home through usercontrolled hourly energy-usage schedules. The result showed the avoidance of energy wastage through planning, monitoring and control of daily energy consumption.
In [7]'s intelligent agent-based Home Energy Management System, the authors combine electricity pricing information, smart metering and smart IoT-capable appliances to design a smart system in which users, network operators and energy suppliers can benefit from a dynamic pricing mechanism.
Providing real-time energy usage statistics to users is an important step in improving energy usage efficiency. Various works such as [8] have proposed real-time meter-reading that sends accurate power statistics to both energy suppliers and consumers via intuitive user interfaces. In [9], an IPv6equipped smart meter prototype reports energy readings to service providers over a cloud. Depending on the user's preference, energy usage in the house adapts to increase/decrease of electricity prices via a gateway which controls appliances. In [8], the authors add actuation and communication functionality to existing traditional meters using an ATMega328P microprocessor (found in Arduino Uno) and a GSM Module. The retrofitted meters in [8] have more accurate meter readings compared to human meter readers and provides consumers with regular updates of their consumption.
Researchers in [10] propose an IoT-based system where a NodeMCU controls relays connected to home appliances. This is a very good solution as it is not specific to smart devices only. However, their work was not deployed in a real environment. Also, they were not exhaustive about the implementation of their proposed voice control. Their solution makes use of a web page interface which may not be as convenient as a native mobile app would be in this case [11].

B. Smart Home Energy Management Systems on the Market
In this subsection we review some of the most common Smart Home Energy Management Systems on the market at the time of writing.
Manufacturers of smart home products usually implement their own control systems and interfaces. These market products usually have a dedicated app for controlling their appliances, such as the ecobee app for controlling ecobee devices. Over time, some manufacturers have opened up their ecosystems to be controlled by other systems ("integration systems"). These systems, such as the Google Home and Amazon Alexa are specifically designed to interface all supported smart devices. The Google Home and Samsung SmartThings are by themselves central control points for an ecosystem of smart devices that support their proprietary integration systems, such as the Google Assistant and Bixby respectively. Integration systems have become common, and manufacturers usually ensure that their smart devices can interface with these systems.
Dedicated hardware devices (known as "smart hubs") have also been developed for integrating smart devices and permitting wider integrations, more convenient user interfacing (such as voice control in smart speakers), and multi-step automation, such as switching lights and Air Conditioners off when the user leaves the house.

III. MOTIVATION AND OBJECTIVES
From the literature review, it is perceived that a lot of work has been done on Smart Home Energy Systems, but these works have been focused on already-smart appliances. The solutions reviewed do not consider devices that are not IoTcapable (that is, devices that do not have the ability to sense and communicate with their environment). Smart devices, according to [12], "are autonomous physical/digital objects augmented with sensing, processing and network capabilities. They carry chunks of application logic that let them make sense of their local situation and interact with human users. They sense, log and interpret what is occurring within themselves and the world, act on their own, intercommunicate with each other and exchange information with people".
According to Statista's 2020 estimate in Fig. 1, only 0.6% of households in Africa own at least one smart device, compared to 69% in the United States. It can be concluded that markets with a low penetration of smart devices (such as Africa) would not benefit from the proposed solutions reviewed in Section II. The proposed architecture for domestic appliances in [3] (including the non-smart appliances) has a major limitation: an IoT mote will have to be installed for every non-smart appliance. This will come as very expensive and hence impractical for low-income households who arguably need energy efficiency the most. The authors in [2] report a mean electricity usage efficiency of 63% in Ghana, suggesting the existence of an immense potential for the implementation of energy efficiency measures. We are motivated to design and implement a smart energy-efficient IoT-based Home Energy Management Solution relevant to homes in developing areas. Our objectives therefore become clear here as follows: • To design a smart Home Energy Management System that includes non-smart appliances into the energyefficient IoT space.
• To implement the proposed system under realistic test environments for possible use-case scenarios.
• To test the effectiveness of the proposed IoT-based solution at improving energy efficiency.

A. System Model
To make the product relevant to homes with non-smart devices and appliances, the "Homergy Box" was developed to be installed in homes/offices and serve as a gateway between the "smart side" (the Internet and Homergy application), and the "non-smart side" (the home appliances), therefore bridging the gap between these classes of appliances. The model is shown in Fig. 2.
The components in the Box consist mainly of an Arduino Mega microcontroller, a NodeMCU, relay modules and an AC-DC converter. Since the electronics require a constant DC voltage, the AC-DC converter converts the input 240 V AC to 5V DC. This 5V DC is then to supplied to microcontroller, NodeMCU and the relay modules. The NodeMCU has an inbuilt Wi-Fi hardware and connects the Homergy Box to the Internet through Wi-Fi.
The NodeMCU receives data from the mobile app, parses the data and sends appropriate instructions to the Arduino Mega. The Arduino Mega microcontroller executes instructions for controlling the appliance-connected relays. Although the NodeMCU alone could have been used as microcontroller, it does not have enough I/O pins and output power to control the Homergy Box's sixteen (16) relay pins. The relay modules serve to interface the high-voltage AC appliances and the low-voltage electronics circuitry. Fig. 3 shows a more-detailed block diagram of the system.

B. Communication
Communication protocols used in Homergy include the I 2 C serial protocol, HTTP, WebSocket and TCP/IP. I 2 C is implemented between the microcontroller (Arduino) and the Wi-Fi module (NodeMCU), and also between the microcontroller and Liquid Crystal Display (LCD). The user interface (Homergy Mobile App) sends the user's instructions to the cloud-based database via an HTTP request. The database then sends a change event notification to the NodeMCU through an alreadyestablished WebSocket over HTTP. The NodeMCU parses the received data and sends the instruction to the Arduino Mega. On reception, the Arduino Mega turns the specified relay on or off. 1) I 2 C Communication Protocol: I 2 C (pronounced isquared-see or i-two-see) is a serial communication protocol usually implemented in microcontrollers, EEPROMs, analogdigital converters and sensors. I 2 C is a multi-master and multislave protocol which makes use of only two wires: a data line called Serial Data (SDA), and a Serial Clock (SCL) line. For each communication session, the respective master generates a start condition, supplies clock for the communication on the SCL line and also specifies which slave can talk on the SDA line by first sending the slave's address. Therefore, each master or slave must have a unique address. At the end of a communication session, the master generates a stop condition. Data transfer between master and slave is split into 8-bit packets.
2) HTTP: In standard Hypertext Transfer Protocol (HTTP), a client sends a request to a server for data. The server responds to the client by sending the requested data or any error message and closes the connection. Communication only begins when the client first opens a connection and requests data from the server.
3) WebSocket Protocol: A WebSocket is a full-duplex communication protocol which runs on a TCP connection. The connection is not closed after the server sends a response to the client. This allows the server and client to communicate at any time until either of the two closes the connection.

V. IMPLEMENTATION
This section discusses the implementation of our proposed architecture in Section IV. The user system's operation and user interaction is described in Fig. 4. The following subsections are a detailed description of the implementation of specific parts of our proposed architecture.

A. Tools Used
Arduino IDE: Atmel-based boards were used as microcontrollers. The Arduino IDE was used to write and upload programs to the Arduino Mega 2560 board. The Arduino IDE was also used to program the NodeMCU using the "ESP8266 Core for the Arduino IDE" open-source library.
Android Studio: Android Studio was the IDE used to develop the mobile application for this project using the Dart programming language and the Flutter framework.
Cloud platform: A NoSQL Database with real-time streaming capabilities was used to store data on users and Homergy Boxes. In our implementation, the Firebase Realtime Database was selected due to well-documented libraries available for both Android/iOS/Web platforms and the NodeMCU platform. The streaming feature of the Firebase Realtime Database was used to send commands to Homergy Boxes in real time. Any cloud-based implementation (e.g. MQTT used in [13]) that allows real-time communication between the NodeMCU and the Homergy Mobile App will also work.

B. Hardware Design
The exterior of the Homergy Box hardware is shown in Fig. 15. The internal components are shown in Figs. 5 and 6. Below are the properties of the hardware used in the Homergy Box; 1) Four-channel Relay board (Fig. 5-A): There are four of these relay modules in the Homergy Box, totalling sixteen (16) relay channels. The relay module serves as coupling between the high-voltage home circuit and the low-voltage Homergy Box circuit. The module has its internal low-voltage digital signal circuit isolated from the relay through opto-coupling. The relay's contact capacity is 10A 250V AC / 10A 30V DC, whilst the Digital circuit operates at 5V 20mA (DC). The module is therefore compatible with the Arduino's 40mA General-Purpose Input/Output (GPIO) pins, and with common household AC appliances.
The relays are connected to the appliances as shown in Fig. 7. The Normally Closed (NC) port of the relay is placed between the source and the load. This way, current can still www.ijacsa.thesai.org flow when the Homergy Box is off. A "High" from the Arduino GPIO pin activates the relay and switches the appliance off.
2) Arduino Mega 2560 (Fig. 5-B): The Arduino's properties are detailed in Table I. 3) 16x04 I 2 C LCD ( Fig. 5-C): An LCD is included to provide information on the state of the Homergy Box to the user. During initial configuration, the LCD guides the user in step-by-step procedure to configure the Wi-Fi connection (SSID and password). Any errors (such as disconnection from the Wi-Fi or the Cloud) is displayed on the LCD. The LCD is controlled by the NodeMCU. Table II shows the properties of the NodeMCU module used.

C. Software Design
There are three main parts of the Homergy system; The Microcontroller (Arduino), the Communications (NodeMCU/ESP8266 and Cloud) and the Homergy Mobile App.
Arduino: The Arduino makes use of the SoftwareSerial library to communicate with the NodeMCU over a serial connection. The Arduino has been programmed to always listen to the NodeMCU for instructions. These instructions are received as a JavaScript Object Notation (JSON) objects which are parsed and executed. The JSON was designed to have two fields: a "command" field and a "payload" field. Command contains a bool which indicates whether the NodeMCU is to change or read the Arduino-connected relays' states. The payload field contains data on user-defined relays states from the Homergy Mobile App, and this field is null only when the NodeMCU is requesting relay states. The Arduino reads or writes the relay states according to the JSON sent by the NodeMCU.
NodeMCU/ESP8266: As shown in Fig. 4, the NodeMCU (bearing an ESP8266 Wi-Fi module) was programmed to connect to the NoSQL cloud-based database (the Firebase Realtime Database) upon start-up. Commands for each Box are saved in a separate child node called "relays" for each Homergy Box (as seen in Fig. 11). The relay states are boolean values (True or False). The Homergy Mobile App, when a user makes a change (on or off), sets the boolean value to True or False respectively. The NodeMCU instantly receives the data for the changed child node (due to Firebase streaming) and sends an appropriate command to the Arduino, which in turn actuates the relay.

D. Homergy Mobile App
The Homergy Mobile App was developed using the crossplatform app development framework Flutter, making it available for major mobile platforms (Web, iOS and Android). The Mobile App was designed to have a nice user-friendly interface. Using the Firebase Database, a rewards system was developed where users gain points (called H-points) for using the system (Fig. 8). Such a reward system is proven to contribute to user retention and engagement [14], and hence leads to better energy efficiency for Homergy users. The app screen on which appliances (relays) are controlled is shown in Fig. 9. The default relay names (Relay 1, Relay 2, etc.) can be edited by the user to more recognizable names (e.g. Projector, Microwave), depending on how the relays are connected to the building by the electrician.
Cloud: The Google Firebase Realtime Database was used as the cloud provider in our implementation. Google's Firebase Realtime Database is a NoSQL JSON-based database with real-time data streaming capabilities. The JSON was structured as shown in Fig. 11. By design, the Firebase sends data change notifications to all clients that have subscribed to listen to a particular node. This feature was taken advantage of. Clients (the Homergy Box and the Homergy Mobile App) subscribe to nodes corresponding to the state of the relays of the user's Homergy Box, and hence receive a real-time payload of the node anytime the user sends a command. This way, the Homergy Box and the Homergy Mobile App virtually communicate directly.

E. Security
Database access rules (Firebase Rules) and a securityfocused database structure (Fig. 11) was applied such that each Homergy Box could only be controlled by their authorized users. Email-password authentication is required by the app for    usage, and users must always re-enter these credentials after an app reset, re-install, or user-reported suspicion of malicious activity. Each Homergy Box has a unique identification, called the "Homergy Box ID" which can be given to each user upon purchase (to give the user access to the Box). The Homergy Box ID maps to a unique Access Code (like a password) which can be obtained by scanning a QR code hidden at the back of each Homergy Box. The QR Code is an encrypted version of the Homergy Box's unique Access Code. After an in-app QR Code scan (Fig. 10), the code is decrypted by the app and verification and authorization is done. The user can then control the Homergy Box. A user who has been authorized to access a Homergy Box can change the Homergy Access Code with an email-verification procedure, after which the QR Code becomes void. This will also require all other users to sign in again (with the new credentials) to maintain control of the Homergy Box.
Other users in a home can get control simply by scanning the scanning QR Code, or by manually entering the Homergy Box ID and Access Code, within the "Add Box" section of the app, as shown in Fig. 10.

VI. RESULTS AND DISCUSSIONS
In this section, we discuss the results of implementing the proposed Homergy system. The Results of using Homergy as a Home Energy Management System (HEMS) is explored and presented in Fig. 12-14.
Three varied environments were used to measure the effectiveness of Homergy. Two of these environments were selected according to Ghana's energy provider's consumer types: Lifeline Consumers and Non-lifeline Consumers. According to the Public Utilities and Regulatory Commission of Ghana, a lifeline consumer is any consumer whose monthly electricity consumption is less than 50kWh. Consumers with monthly consumption above 50kWh are Non-lifeline consumers. The third environment was a single-user office with Air Conditioning. This is a common energy usage scenario found in workplaces.
Our Key Performance Indicator is the power consumption (in kWh) per week. The kWh parameter has been successfully used by researchers in [2] to compare the energy efficiency levels of various consumer groups. For each of the three environments, we measured the kWh/week for eight weeks. In the first four weeks, there was no Homergy in the environment. In the subsequent four weeks, Homergy had been installed in the environment. Users were allowed to get accostumed to the Homergy Box for a week before measurements were taken in the four subsequent weeks of Homergy usage. The  Non-lifeline consumer had an existing Smart Home Energy Management System (HEMS) whose impact was also measured. The existing HEMS provided energy savings only through smart devices in the house, including smartphonecontrolled Air Conditioning, smart motion-activated bulbs, and a smart energy-saving refrigerator. The findings are presented in Fig. 12 -14. The most commonly used appliances for each environment are shown in Table III.
All three environments with Homergy showed a weekly reduction in kWh compared to their consumption without Homergy. Since the number of users and appliances was constant during the entire test period, this can be explained as an increase in energy efficiency [2].
The implementation of Homergy translated to weekly energy savings of 0.5 kWh for the lifeline consumer, 0.35 kWh for the single-user office, and 18 kWh for the non-lifeline consumer (compared to their usage without any HEMS). According to Ghana's electricity prices at the time of writing, these numbers are equivalent to yearly monetary savings of at least USD 1.3 for the lifeline consumer, and USD 121 for the non-lifeline consumer.

VII. CONCLUSION AND FUTURE WORK
In this paper, a modular IoT-based Home Energy Management System was successfully developed, giving users the ability to control the electrical consumption of their appliances.
This finished work provides users the convenience of controlling appliances from anywhere, integrate the proliferated non-smart devices into the energy-efficient IoT space and also provide a modern energy management approach for both urban and rural areas. The proposed system was also successfully deployed in three real environments that are reflective of possible use cases (moderate energy consumer, offices, and high energy consumers). The results of Homergy's deployment showed increase in energy efficiency for all scenarios (including a 25-kWh energy savings in the first month for a high consumer).
In the future, the Arduino Microcontroller could be removed altogether to make the module cheaper and simpler. This is because the NodeMCU is a microcontroller and can handle the basic switching functions given to the Arduino in our model. The need for more GPIO pins for more relay connections can be met by using special pin-extension modules or shift registers.
The system could be made smarter by taking advantage of Machine Learning. With Machine Learning, the Homergy system could "learn" the habits of users connected to a Homergy Box, and automatically control appliances or give reminders in cases where the users may have forgotten to do so.