HEMS-IoT: A Big Data and Machine Learning-Based Smart Home System for Energy Saving

: Energy efficiency has aroused great interest in research worldwide, because energy consumption has increased in recent years, especially in the residential sector. The advances in energy conversion, along with new forms of communication, and information technologies have paved the way for what is now known as smart homes. The Internet of Things (IoT) is the convergence of various heterogeneous technologies from different application domains that are used to interconnect things through the Internet, thus allowing for the detection, monitoring, and remote control of multiple devices. Home automation systems (HAS) combined with IoT, big data technologies, and machine learning are alternatives that promise to contribute to greater energy efficiency. This work presents HEMS-IoT, a big data and machine learning-based smart home energy management system for home comfort, safety, and energy saving. We used the J48 machine learning algorithm and Weka API to learn user behaviors and energy consumption patterns and classify houses with respect to energy consumption. Likewise, we relied on RuleML and Apache Mahout to generate energy-saving recommendations based on user preferences to preserve smart home comfort and safety. To validate our system, we present a case study where we monitor a smart home to ensure comfort and safety and reduce energy consumption.


Introduction
Nowadays, increasing energy efficiency is used to face the great world challenges, such as energy security, air pollution, climate change and economic crises, among others. Energy efficiency alternatives have the power to optimize energy consumption and reduce greenhouse gas emissions, thus contributing positively to the preservation of natural ecosystems and human health. Additionally, energy efficiency alternatives help mitigate the economic effects in the workplace [1]. Energy efficiency has aroused great interest in research worldwide, because energy consumption has increased in recent years, especially in the residential sector. For this reason, organizations and governments worldwide are proposing actions for energy conservation with the purpose of reducing energy-related inconveniences. The residential sector is attributed a high energy consumption; however, home automation systems (HAS), combined with IoT, are alternatives that promise to contribute to greater energy efficiency [2].
The remainder of this paper is structured as follows. Section 2 discusses works on IoT, big data technologies, energy efficiency strategies for smart homes, intelligent agents, and machine learning. Next, in Section 3, we introduce the architecture of HEMS-IoT and discuss a case study in which we monitor a smart home to ensure comfort and safety and reduce energy consumption. In Section 4, we present the results from the case study discussed in the before section. Finally, in Section 5, we present the conclusions and the future work.

Related Work
The IoT is modifying citizens' living environments by moving from a traditional home to a smart home [15]. In smart homes, people can control, monitor, and manage energy consumption according to their lifestyle [3]. In this section, we present a review of related works with IoT initiatives for energy efficiency in smart home. We pay close attention to those initiatives using machine learning and big data. For instance, in their work, Kang et al. [16] proposed an IoT-based system that uses a three-level context creation model for environment-sensitive services in the domotic space. IMS was designed with open source software and hardware in order to extend in the IoT context. The system was tested as IMS-based smart home services in two scenarios: a smart home health care service and a disaster management service. Also, Adiono et al. [17] introduced an optimization protocol for WSN through an architecture for a smart home. This architecture is divided into two environments, exterior and interior, which communicate through an access point. The user´s home can be controlled from anywhere and anytime by a smart phone. SQLite database system was used for the implementation and different tests for the validation. Lee et al. [18] proposed a web services architecture for home service environments. Three layers shape the architecture: 1) information layer, 2) management layer, and 3) presentation layer. The service overlay network was used in this work to generate new service composition in the IoT context. By contrast, Montesdeoca-Contreras et al. [19] implemented an IoT application for controlling and monitoring smart homes. Namely, the application allows users to monitor and control domotic devices through tactile functions or voice commands, including a safety net. The application was developed with App Inventor and Android Studio.
Chilipirea et al. [20] proposed a method for creating models for IoT applications that facilitates the generation of robust, energy-efficient systems in a home security system. The model used the overlap between device characteristics to preserve energy and temporarily disable part of them. Elkhorchani and Grayaa [21] proposed a shedding algorithm for home energy usage and an architecture of a smart home energy management system. This work was based on domestic renewable energy sources, wireless communication among domotic devices, a control system and a home management system, and on grid management. Likewise, Salman et al. [22] proposed a smart system for energy efficient IoT-based homes with a cooling system was demonstrated the heat distribution in the kitchen area and virtual model of flow. The system remotely controls heating/cooling and lighting when an occupant leaves or enters the kitchen. In their work, Al-Ali et al. [9] introduced an Energy Management System (EMS) for smart homes. The EMS relies on MQTT (Message Queue Telemetry Transport), is empowered with Business Intelligence (BI) and analytics and uses big data. The system was validated using HVAC (Heating, Ventilation and Air Conditioning) to simulate the small residential area systems.
Baker et al. [23] introduced and tested the algorithm E2C2, an energy-aware multi-cloud IoT service composition which can generate energy efficient composition proposals by adding services from service providers that are scattered globally. By contrast, Matsui [24] proposed an data provision system for both maintaining indoor comfort and decreasing electricity consumption with data provision to modify home resident behaviors. Fensel et al. [25] presented the OpenFridge platform and approach for energy saving in electrical appliances, particularly refrigerators. The approach demonstrated the feasibility of users eventually using it up for data economy and interacting with semantic energy information. Additionally, Hossain et al. [26] proposed an energyefficient cyber-physical smart home system. Using cloud big data and computing, the system monitors the elderly to assist them in maintaining energy efficiency at home. In addition, in this work was proposed a smart multimedia-enabled middleware assistant to receive notifications relating to the status of domotic devices, visualize energy-efficient processes, share multimedia messages and control smart domotic devices through gestures.
Golam et al. [27] proposed an architecture that uses web objects for offering energy efficient comfortable living services for smart home IoT services. In addition, a conceptual semantic ontology model was designed using the tool Protégé for use in the smart home scenario. Additionally, Chauhan and Babar [28] presented a Web-of-Things (WoT) system to manage appliances. The system tries to meet some of the standard business needs and the quality of smart homes. The use of a Reference Architecture (RA)-centered approach for the evolution of the WoT and IoT systems was proposed in this work. In addition, Lanfur and Pérez [29] implemented a real-time video streaming and transmission security system in a residential scale model. The system allows lights to be turned off and on, and doors to be closed and opened as occupants enter/leave a room. Also, the system relies on motion sensors to obtain information that can be visualized through a web interface. Iqbal et al. [30] presented architecture that uses the ZigBee technologies to minimize unnecessary electrical energy usage in smart homes, based in the context of IoT. The architecture is powered by GRAPHX, Bit Data, SPARK, and Hadoop for data analysis.
Marinakis et al. [31] proposed an architecture of a big data platform that can create, develop, maintain, and exploit smart energy services using cross-domain data. A web-based Decision Support System (DSS) according to the proposed architecture was developed to use multi-sourced information to generate management activity strategies in the domotic space. Jo and Ik-Yoon [32] presented three intelligent models as IoT platform application services for a smart home: 1) intelligence energy efficiency as a service (IE2S) to perform the role of a server and process the information collected by IAT using the Mobius platform and an artificial TensorFlow engine for data learning, 2) intelligence service TAS (IST) to manage, and provide control the service stage, and 3) intelligence awareness target as a service (IAT) to manage the "things" stage. Filho et al. [33] proposed STORm, a decision-making solution for residential environments that combines computational intelligence and fog computing. STORm retrieves, processes, disseminates, detects, and controls the information sent by sensors installed in a residential scenario to apply the decisionmaking process. Additionally, Tao et al. [34] developed a multilayered architecture based on the cloud and a home automation anthology supported by the IoT. The anthology was used to address application heterogeneity, data representation, and knowledge.
Iqbal et al. [35] developed an interoperable IoT-based platform for domestic environments using web-based objects and the cloud. The platform facilitates the control of domotic devices from different locations, provides important household information to analyze applications and various services, and tries to improve resource utilization. Yassine et al. [36] proposed a platform for smart homes that combines big data analytics technology and IoT with cloud computing and fog. This platform is a fast and efficient solution that supports large volumes of smart home information. In addition, Matsui [37] presented a HEMS to obtain information from a smart home, with the purpose of maintaining interior comfort and reducing energy consumption according to resident comfort preferences, which were previously provided and set through a web page. On the other hand, Terroso-Saenz et al. [38] presented IoTEO, an IoT energy platform that attempts to be the first holistic solution for the management of IoT energy information. IoTEO relies on FIWARE to deal with energy quality and support data analytics. Likewise, Park et al. [39] proposed a thermal comfort-based controller (TCC-V1) to decrease the energy consumed by cooling residential buildings. To energy optimal control, the controller uses the predicted mean vote (PMV).
Bouaziz et al. [40] proposed EMA-RPL, a new energy efficient and mobility aware routing protocol which is based on Lossy Networks (the RPL standard) and the Routing Protocol for Low power. EMA-RPL enables the better sustaining of connectivity of conserving energy and mobile nodes. By contrast, Mancini et al. [41] presented the characterization of three control systems based on user energy consumptions habits. The authors used a demand/response (DR) program and procedure to evaluate energy consumption and economic savings. Similarly, they conducted a financial analysis of the investment needed to implement the program. Sun et al. [42] proposed an energy-efficient mechanism that optimizes IoT service compositions to support concurrent requests.
The mechanism reduces energy consumption in the network and improves the exchange of IoT services among concurrent requests. In addition, Meena et al. [43] presented a framework for optimal planning of hybrid energy conversion systems (battery energy storage system, photovoltaic cells, and wind turbine) in smart homes. The model aims at generating less costly and more reliable alternatives for smart homes for middle-class families. Alarif and Tolba [12] proposed AQL (Adaptive Q-Learning), a reinforcement-based learning technique to increase network performance with reduced energy-overhead tradeoff in a smart device (sensor) cloud-assisted internet of things (CIoT).
Matsui et al. [4] presented a study on energy usage patterns to then propose an energy conservation action plan. To this end, the researchers gathered real-time data on energy consumption and indoor temperature in a Tokyo residential area using IoT devices and sensors. Then, the data were analyzed using three types of method: a clustering algorithm, a correlation analysis, and a classification of indoor temperature for detached houses with different building structure and ages, and condominium apartments. From a similar perspective, Le and Benjapolakul [44] conducted a study to test the energy yield of the rooftop photovoltaics (PV) systems based on machine learning techniques (i.e., multiple linear regression and bootstrap). The authors identified an association between technical configuration details of PV (number of inverters, number of panels, rated solar panel power, and rated inverter power) and the energy yield. In addition, Castro-Antonio et al. [45] presented a Robotics Operation System (ROS) that integrates various types of services in a single smart home service system. The ROS provides services to smart homes without fully recognizing them through a collection of sensors, cameras, and by incorporating autonomous service robots that can move inside the home and interact with the residents.
Huh et al. [46] introduced the design of a Smart Metering Control System and a series of tests based on power line communication (PLC) using smart agents (i.e., program in charge of collecting data or performing certain actions without user intervention). For the tests, the authors used a smartphone and an Android mobile application. On the other hand, the protocols in the system were developed with languages C++ and C. In addition, the system was developed and integrated in Java with the purpose of being a basic element for the Smart Grid. Likewise, Jung and Huh [47] proposed a model to predict atypical data of a linear transmission point using the A-Deep Q-Learning algorithm in combination with the altered K-means algorithm. The goals were to identify atypical information of the same linear transmission point in big data, and to know the objective of its elements. Additionally, the model makes it easy to automatically select values from cluster k, which is based on unlabeled sensors and big data. In addition, Yassine et al. [48] proposed a model to identify patterns of human activity to support the health care of people from their homes. The model makes use of big data to analyze the activities of the inhabitants at home. Additionally, pattern mining is proposed to analyze energy consumption variation in domotic devices, which depends on the behavior of the inhabitants. Also, in the model, FP-growth was used to identify patterns, whereas the k-means algorithm was used to know the relationship among devices influencing energy consumption.
Zhao et al. [49] proposed a neutral blockchain-based data trading protocol within the big data market to increase the availability, fairness, and privacy of data trading. The blockchain infrastructure has the main advantage of debugging failures in any of the big data market points. Additionally, similarity learning was used to increase the quality and availability of information from data providers, and an extension of the double authentication preventing signature (DAPS) was carried out. Additionally, Risteska Stojkoska and Trivodaliev [50] proposed a framework that integrates different components from IoT architectures/frameworks proposed in other works in order to efficiently integrate smart home objects in a cloud-centric IoT solution. Likewise, the authors identified a smart home management model for their architecture, along with the tasks to be performed at each architectural level. Finally, the authors discussed current challenges in smart home design, emphasizing such aspects as interoperability, information processing, and communication protocols. Rathore et al. [51] proposed an IoT-based system that relies on different types of sensors installed in a home to contribute to smart city development and urban planning through big data. The system uses a four-tier architecture: 1) bottom tier-1, 2) intermediate tier-1, 3) intermediate tier-2, and 4) top tier. In addition, the system is implemented using Hadoop with Spark, voltDB, Storm or S4 for real-time information processing and data collection.
As the previous paragraphs show, a great range of applications and IoT tools seek to contribute to energy-saving efforts in smart houses. Likewise, note that many of the analyzed works established models, communication protocols, technologies, and security paradigms to guarantee the interoperability and integrity of domotic systems. However, it seems that only a few initiatives can automatically, and without much user intervention, handle and operate decisions of smart home devices connected to a domotic control system. From this perspective, HEMS-IoT is a solution that integrates and provides access to information from different IoT providers, domotic devices, and sensors. Likewise, our system analyzes the information collected from big data technologies and machine learning algorithms and offers knowledge on efficient energy consumption and home comfort through recommendations, rules, and alerts. Overall, HEMS-IoT monitors domotic devices and sensors in real time, provides energy-saving recommendations, and facilitates communication and interaction between devices and with users. The following section describes the architecture and functionality of HEMS-IoT and discusses our case study.

Materials and Methods
Home automation is part of the application domain IoT personal and social and thus offers many opportunities for developing new useful applications [52]. Home automation refers to a set of techniques aimed at automating a home, which integrate technology into security, energy management, and welfare. Comfort is essential in a home automation system and comprises all the actions performed to improve the way home residents feel in their houses [37]. However, home automation applied in the IoT faces a major challenge-few communication systems ensure device interconnectivity [50]. This problem arises from the lack of unified protocols and the many different lifestyles of users coexisting in smart cities [53]. In the following subsections, we present and describe the architecture and functionality of HEMS-IoT and discuss a case study where our system is implemented.

Architecture Description
HEMS-IoT is a home energy management system that seeks to contribute to the comfort and security of smart homes, while simultaneously helping residents save energy. To this end, HEMS-IoT uses IoT devices, big data technologies, and machine learning to manage energy consumption. Also, HEMS-IoT allows for the real-time monitoring of domotic devices and home sensors. All the information obtained is analyzed and processed using machine learning algorithms to learn energy consumption patterns and user behavior patterns and make relevant recommendations for cutting energy waste.

HEMS-IoT: Architecture and Functionality
HEMS-IoT has a seven-layered architecture, which facilitates the system's maintenance and allows for high scalability. The architecture of HEMS-IoT is presented in Figure 1, and integrates the presentation layer, the IoT services layer, the security layer, the management layer, the communication layer, the data layer, and the device layer. Every layer has a clearly defined function and includes multiple components having a specific functionality within their corresponding layer.
 Presentation layer. This layer ensures bonding between the user and the system through either a mobile application or a web application. At the presentation layer, users can visualize energy consumption data, available IoT services, power consumption history, and recommendations. As a web application, HEMS-IoT receives information and allows users to manipulate and control domotic devices through various devices. As a mobile application, HEMS-IoT works on the Android operating system for users to manage and control domotic devices. In addition, with the mobile application, users monitor home domotic devices, incorporate new rooms, remove or add domotic devices from a particular room in the house, and obtain energy-saving recommendations. The application also displays charts to consult energy consumption patterns on a daily, weekly, and monthly basis and offers users energysaving recommendations for their smart homes.  Security layer. This layer guarantees information security and hence guarantees the confidentiality and secure collection of data from the device layer. Communication between the device layer and the security layer is not direct, since they communicate through the communication layer and the management layer.  IoT services layer. This layer serves as a link between the application layer and the management layer. Additionally, this layer provides various REST services, allowing users to fully exploit the functionalities of HEMS-IoT.  Management layer. This layer performs and manages the actions to meet user requirements requested at the application layer. To this end, the IoT layer uses the REST API to ensure communication between the presentation layer and the management layer.  Data layer. This layer saves the data generated in the device layer. Namely, the data layer relies on modules to manage five types of information: recommendations, service profiles, sensed data, device profiles, and user profiles. The recommendations module is responsible for managing comfort and energy-saving recommendations. In turn, the service profile manages data on the provision of system services. The sensed data module saves and manages all the information collected by the device layer from the smart home, such as gas/water/energy consumption and room temperature, among others. The device profile module handles data on domotic devices, such as their status and location, among others. Finally, the user profile module manages user information, such as full address, name, and gender, among others.  Communication layer. This layer considers elements such as a set of sensors, HTTP and TCP/IP, and 4G communication to establish the communication protocols for each domotic device. Other layers in the architecture communicate with each other through the communication layer.  Device layer. This layer facilitates data linkage and reception from various domotic devices.
Also, the device layer controls actuators and home automation devices.
The following subsections describe the most important aspects of HEMS-IoT.

Device Layer
An efficient home energy-saving system must take into account resident preferences in order to successfully control how domotic devices operate in the house. However, home energy consumption also depends on other factors, such as external environment, natural ventilation, temperature variations through seasons, and the age of residents, to name but a few. Some examples of the devices considered in the device layer of HEMS-IoT are listed as follows:  Gateways. These objects allow smart home automation devices to remain interconnected.
Likewise, gateways are the link between external networks and domotic devices installed in the smart home and make it easier to control domotic devices both remotely and locally. The gateways used in smart homes are border devices that allow access between external and local networks within a house. Because the different home automation devices linked to the smart home connect to other networks or even the Internet, gateways handle the main communication access between those networks.  Sensors. They collect data on different parameters of the smart home, such as risk of burglary, gas or water leaks, and room temperature, among others.  Actuators. They are usually of various types and are installed throughout the house. Actuators are used to change the status of domotic devices and some home facilities. For instance, actuators can interrupt the water and gas supply, issue failure or risk warnings, increase or decrease temperature from air conditioners, or adjust light intensity from smart bulbs.  Controllers. These devices allow users to control domotic devices with respect to the chosen parameters. HEMS-IoT retrieves data from the various sensors installed in a house and processes the data by means of an algorithm. Then, the system prepares the rules necessary to invoke the actuators. Likewise, HEMS-IoT allows users to monitor the status of the operating domotic devices, thus making home residents completely involved in the process. Users can also control and program the actuators and sensors installed in the smart house through a centralized control system and using a touch screen, a keyboard, or a voice interface, among others.

Communication Layer
Home needs vary across smart homes, yet the most common include indoor cooling or heating, hot water, and lighting. HEMS-IoT needs to draw upon on reliable communication networks to successfully retrieve energy consumption data and user behavior data. Some of the protocols used in the communication layer of HEMS-IoT are listed below:  ZigBee. The ZigBee Alliance developed the ZigBee protocol following the IEEE802.15.4, a lowpower wireless network standard. ZigBee is a low-cost and high-level protocol used to establish personal networks through reduced, low-power digital radios that send information wirelessly to larger areas. In addition, ZigBee is used in low information rate applications that require secure networking and long battery life. Finally, ZigBee considers various kinds of network topologies, including the tree, star, and mesh topologies.  TCP/IP. The US Department of Defense developed the Transfer Control Protocol/Internet Protocol (TCP/IP) with the purpose of intercommunicating computers with various operating systems (minicomputers, PCs, and central computers), which work in local area networks (LAN) or wide area networks (WAN). The TCP/IP protocol is a group of protocols that determine various premises and rules for machines from different providers to exchange data through public telephone networks, such as WAN and LAN networks. The Internet design is based on the TCP/IP protocol.  HTTP/IP. The World Wide Web Consortium (W3C) and the Internet Engineering Task Force (IETF) developed the Hypertext Transfer Protocol (HTTP), which is used in any type of transaction made over the Internet. HTTP helps to define the semantics and syntax used by various agents (servers, clients and proxy) to communicate among them. HTTP is a requestresponse-client-server protocol, where the HTTP user sends a request to an HTTP server; then, the server returns the message with a response. User requirements include programs, translations, files, and database queries, among others. All the data executed on the Web through HTTP are identified with either an HTTP address or a uniform resource locator (URL).
The communication layer helps home residents control smart home devices, both intelligently and efficiently. The goal in this layer is to collect information from the different IoT-based devices installed in a smart home. These data provide information on the home, such as energy consumption, room temperature, motion, and the air conditioner's temperature, to name but a few. Figure 2 illustrates the general workflow of HEMS-IoT in the communication layer. As seen in Figure 2, sensors are a key element in smart home monitoring. By collecting real-time information, sensors allow HEMS-IoT to analyze and identify how much power smart home appliances and devices are consuming. Users can visualize and monitor this information on a daily basis to make the necessary energy-saving adjustments. Also, thanks to sensors, HEMS-IoT can issue appropriate energy-saving recommendations and invoke both basic services (e.g., plumbing and electrical repairs) and emergency services (e.g., police, firefighters) when required.

Management Layer
This layer uses machine learning and big data storage technologies to easily manage and analyze the information collected in the device layer. Similarly, information access commands are encapsulated by the management layer to ensure information security. The management layer also identifies user behavior patterns and classifies homes according to their energy consumption patterns using the API of Weka 3.8, which is the stable version of the open-source software and successfully helps HEMS-IoT comply with the required functionalities. To classify data and generate energysaving recommendations, HEMS-IoT uses an open source Java implementation of algorithm C4.5, which is the J48 machine learning algorithm. C4.5 and J48 are used to generate decision trees, and they are classification algorithms. Classification algorithms are widely used in healthcare and have proved to yield outstanding results in the diagnosis of hepatitis [54], cancer [55][56][57][58], heart disease [59], eye diseases [60], and tumors on digital mammograms [61]. In addition, J48 has a better performance than other algorithms, such as random forest, CART [62], random tree, fuzzy C-means, and REPTree [63].
HEMS-IoT was developed and implemented in a modular and generic way, with better application extensibility, ease of implementation, and with a view to high performance. The tasks performed by the management layer can be divided into four groups: 1. User management. Comprises actions such as deleting and editing user profiles and user registration, among others. 2. Home management. Encompasses actions of data deletion, data editing, and management of domotic devices, among others. In this sub-module, we developed an anthology of domotic resources, as recommended in multiple research works [64][65][66][67][68][69]. To this end, we used a subversion of the web ontology language (OWL), the OWL-DL, which is based on the SHI2 description logic. Likewise, OWL-DL has a broad vocabulary and greater expressiveness than RDFS. Figure 3 depicts a fragment of the developed ontology, which present the main domotic concepts, such as home activity, environment, entity and stay, among others. We also followed the Methontology method to develop the home automation ontology [70]. That is, we conducted different operations, each based on particular aspects of the conceptual model of knowledge: relationships, terms, axioms, taxonomy, rules, and mathematical approximations of elements.
3. Recommender system. This system issues recommendations for energy saving and home comfort based on home residents' behavioral patterns. To this end, the system takes into account both daily and average energy consumption values from each domotic device, which allows the system to generate the rules in the algorithm. Therefore, smart homes are classified on a daily basis with respect to four energy consumption categories: normal, low, medium, and high. Once the classification is performed with the J48 algorithm, the rules are established according to energy consumption categories. In this sense, energy consumption is calculated with respect to the number domotic devices connected in a home, the average number of home residents, and the season (spring, summer, autumn, and winter). The algorithm rules identify and indicate how the energy-saving recommendation process works. We also used Apache Mahout and RuleML to generate energy-saving recommendations. Apache Mahout is a free software library that supports the scalable implementation of machine learning algorithms. On the other hand, RuleML is based on XML (Extensible Markup Language), which is used for the immediate exchange of rules. Finally, the recommender system of HEMS-IoT not only issues recommendations, but it also suggests IoT services to solve safety problems.

Dashboard. This displays graphical representations (charts) of the main smart home indicators
(electricity, gas, or water consumption) and resident habits. The technologies used in the system are very important, because they allow HEMS-IoT to analyze and display visual representations of energy consumption. Through these charts, users can make sound energy-saving decisions and thus optimize energy consumption in their homes.

IoT Services Layer
This layer provides various REST-based web services to communicate with both the application layer and the management layer. Consequently, HEMS-IoT users can easily interact with the system's functionalities. The main components in this layer are described below:  REST API. REST collects information or performs operations on such information in all possible formats, such as JSON and XML, using HTTP. REST is a good option if compared to other protocols for information exchange, such as the Simple Object Access Protocol (SOAP), which has a high capacity but is complicated.
 Service selector. This module validates the parameters passed on by the presentation layer and choosing the required services. Likewise, the service selector has the power to either give or deny services, according to the authentication data and received parameters.

Security Layer
This layer guarantees data confidentiality and can retrieve data protected by both the device layer and the end users. The communication layer and the administration layer facilitate communication between the security layer and the device layer. This layer considers two security components, authorization and authentication, described below:  Authentication. This refers to the act of validating with evidence that something/someone is what/who they claim to be. Object/device authentication involves ensure its origin, whereas confirming user identity usually implies user authentication. In HEMS-IoT, user authentication requires ensuring that the user who wishes to interact with the system is truly who he/she claims to be. When this is the case, HEMS-IoT authorizes said user to access the system.  Authorization. This occurs after user identity is authenticated by the system. The goal of authorization mechanisms is to protect user information and prevent unauthorized or unidentified users from accessing data or performing particular tasks. Authorization and authentication are different, since authorization involves the tasks that users are allowed to perform or the information that can access once their identity is confirmed. User authorization is applied either to individual elements or to a set of them. In smart home management systems, each element relates to an activity to be run.

Presentation Layer
As a mobile application, HEMS-IoT works on the Android operating system. Figure 4a illustrates the application's menu list on the presentation layer. The main menu options include home (i.e., return to the initial screen), favorites (rapidly access preferred rooms), statistics (visualize energy consumption patterns), rooms (view home rooms), and devices (visualize domotic devices and sensors connected to the smart home). Additionally, the application's menu allows users to add and remove devices or rooms, view existing user profiles, consult and change application settings, and exit the application. Figure 4b illustrates examples of comfort, safety, and energy-saving recommendations issued by HEMS-IoT.   Figure 5a shows a yearly graph and a weekly graph generated by HEMS-IoT. Graphs allow application users to visualize energy consumption data daily, weekly, monthly, or yearly.
Additionally, as Figure 5b illustrates, the HEMS-IoT mobile app provides a set of user interfaces for home residents to view and request basic services available in the IoT (e.g., plumbing and electrical repairs). Thanks to the use of IoT technologies and machine learning techniques, HEMS-IoT helps residents to monitor their smart homes easily and in real-time and provides energy-saving recommendations accordingly. In the light of a fire or safety problems, the system intelligently requests emergency services (police or fire services), notifying home residents of the possible risk.

Case Study: Monitoring a Smart Home to Ensure Indoor Comfort and Safety and Reduce Energy Consumption
In this section, we introduce a case study to validate HEMS-IoT in the smart home's comfort, safety, and energy saving. The case study depicts how a home resident can monitor user energy patterns and total energy consumption in their smart home and how HEMS-IoT can generate energysaving recommendations accordingly. Overall, the case study scenario can be described as follows:  A smart house equipped with six sensors-a water flow sensor, an energy control sensor, a gas sensor, a motion sensor, a sound sensor, and a temperature sensor-needs to be monitored to ensure it provides its residents with appropriate comfort and safety while simultaneously reducing energy consumption. Figure 6 introduces a visual representation of the scenario. As can be observed, home data and/or events are monitored through the six sensors, which send the data and/or events to a synchronized gateway. This mechanism ensures that the appropriate information is sent to each sensor supplier. Subsequently, HEMS-IoT requests home data from each sensor supplier to ensure indoor comfort and issue energy-saving recommendations according to the resident's preferences. HEMS-IoT receives and analyzes the data to identify 1) energy consumption patterns, 2) possible problems within the normal operation of the house, such as water or gas leaks and electrical failures (which may increase energy consumption), and 3) possible emergencies compromising home security and integrity (e.g., flood, fire, burglary attempt). If a problem requires requesting a basic service, HEMS-IoT locates available basic service providers to handle the request. Then, the system notifies the user of the problem and displays basic information of each provider (i.e., name, address, telephone number, open hours, costs, and references, among others). The user can then choose their preferred provider and sends the service confirmation to the system to notify the corresponding provider, so that the service request is answered. Conversely, if HEMS-IoT identifies a safety emergency, it automatically invokes an emergency service provider (police service, fire service) by sending basic data on the house (e.g., address, type of emergency, the data and/or events emitted by the sensors, owner). The system simultaneously notifies the home resident of the emergency to help them take the necessary measures, depending on whether they are in the house or not.

Methodology
The main goal of the case study is to calculate energy consumption in smart homes and classify consumption rates with respect to what HEMS-IoT sets as a normal energy consumption level. The case study was conducted among ten houses from a Mexican residential complex. The houses were of two types, as listed in Table 1. As can be observed, the first home design is smaller than the second one, and this difference lies in the number of bedrooms: the houses with the first design had two bedrooms, whereas those with the second design had three bedrooms. The first house design is suitable for three residents, while the second house design is appropriate for four people. All the houses had at last two smart plugs. The ten houses were equipped with sensors to visualize and document data such as motion and room location, lighting, and temperature. The sensors collected and sent the data to the data layer every 30 seconds, thus generating more than 2500 data per day.

Smart Home 1 Smart Home 2
Room 1 Two lamps, one light, one TV, and one air conditioner Two lamps, one light, one TV, and one air conditioner Room 2 One computer, one TV, one iron, and one light One computer, one TV, one ceiling fan, and one light Room 3 Not applicable Two lights and one iron Living room One ceiling fan, two lights, and one TV One ceiling fan, one video game console, one television, and two lights Dinner room Two lights and one ceiling fan One ceiling fan and two lights

Kitchen
One electric stove, one refrigerator, one blender, and two lights One electric stove, one refrigerator, one microwave, one blender, and two lights Since it was important to determine energy consumption in the smart homes both before and after using HEMS-IoT, we applied the following methodology:  The first monitoring period (before using HEMS-IoT) lasted eight months, from mid-January to mid-September 2018. All the residents were asked to interact with their domotic devices normally without paying particular attention to energy consumption or using HEMS-IoT. At this stage, energy consumption in each home was noted as stated in the electricity bills, which are issued by Mexican electricity company CFE, by its Spanish acronym.  The smart home residents were given the HEMS-IoT manual to learn how to use the application.
The manual is a written guide of the HEMS-IoT application, as it describes all the system's functionalities that help control domotic devices and visualize energy consumption patterns.  The second monitoring period (while using HEMS-IoT) also lasted eight months, from mid-January to mid-September 2019. During this period, the smart home residents used their domotic devices normally but were also asked to follow the system's recommendations for energy saving, which took into account their own indoor comfort preferences. Note that every time a recommendation is accepted in HEMS-IoT, the system executes the necessary operations to control and program the domotic devices accordingly.  During the second monitoring period, data on energy consumption was collected thanks to HEMS-IoT's device layer, but also through the CFE bills. The data collected in this second period helped us identify energy consumption patterns following the use of HEMS-IoT and its recommendations.  The data were analyzed through big data analysis technologies to recognize usage patterns across domotic devices, home comfort preferences, and house problems or security risks. Then, thanks to the J48 machine learning algorithm, home residents, domotic devices, and smart homes were classified with respect to energy consumption levels. HEMS-IoT relies on the J48 machine learning algorithm that uses the 10-fold cross-validation technique to achieve a predictive model. This validation technique is widely recommended for accurate estimates due to its low variance and low risk of bias [71]. Additionally, the J48 machine learning algorithm has demonstrated better performance than other algorithms [72][73][74]. Finally, to generate the energy-saving recommendations, HEMS-IoT uses both Apache Mahout and RuleML. Note that some system recommendations are in the form of requests for IoT services (either basic or emergency services).  To determine whether HEMS-IoT actually managed to reduce energy consumption in the ten smart homes, we compared the data collected during the first monitoring period (mid-January to mid-September 2018) with those collected in the second period (mid-January to mid-September 2019).

Results and Discussion
HEMS-IoT gives home residents a more significant expectation of energy consumption in smart homes, because it collects deeper data through its service layer using machine learning and big data technologies. In this section, we analyze the data collected by HEMS-IoT during the case study to identify energy consumption patterns and understand the circumstances encouraging such patterns. Additionally, we propose a series of energy-saving actions and we present a user-centered evaluation.

Data Analysis
We conducted daily, weekly, and monthly data analyses to identify trends in energy consumption. Due to missing data, we used the average aggregation technique to calculate the average of the original valuation and transfer this value to a lower frequency. According to experts, this technique has yielded remarkable results when applied in sensor networks [75][76][77]. Next, we analyzed the HEMS-IoT recommendations. Likewise, we organized energy consumption data by establishing a continuous order, and we assigned 0 as the daily energy consumption value to domotic devices not used on a daily basis, such as irons.
Regarding room lighting and temperature, we found that 12.5% to 22.5% of the total energy is consumed by air conditioning systems. Also, our results reveal that during the first months of the second monitoring period, home residents still seemed to pay little attention to how much power they were using; that is, we found evidence of excessive use of the air conditioners and lights on in empty rooms. We also identified smart homes where energy consumption levels were higher when the residents were absent. This phenomenon was particularly visible in households with children. In the end, these homes were classified into the low/poor energy consumption efficiency category as a result of the cluster analysis. We also identified two smart homes where energy consumption was disproportionate with respect to the number of inhabitants. This phenomenon might be explained by the use of the air conditioners.
To identify energy consumption patterns, we conducted a daily analysis by paying close attention to the time of the year: spring, summer, fall, and winter. Overall, we found that daily energy consumption was higher at night and in the afternoon than in the morning. Likewise, we found that some hours can be important indicators of daily energy consumption in smart homes. Our results also indicate that energy use levels vary significantly across seasons. Undoubtedly, the demand for electric energy increased during the winter (use of heaters) and decreased during the summer (use of air conditioners). Finally, our results confirm that during the school summer break (July -August), energy consumption in smart homes with the second design significantly increased due to video game consoles.
Our analysis of smart home energy consumption also led us to propose a series of energy-saving recommendations that can help residents cut energy waste and lower energy bills. Overall, it is very important to pay close careful to the use of both room lights and air conditioning systems. According to Mexico's Energy Ministry (SENER, by its Spanish acronym), both cause a great deal of electricity waste. We also conducted a simulation of IoT service requests, since this system functionality was not exploited during the case study. The results obtained from the simulation were satisfactory, thus confirming that HEMS-IoT is well prepared to invoke IoT services as soon as the suppliers adopt this new paradigm.

Comparison Results and Findings
During the case study, we gathered energy consumption data before the residents used the HEMS-IoT application, but also while they were using it. As a result, we conducted a before-andafter comparison to identify differences between the two monitoring periods (mid-January to mid-September 2018 vs. mid-January to mid-September 2019). Since in Mexico energy bills are issued on a bimonthly basis, our analysis follows the same trend. According to our results, visually depicted in Figure 7, HEMS-IoT reduces energy consumption from 42 kWh to 90 kWh every two months. We attribute these results to the fact that smart home residents followed the energy-saving recommendations issued by HEMS-IoT. Additionally, we believe that the satisfactory results were also due to the following aspects:  Interest from smart home residents in cutting energy waste, and discipline to change energy consumption habits.  Adequate and optimal use of domotic devices, particularly those with higher demand for energy, such as air conditioners (e.g., limiting room temperature to 20-25°C and setting automatic device shutdown for empty rooms).  Acceptance of HEMS-IoT recommendations for energy saving. Energy consumption is highly dependent on resident behavior. In this sense, the performance of our system is bound to whether residents follow HEMS-IoT recommendations. For instance, our results reveal behavioral changes with respect to the use of the air conditioner. Initially, these were used for longer periods of time, even in empty rooms; however, during the second monitoring period, we found evidence that residents limited air conditioner temperatures to 18-24 °C and set the application to automatically turn the air conditioner off once the room was empty.  Smart home residents who accepted more HEMS-IoT recommendations and changed their home automation habits managed to better cut their energy waste.

User-Centered Evaluation
It is very important that mobile applications achieve their goals regarding end-user satisfaction, which depends largely on quality aspects such as design, service, assistance, utility, and usability. On the other hand, to evaluate recommender systems, precision and accuracy metrics are widely used in the literature. However, several researchers have identified that the use of recommendation systems that provide personalized assistance to find relevant information generates a high perception of satisfaction [78,79]. In this regard, it is necessary to investigate recommendation systems from a usercentered perspective [80]. Therefore, the HEMS-IoT system was evaluated through the User-Centric Evaluation Framework for Recommender Systems [81] which is based on a theory about human behavior that can be used in situations such as the use of a specific system.
The overall goal of this last evaluation was to measure the user's perception of HEMS-IoT regarding the quality of the recommendations generated by the system, the level of satisfaction, the effectiveness, and the intention to use. Figure 8 depicts the theoretical model used in this experiment. Specifically, the hypotheses aim to explain the perceived recommendation quality by the user about the energy-saving recommendation method as well as how perceived quality influences the system's effectiveness and the satisfaction perceived by the user. Furthermore, this experiment considered the user's intention to use [82], aiming to determine if the system's effectiveness and the user's perceived satisfaction have a positive influence on users to continue using the HEMS-IoT system. The people involved in this case study (21 women and 14 men between 18 and 59 years) were asked questions to measure their experience and perceptions using HEMS-IoT. The questionnaire used in this work was adapted from standardized data collection instruments focused on measuring user-system interaction.
Specifically, the questionnaire used in [81] was slightly adapted to identify the user's perception regarding perceived satisfaction, perceived system effectiveness, and the quality of energy-saving recommendations. Meanwhile, the questionnaire proposed in [82] was used to measure the perceived recommendation quality, and the questionnaires presented in [83] and [84] were used to identify the user's intention to use. Table 2 describes the final questionnaire, which is based on a five-point Likert scale ("Strongly disagree" to "Strongly agree") that helps quantify user satisfaction. Table 3 describes the results obtained for the perceived recommendation quality (PRQ) of the users, the perceived satisfaction (PS), perceived system effectiveness (PSE), as well as their intention to use (ITU). As can be observed, the average results were 3.81 for PRQ, 3.45 for PS, 2.98 for PSE, and 4.07 for ITU.

Perceived Recommendation Quality
Perceived System Effectiveness 1. I like the energy-saving recommendations provided by HEMS-IoT. 11. The system is useful.
2. The energy-saving recommendations fit my comfort preferences.
12. The system makes me more aware of energy consumption at home. 3. The energy-saving recommendations provided by HEMS-IoT were well chosen.
13. I make better energy-saving decisions with HEMS-IoT.
4. The energy-saving recommendations were relevant. 14. I can have better energy savings without use HEMS-IoT. 5. The system provided various inefficient energysaving recommendations.
15. I can decrease the cost of energy consumption using HEMS-IoT.

Perceived Satisfaction
Intention to Use 6. I like the energy-saving recommendations I have accepted.
16. I will use this system again for energy saving. 7. I am comfortable with the energy-saving recommendations accepted.
17. I will use this system more frequently for energy saving. 8. I feel happy to have a more efficient energy consumption.
18. I will tell my friends or acquaintances about this system. 9. I would recommend some of the energy-saving recommendations I have accepted to friends or family. 19. I am very likely to use this system for energy savings at home.
10. The energy-saving recommendations fit my comfort preferences.
20. I am very likely that I would recommend my family to use this system. To identify the importance of all aspects presented in Figure 8, the obtained results were analyzed statistically by using the T (statistical) value, the p (importance) and the correlation (size effect). Figure 9 depicts the results obtained from this analysis. Furthermore, Pearson correlation was performed to determine the relatedness between the perceived recommendation quality, the perceived system effectiveness, and perceived satisfaction. As can be observed from Figure 9, perceived recommendation quality positively influences the perceived system effectiveness (r = 0.675, p < 0.5) and the perceived satisfaction (r = 0.891, p < 0.01). Also, perceived system effectiveness (r = 0.669, p < 0.05) and perceived satisfaction (r = 0.943, p < 0.01) have an important influence on the user's intention to use. Finally, it should be noted that perceived satisfaction obtained higher correlation values than those obtained by the perceived system effectiveness; hence, we can conclude that perceived satisfaction has a stronger effect on user's intention to use HEMS-IoT.

Conclusions
Energy efficiency has become a key research area, because energy consumption exponentially increases as years go by, particularly in the residential sector. If combined with the IoT paradigm, home automation systems are promising energy saving alternatives. The IoT can successfully collect, distribute, and analyze data to convert it to knowledge and information; however, IoT devices for smart homes have limited resources. To overcome this limitation, it is important to consider other data handling alternatives-such as machine learning and big data-to collect, manage, and analyze large volumes of data. The big data analytics technologies are used to obtain and analyze large amounts of data, whereas machine learning algorithms and statistical models based on patterns and inferences are needed by the system to meet its goals. Additionally, machine learning provides alternatives to learning-based problems and identifies the background and characteristics of such problems in order to learn from them and increase system functioning.
Current challenges in the residential sector related to energy consumption are areas of opportunity for the IoT paradigm, machine learning, and big data technologies. In this work, we proposed HEMS-IoT, a big data and machine learning-based smart home energy management system for home comfort, safety, and energy saving. Machine learning techniques and big data technologies are important in our work, because they are used by the system to analyze and classify energy consumption efficiency, identify user behavior patterns, and ensure home comfort. We used the machine learning algorithm J48 and Weka API to learn energy consumption patterns and user behavioral patterns. Also, RuleML and Apache Mahout were used to create energy-saving recommendations based on user preferences to preserve smart home comfort and safety. We presented a case study to validate HEMS-IoT, where we monitored a smart home to ensure home comfort and safety and reduce energy consumption. In conclusion, three factors were fundamental in achieving energy consumption reduction in this case study: 1) the commitment of smart home inhabitants to change their energy consumption habits, 2) follow-ups on the system's energy-saving recommendations, and 3) the fact that the system allows users to modify the operating parameters of domotic devices. From this perspective, we trust that the results obtained in this work will be a motivation for more users to rely on HEMS-IoT when seeking a smart home management alternative that makes it possible to optimize energy consumption and thus make savings.
Our proposal has five main constraints. First, the HEMS-IoT mobile application only works on the Android operating system, even though we know that the tablet market is dominated by iOs. Second, our system is only compatible with some types of home automation sensor. Third, we only use big data technologies and the J48 machine learning algorithm. Fourth, the system does not generate customized energy-saving recommendations due to some limitations having arisen during the research process. Five, we did not collect data on energy consumption from domotic devices before the implementation of HEMS-IoT.
As future work, we will seek to implement HEMS-IoT on a larger scale and among smart homes using a greater number of domotic devices. Additionally, we will intend to incorporate locationbased functionalities in HEMS-IoT by relying on the GPS from mobile devices. In this sense, we expect that HEMS-IoT will be able to estimate residents' arrival time at home to increase comfort by performing actions such as playing music or turning the air conditioner in advance based on the mood of the user. Finally, we will seek to include solar panels-in order to minimize electrical energy consumption-and implement more advanced security strategies, such as blockchain and cyber security.