Design of a Smart Energy Management System for Photovoltaic Stand-Alone Building

PV stand-alone buildings, that depend completely on PV array, are suffering from the uncertainty of the supplied power due to weather conditions. To manage this uncertainty and reduce the risk of completely losing power, the proposed system offers a design that able to manage the consumed power according to the produced energy, battery capacity, and weather conditions, it also gives permission for the user to select its load priorities. A hardware prototype has been built to simulate all the system possible states included; PV voltage & current, the battery capacity, PV produced power, the loads. An ESP32 microcontroller has been used to adapt accurate forecasting and loads management strategy with a prediction model for managing the consumed energy with hourly and two days ahead planning. The results show a promising module that able to manage the stand-alone building energy without affecting the quality of life.


Introduction
Population growth and economic activity in addition to increasing the individual's requirements for electrical energy are the most important reasons for the high cost of production and distribution of electrical power. Therefore, there is a need to use renewable, sustainable, and environmentally friendly sources [1]. However, these sources have the disadvantages of being unreliable and volatile depending on weather conditions such as solar photovoltaic and wind energy, as the production energy of photovoltaic is affected by the movement of clouds [2]. This effect is clearly visible at peak time, so a balance must be between energy production and consumption, therefore, many methods have emerged to solve the problem of fluctuating production energy and reduce its impact on users [3].
Several studies have been carried out regarding finding the optimal solution for energy management. Such as, cost optimization algorithms for reducing the overall cost of electricity without limiting consumption are presented in [4]. As well as, intelligent smart energy management systems (ISEMS) to manage energy demand in a smart grid environment in [5]. For example, authors insert approximation for home energy management system that founded on task classification to find the best task activation plan regarding the boarder requirements and instrument qualifications [6]. Moreover, a step-wise demand response program (DRP) is also treated, in the energy management to get a costeffective operation in [7]. Furthermore, linear programming, nourishing the in-house temperature within its threshold, simulation results show reduces the energy consumption of thermostatically controlled loads (TCLs) and photovoltaic-battery systems by 30% while taking part in client's quality of the trial [8]. Researchers have adopted an algorithm where devices are shifted to engage on battery instead of shifting to other times and thereby human rest is less fracture and attains a reduction in  [9]. A master control unit is used to calculate available power from PV, stored energy, weather prediction to manage energy consumption by reducing consumed power according to the priority list [10]. A building-integrated photovoltaic (BIPV) is proposed that primarily self-feeding of buildings equipped with PV array and storage system, with the intent of cancel of various energy conversions [11]. In [12], researchers are presented a model that uses two optimization standards; the loss of power supply probability concept for reliability, and the active cost for an economic estimate, to carried out by reducing the wastage power supply probability and by reducing the shading of the load. Nevertheless, a priority load control algorithm has been advanced in order to earn optimal energy management over system loads and the battery storage, and therefore tool up a better energy management efficiency and undertaken the energy supply for high loads [13]. While in [14], there is a proposed that aims to optimize the demand side management for a stand-alone photovoltaic system (SAPS) without helpful source in wilderness regions used two strategies, first by decreasing the loss power supply eventuality to decrease of load shedding, and the second by the refinement the life cycle of batteries to reducing the batteries changes. Optimal energy management is presented in [15], with tracking technique, and modes of operation that based on the variation between the supply and the load demand. However, in this work, the system gathering data about the produced solar energy, the batteries charging status, the loads' consumed power, and the weather conditions for the next two days which determine the most appropriate group of loads to turn on and off. The adopted energy management strategy is depending on dividing the loads' priority into three levels, according to user requirements. In case there is shading in the power the system reduced the low priority loads and the medium priority loads if the shading in power greater, in order to save power for high priority loads. The proposed system manages the loads according to the available power. It is significant to know that available power based on the power generated from the solar photovoltaic, batteries storage energy and the power determined by the weather condition for the coming two days.

System Design Aspects and Methodology
The main design aspect adopted in this system is managing the consumed power below the produced power according to gathered data about the produced power, the consumed power, the battery status, and the weather conditions for the present and two days ahead. The proposed system has the ability to monitor and control all the devices in the building; it is also monitoring the produced power by the PV system, and the battery capacity as showing in Figure 1.
The system main core controller is a microcontroller ESP32, that has many features includes; sensing analogue signals from PV and batteries, built-in Wi-Fi module for communications, an RS232 communication protocol that make it compatibles with PZEM-004T (AC Power sensor) and read/write digital signals that will be used to control the loads via relays. Below a list of the main electronic components used in the design:

ESP32 Microcontroller Module
It is a low-cost, low-power chip microcontroller, see Figure 2a, with integrated Wi-Fi and Bluetooth, has several analog and digital ports, the chip receives data from the sensors and performs processing and communicate these data. All calculations, monitoring, prediction, and decision making is carried out in this microcontroller, and it is responsible for managing the load by turning them ON or OFF based on user classification of the loads, the sensors data, and weather prediction.

Router
It is a networking device that is used to link between different nodes of the system. It uses a Wi-Fi signal to connect one or more microcontroller based on the size of the system with the main PC or smartphone for monitoring and sending requests and getting responses between them, the router can be connected to the Internet if the system needs to be controlled from a remote area.

AC Power sensor PZEM-004T v3
This sensor connects to the power supply cable of each device. Where it converts the analog signal from the current transformer to a digital signal and then transmits it via serial communication receive data (Rx), transmit data (Tx) [16] to exchange data with control unit ESP32. It measures the power consumed for the load as well, current, voltages, energy, frequency, and power factor as shown in Figure 2b. Since the system can monitor and control more than one device or loads, the load may consist of more than one device, so the number of used sensors must be less than or equal to the number of loads. To manage all these sensors by the ESP32 which has a limited number of RS232 pins, and analog multiplexers, which has been used which is also controlled by ESP32.

The 16-channel Analog/Digital Multiplexer
Two multiplexers shown in figure 2c, have been used to multiplex and demultiplex TX and RX signals. The first receives the TX signals from the sensors and passes it to the ESP32 chip sequentially, and the second is demultiplexers RX for all sensors. For timing purposes, both multiplexers are controlled by ESP32 with the same controlling signals.

Relay Module
This module is used to control the loads by turning them ON or, OFF. It is controlled by ESP32, each relay able to handle 10A loads, but for more than 10A an external contactor may be required, Figure  2d shows the used module which has 8 relays, it can be controlled with only three digital signals, which can save the ESP32 digital pins.

System Software Strategy
The system adopts two software programs, Visual C++ and Arduino. The main server is built with Visual C++, it is responsible for managing the whole system based on the additive features in the design. The server main features can be concluding as following:  Send periodic requests for all the nodes in the building to collect data about the consumed power by each device in the building, also the status of them. It also collected data about the suppled power by the PV system and the battery status from the node that physically connected to them.  Since the system is connected to the internet, it is keeping an hourly and two days ahead track of the weather conditions, as well as the time of sunrise and sunset. This is supplied by the application programming interface (API), which is used to abstract this information from a trusted weather site.  The main server is adopting a strategy to limit the consumed power according to the available power, the available power is calculated according to the current supplied power by the photovoltaic system, the current day length, the storage battery statues, the predicted weather for the current day and the two days ahead, and the history of the consumed energy of the building. This strategy defines the used appliances or the used loads in the building according to their priorities; the user can select and modify the priority of each load as required. Three-level of priority are presented: low, medium and high, if the system decides to adopt power-saving mode (PSM), only high priority devices can be used, but if the regulated power mode (RPM) is adopted the medium and high priority devices can be used, otherwise, in high-performance mode (HPM) the user can use all device.  Every node in the system, consisting of ESP32 microcontroller, is responsible for monitoring the consumed load and controlled the nearby devices, as well as monitoring the PV system production and the storage batteries capacity state. These nodes also periodically receive a request from the main server and reply with all the available data, they also receive a request to turn ON or OFF some device as required. Controlling devices not only obey the availability of power, but it also follows a time schedule by the user for each device, for example, the user request to turn ON the lights at night then turns them OFF at the morning, Figure 3 shows a flowchart that describes the system processing steps in details.

System Operation Modes
As mention before, the system adopts three operation modes High-Performance Mode (HPM), Regulated Power Mode (RPM) and Power Saving Mode (PSM). The system instantly changes the operation mode according to the available net power. Three case studies are presented to show the system responses. However, it is important to mention that the used batteries have only a 50% deep cycle, so it is recommended that they do not discharge it below this level. A hard demo was held on the prototype with three scenarios on Monday 27/01/2020 and for more flexible in changing the produced power and the battery capacity, three potentiometers are used, two of them for the PV system voltage and current, and the other is used to represent the battery capacity. The system is adopting the following levels ranges, PSM (50%-60%), RPM (60-70%), and HPM (≥70%). Below a list of the system responses for different conditions:  Power Saving Scenario (PSM): in this scenario, see Figure 4, the system worked automatically with absolute power. The produced power is more than the consumed power, but the battery capacity is only 58%, and the next day is mostly cloudy The system predicts the available power for the rest of the day by measuring the day length based on the period between the sunrise and sunset times [17]. It is also clear from the figure that only the high priority loads are enabled.
 Regulated Power Scenario (RPM): in this scenario the battery capacity is exceeding 60%, so the RPM mode is set, Figure 5 reveals that the system enabled both high and medium priority loads. In this case, there is only 75.1W will use to charge the battery. For the same level of battery charge, the system switches back to PSM if the weather is cloudy.
 High Performance Scenario (HPM): in the scenario, the battery capacity is exceeding 70%, so the HPM is elected and the system is enabled all the loads as shown in Figure 6. It also clear that there is 53.3W is used for charging. The system also classified the loads into three categories, Low Priority Loads LPL, Medium Priority Loads MPL, and High Priority Loads HPL.  Request the API data for the weather for current day and for two days ahead , sunrise and sun set times.
Send request for all nodes in the system to collect data about the consumed power, the devices status, the produced power by P.V system, and current batteries capcity

Results and Discussion
To test the system a prototype had been implemented as shown in Figure 7. Three potentiometers have been added to simulate the PV system voltage and current, and the battery voltage that is used to indicate the storage capacity. Figure 8 shows a daily load distribution with thirty minutes time-space. For example, at the beginning of a workday at 9 o'clock, most loads are on and are reduced at noon at 13 o'clock to provide energy for night consumption. The design offered a policy to scarify with a part of the loads which could save energy, protect the batteries from deep discharging, avoiding a complete shutdown, and improve the reliability of the standalone building.   Error! Reference source not found. shows the system recovery and response for the changing in the produced power, and the consumed power on 27th Jan 2020, it can be concluded from this figure some points such as:  The system is always trying to keep the battery capacity ≥50% to avoid deep discharging; this percentage can be adjusted according to the batteries types.  The system saves the battery capacity until the sunrise to recharge again.  The system adopts three operation modes PSM, RPM, and HPM.  The slop of the battery capacity curve is affected by the next two days; for example, the next days are cloudy this slop will decrease.  The produced power by the PV system is three times higher than the consumed power. It is expected in summer that production will be three times greater than consumption.   Figure 9. System recovery and response.

Conclusion
In this article, a new approach for energy management system is introduced with an ability to manage the consumed power according to produced, storage, and demand power without affecting the quality of life. The proposed system is designed and implemented to conduct a demonstration for all the expected power situations. The results show that the system ensures optimum management for the consumed energy by taking into consideration the power availability. A new strategy is presented that classifies the house's appliances into three levels of priority based on the user elections, of course, critical appliances considered to have a high priority. This strategy is adopting a dynamic level of limitations to switching between the loads' priorities decisions based on the available power, and the predicted weather for the two days ahead. The results show a promising system that able to increase the reliability of the PV standalone system.