IoT Based Smart Electrical Meter for Smart Homes

The mankind’s home has evolved as humanity itself and through history, humanity has observed the safety and comfort of their homes. The adaptation of homes to the modern times, is now involved in a technological environment and constant innovation, especially in the control of appliances, safety, pleasure, the monitoring of electrical consumption, etc. These factors have allowed the integration of homes with IoT environments in what is known as smart home. In this work, an IoT smart sensor of electrical consumption in smart homes is presented which is capable to analyze the power consumption using mobile devices through a wireless connection. The smart meter was designed using a cyber-physical system based on the ESP32 micro-controller in which an embedded Web application is executed that shows the electrical consumption of electrical devices. The aim of this technological IoT smart device is to help to detect the phantom consumption of electrical energy in a smart home environment in order to promote the energy saving. The results obtained show that this kind of IoT technology contributes to decrease the economic expense for home owners and also allows to observe and analyze the electrical energy consumption of di ﬀ erent electrical devices using mobile devices.


Introduction
The world's population is growing and through history, humanity has observed the safety and comfort of their homes. The adaptation of homes to modern times, is now involved in a technological environment and constant innovation such as in the control of appliances, safety, pleasure, monitoring of electrical consumption, etc. These factors have allowed the integration of homes with Internet of Things (IoT) environments in what is known as "Smart Home" (SH) [1][2][3].
SH is a term commonly used to define a residence that has appliances, lighting, heating, air conditioning, televisions, computers, audio and video entertainment systems, security systems and cameras that are able SH is a way to better manage the demands of daily life through technology. This is reflected in a better administration and reduction of household electricity consumption as part of a broader transition to a low carbon future [7][8][9].
This socio-technical vision considers the SH as the next wave of development in the electrification and digitization of everyday life, making a great leap towards the development of a society that coexists between urbanization centered on "Smart Cities" (SC) and the special care of the nature [7][8][9].
The concept of SC applied in homes integrates the new information and communication technologies of Industry 4.0 such as cyber-physical systems (CPS) connected to the Internet of the networks of things to cloud computing applications in order to optimize 1 [10][11][12][13].

EAI Endorsed Transactions on Internet of Things
However, the generation, consumption and conservation of energy are the root of many of the most alarming problems that face the energy industry and indirectly the home consumer in an IoT environment for SH.
The demand of electric energy continues increasing while the ability to generate it and deliver it increases at a much slower space. Therefore, making the management and an efficient use of the electricity produced is essential for collective prosperity and quality of life [14,15].
Saving operative costs and seeking to reduce the need for massive investments are other major challenges. It is here that SC generate a large field of research, because it is an urban area that uses different types of technology, where is possible to manage assets and resources efficiently [16][17][18].
A large part of global consumption of electric energy is due to households where the majority of this consumption is caused by household appliances such as weather heaters, clothes washers and dryers, dishwashers, refrigerators, freezers, electric stoves, lights, etc., that are responsible for an important part of energy bills. The time of use and how long is connected to the power grid has a great impact on the level of energy consumption of each element [6,17,19].
When an electric device is used, it generates different energy loses. Of all electric energy that is intended to consume, only a percentage is used and what is not, is known as loss. This phenomenon goes unnoticed by the user because the registration of the electric energy consumption is done in a general way which implies that each appliance cannot be detected in order to determine which device is generating a cost of kW/h creating an extra cost reflected in the consumer's pocket [4,5,[20][21][22].
The energy distribution and consumption concerns is the control and reduction of losses, oriented on the final consumer, allowing generate an internal analysis of both consumption and control leading to an efficient optimization of energetic resources.
This technology trend is known as smart grids (SG) [23,24], which is the convergence of advances and technological development that help modernize the generation, transmission and distribution of electrical energy, optimizing the operation of the system. SG are presented as a solution to the demand of distributed and intelligent energy management, thus improving the functions of automation, data collection and processing of the information [16,17,24,28].
Another important difference with classical technology, is the incorporation of digital and web technology in such a way there is a two-way flow of information between generators and consumers, thus reducing generation and transmission costs, while improving efficiency and reliability [16,25,26].
This work presents an IoT SM of electrical consumption in SH capable to analyze the power consumption using mobile devices. The SM was designed using a cyber-physical system based on the ESP32 microcontroller which executes a Web app that shows the electrical consumption of electrical devices.
The smart device helps to detect phantom consumption of electrical energy in a SH environment in order to promote the energy saving. The results obtained show that this technology contributes to decrease the economic expense for home owners and allows to observe and analyze the electrical energy consumption of different electrical devices using mobile devices.

Marerials and methods
In order to know the impact of the consumed energy, it is necessary to make measurements, since it is the best way to validate the measures and effects of the energy sector [16,17,26,27]. The problem is that measurements are expensive by involving various equipment and processing time.
There are economic registrars such as data loggers, but they can only register specific charges, their installation is done internally and more time is required for the processing of the information [20,21,28].
Another way to make measurements in the domestic sector is the design and use of equipment with industry 4.0 technology, known as "Smart Meter" (SM), where the software performs the disaggregation of curves of the main appliances, facilitating the handling of the information, allowing at the same time to manipulate the results in a simple and practical way, thus reducing the operating times [22,29,30].
The SM are classified in two groups: The automatic reading meter (ARM), which only have one-way communication to the service provider and used for billing functions. The second one, showed in Fig. 1, is the advanced measurement infrastructure (AMI), which has a two-way communication channel and the ability to perform some maintenance functions. The SM is one of the most important devices used in SG [6,16,17,25,26,31].
In collaboration agreement with the OMADS company [34], an enterprise dedicated to the research, innovation and technological development, new information and communication technologies of Industry 4.0 are being used for building an IoT SM of energy consumption for SH, embedded on a CPS based on the ESP32 micro-controller, in order to monitoring and controlling electrical devices connected to the network with the objective of saving energy and reduce costs in homes. 2 EAI Endorsed Transactions on Internet of Things 10 2019 -04 2020 | Volume 6 | Issue 21 | e2 The aim of this work, was to test a prototype of the IoT SM and to analyze its behaviour and performance under laboratory controlled conditions. By using the IoT SM, electrical data such Voltage and Frequency was measured. The energy consumption information was recorded in real time and was observed by using mobile devices with WiFi wireless communication capabilities. Figs. 2 and 3 show a prototype of the IoT SM which was inserted in an electrical box and was connected to an outlet respectively.    From Fig. 4 and Fig. 5 can be observed that the signal detection stage is realized using an ACS712 current sensor. The signal processing stage uses a LM385 operational amplifier. The other stages are performed by the Web app embedded on the IoT SM which are being designed both, the Web app and the IoT CPS board, by the OMADS company. As can be seen from Fig. 5, the SM supports bidirectional communication between the meter and the home holder. By using mobile devices and a type of IoT communication known as Machine-to-Machine (M2M), the home holder can communicate with the embedded Web application. This allows immediate 3 EAI Endorsed Transactions on Internet of Things 10 2019 -04 2020 | Volume 6 | Issue 21 | e2 action against any anomaly or irregular event in the electrical installation of the home [32,33].
According to Figs. 4 and 5, the ACS712 current sensor, as the showe in Fig. 6, was used for the electrical signal detection stage. This device is based on the linear Hall effect and offers a resistance of around 1.2 m Ohm to the passage of current with an electrical isolation of up to 2.1 kV RMS. The sensor is capable to read direct current up to 30 A and a proportional analog voltage output of 66 mV / A, measuring 500 mV when the input current is zero. The typical output error is ± 1.5% and operates from 4.5 to 5.5V. Because of this is intended for use in 5V systems.
The current sensor sends an analog signal to the IoT SM where the value of the voltage is represented as a sine wave with positive and negative pulses over the time. In order to measuring the current it was necessary to correct the pulses, because of this, a LM385 operational amplifier, as the showed in Fig. 7, was used with the objective to handling only positive pulses. As shows Fig. 7, the LM385 op amp has 2 operational amplifiers that are two independent circuits and each works as a power supplement, working at different voltage ranges.
The LM385 gives a value of 2.5 V for a current of 0 A and increases proportionally according to the sensitivity, having a linear relationship between the voltage output of the sensor and the current.
It is important to mention that the IoT SM was designed in order to automatically unplug it from the general electrical supply. In this sense, after unplug it, the devices connected to the outlet are also unplugged, as a protection system, by using a relay module, as the showed in Fig. 8, which is formed by a coil that creates a magnetic field when the current passes that attracts a metal, cutting off the electricity. When the current ceases, the magnetic field also ceases and the metal returns to its place and the current is restored. Another feature of the relay is that the copper conductor thickness allows the device to work under over-current conditions of up to 5x. The conductive path terminals are electrically isolated from the sensor wires. This allows the sensor to be used in applications that require electrical isolation without the use of optoisolators or other expensive isolation techniques.
The IoT SM was programmed for ignoring electric signals below 25 A. If this value or a superior value is reached, the relay is activated, unplugging the IoT SM and the outlet from the general electrical installation.
The SM also allows to remotely control the relay through the Web application for energy saving and protection purposes. By disconnecting the outlet where the electrical devices are connected and consume energy, helps to avoid phantom energy consumption helping to reduce the cost of the energy.
As mentioned, a feature of the IoT SM is its ability to run autonomous Web applications embedded on chip. After measuring the electrical signals of the input sensor, a set of algorithms to perform the calculations, the storing, the Graphical User Interface (GUI) for the end user and the control of the output actuator were designed and programmed in order to build the Web app which was designed on the programming environment of the Integrated Development Environment (IDE) of Arduino, a computer program composed of a set of programming tools. Thanks to the board manager of the Arduino IDE, it is possible to add support to other micro-controllers and boards such as the IoT CPS. 4 EAI Endorsed Transactions on Internet of Things 10 2019 -04 2020 | Volume 6 | Issue 21 | e2 The Web app embedded on the IoT SM, Fig. 9, is composed of six main elements: The GUI where the electrical consumption of the connected electric device is showed; The weekly consumption button which creates the activity log during the last week; The costs button that relates the consumption to the expense that is generated; The consumption maximum button; The quantity of connected elements button and The report generation button which shows the information to the current consumption at the time of the requisition. In order to see the Web app of the IoT SM through a WiFi network by using mobile devices, the end user should point to the IP address of the IoT CPS in order to view the information on a web explorer.
The Web app allows to observe, to monitor, to analyze and to control the electric energy consumption in real time. The activity log is showed on the Web app and the information is stored on the IoT SM. The microcontroller of the IoT SM records, stores and displays the information obtained by the current sensor.

Results
To analyze the performance of the IoT SM, several tests were carried out connecting different electrical devices with the aim of observing and analyzing the behavior of each device and the performance of the IoT SM. As first test, a stable power consumption device was connected. At second test, a high current electric device was connected. As third test, a short cut was generated in order to test the automatic protection system of the electrical devices connected to the outlet where the SM is connected. Fig. 10 shows the electric consumption of a refrigerator over the time at test one. After connecting this electric device to the SM, as can be seen from this figure, a higher electrical consumption occurs during the afternoon. Fig. 11 shows the Web app during test two, when a 200 W drill, which is a high current electrical device, was connected. As can be seen from this figure, when the drill was power on, the Web application showed the variation of the current over the time in real time.
In third test, Fig. 12, a high current consumption was generated which produced a short circuit. When the short circuit occurred, the relay was activated and the power supply to the outlet was cut off, which prevented a general power outage from the electrical installation. With this test, the protection system for connected electrical devices was validated.

Disscusion and conclusions
Measuring the consumption of electric energy is an important factor for both electric companies and 5 EAI Endorsed Transactions on Internet of Things 10 2019 -04 2020 | Volume 6 | Issue 21 | e2 their customers. By using electric energy meters, consumption control can be carried out. Over the time and with the evolution of the new information and communications technologies of the Industry 4.0, classical energy meters have evolved to smart devices capable to interact in an IoT environment.
Real time optimization control, consumption minimization strategies and predictive control of electric energy consumption are methods that represent a breakthrough in electrical control, not only in the field of consumption, but also in the field of safety, since within the panorama of the prediction is possible to act at the moment before some anomaly occurs.
In this work, an IoT smart sensor of electrical consumption for smart homes was presented. The aim of the SM was focused on the monitoring of the electricity consumption and at the same time on the ability to act when any anomaly occurs within the residential power grid such as a peak consumption generated by some technical failure, which at first glance is very difficult to perceive.
The development of the IoT SM of electrical consumption for SH it was the integration of a Web App embedded on a CPS. This application was designed on the Arduino programming environment, and was connected with a set of electronic components.
To analyze the performance of the IoT SM, several tests were carried out connecting different electrical devices with the aim of observing and analyzing the behavior of each device. The results obtained show that this kind of IoT technology contributes to decrease the economic expense for home owners and also allows to observe and analyze the electrical energy consumption of different electrical devices using mobile devices.

Acknowledgement
This work was supported by OMADS S.A of C.V., and partially supported by "Fondo sectorial de investigacion para la educacion" under contract 241771. Second, third and fourth authors thanks the Master scholarship received by CONACYT through the PNPC Master in Engineering and Applied Technology of the Electrical Engineering Unit from the Autonomous University of Zacatecas, México.