Energy Management in Residential Microgrid Based on Non-Intrusive Load Monitoring and Internet of Things

: Recently, various strategies for energy management have been proposed to improve energy efficiency in smart grids. One key aspect of this is the use of microgrids. To effectively manage energy in a residential microgrid, advanced computational tools are required to maintain the balance between supply and demand. The concept of load disaggregation through non-intrusive load monitoring (NILM) is emerging as a cost-effective solution to optimize energy utilization in these systems without the need for extensive sensor infrastructure. This paper presents an energy management system based on NILM and the Internet of Things (IoT) for a residential microgrid, including a photovoltaic (PV) plant and battery storage device. The goal is to develop an efficient load management system to increase the microgrid’s independence from the traditional electrical grid. The microgrid model is developed in the electromagnetic transient program PSCAD/EMTDC to analyze and optimize energy performance. Load disaggregation is obtained by combining artificial neural networks (ANNs) and particle swarm optimization (PSO) to identify appliances for demand-side management. An ANN is applied in NILM as a load identification task, and PSO is used to optimize the ANN algorithm. This combination enhances the NILM technique’s accuracy, which is verified using the mean absolute error method to assess the difference between the predicted and measured power consumption of appliances. The NILM output is then transferred to consumers through the ThingSpeak IoT platform, enabling them to monitor and control their appliances to save energy and costs.


Introduction
The energy sector is shifting towards sustainable and energy-efficient alternatives, away from traditional fossil fuel-based generation [1].Microgrids are becoming a viable solution for addressing global energy issues as they can provide reliable and resilient power sources [2,3].By integrating local renewable energy sources, such as solar, wind, and smallscale hydro sources, microgrids can generate power closer to the point of consumption, reducing the energy losses associated with long-distance transmission and distribution [4].In addition, they can operate either independently or connected to the main grid based on the operating requirements [5,6].However, the generated power from these sources, such as solar cells, can be impacted by environmental conditions, such as solar irradiance, which give them an intermittent nature.Energy storage systems (ESSs) like batteries are used to mitigate this issue where they can efficiently store and supply the required energy with a fast response.Implementing ESSs allows the storage of excess renewable energy generation for later use, improving the utilization of these resources and reducing waste, thereby reducing power flow through transmission lines and enhancing grid efficiency and reliability [7].
Effective energy management is crucial for the successful deployment of microgrids and the integration of renewable energy sources [8].Energy management in residential microgrids is crucial for several reasons.Firstly, residential areas consume a significant portion of the total energy produced, and efficient energy management can help reduce overall energy consumption.Secondly, residential microgrids offer an excellent opportunity to integrate renewable energy sources such as solar and wind power, which can significantly reduce greenhouse gas emissions.However, the intermittent nature of renewable energy sources, varying load conditions, and the need to balance supply and demand pose significant challenges [9].
Energy disaggregation is one of the proposed methods for energy management in residential microgrids, which separates the net load from solar panels' power and battery charging/discharging.To achieve this, a smart home battery management model was proposed [10] to simulate battery charging/discharging patterns and an optimal disaggregation model was developed using a contextually supervised source separation method.The energy consumption of typical building equipment was also analyzed.Another smart energy management systems approach was proposed by [11], which aims to effectively balance power demand and supply throughout the smart microgrid using control algorithms simulated in MATLAB Simulink.This approach was tested using actual data from a building with residential and commercial loads in a residential area.Additionally, a forecasting model was proposed to help load aggregators predict the available demand response capacity of smart households in the day-ahead market.This model considers various factors that may impact the forecasting of aggregated demand response capacity.
A new approach has been proposed for scheduling loads in a residential home within a PV microgrid utilizing a genetic algorithm [5].The main objective of this approach is to demonstrate how demand-side management can decrease the cost of a residential home and the microgrid by minimizing the use of fossil fuel generators.This is achieved by allocating loads in such a way as to optimize the use of solar PV resources, and the scheme is based on time-of-use (TOU) and enhancing electricity users' comfort.The authors in Ref. [12] also presented an effective energy management system (EMS) for residential microgrids using data from smart meters; this research was conducted with a Deep Neural Network (DNN) technique.This study examined the patterns of consumers' energy consumption.Another study proposed an optimized home energy management system that not only incorporates renewable energy sources and energy storage systems but also includes the residential sector in demand-side management activities [13].The proposed system minimizes the electricity bill by scheduling household appliances and ESSs based on dynamic electricity pricing.In addition, a multi-objective energy management system for smart appliance scheduling based on an Internet of Things (IoT) platform was proposed for RES-integrated residential microgrids [14].This system took into account both residents' living quality and energy costs.
A new real-time EMS was proposed for residential hybrid AC/DC microgrids with a local DC distribution system [15].The proposed system aimed to minimize distribution losses and facilitate the integration of local renewable energy sources and energy storage systems at the consumption level.The proposed architecture of EMS and the residential microgrid has been implemented and validated experimentally.Furthermore, a comprehensive design methodology has been developed to optimize the energy flow and element sizing in a residential microgrid with energy storage [16].This methodology includes the determination of the optimal number of photovoltaic (PV) panels and battery bank capacity, as well as the design of an advanced control system for various end-user devices.The proposed model aims to provide economic benefits for residential electricity consumers by utilizing various techniques such as prioritization, load peak shaving, and load shifting to determine the optimal sizing for both islanded and grid-connected microgrids.The model also enables the identification of the optimal configuration for both the PV generator and energy storage system.In addition, the proposed methodology has been tested and validated using real-time measurements from the laboratory-scale setup.
A technique for managing energy and achieving savings in a residential microgrid connected to the grid was proposed using fuzzy logic control [17].The strategy, modeled on human decision-making, aimed to decrease grid power fluctuations and extend the battery's lifespan.The proposed method controlled the power flow within the microgrid, enhancing load management and ensuring a stable and steady power supply for users.A smart microgrid EMS was suggested to manage the power flow among microgrid components and meet predefined goals through simple fuzzy logic monitoring and regulation.Furthermore, an energy storage battery bank was employed as a power source and sink, improving power flow performance.A new method for energy management in residential microgrids using intelligent algorithms was proposed for scheduling in smart homes [18].The technique involved scheduling rooftop solar panels, home appliances, and hybrid electric vehicles while considering uncertainties in solar and electric vehicle production.The analytical hierarchy process (AHP) method and multi-objective dragonfly algorithm were combined to optimize a techno-economic objective function and determine the optimal schedule for appliances.Moreover, the method took into account a price-based demand response program using a real-time pricing tariff.
A new approach for managing energy in residential grid-connected hybrid energy systems was proposed by [19].The hybrid system consisted of a photovoltaic array, a battery bank, and a residential building.The strategy included three control levels: a dual prediction model using residual causal dilated convolutional networks to forecast energy production and electric load, a logical level to manage computational load and accuracy, and a multi-objective optimization to efficiently exchange energy with the utility grid by scheduling battery charging.The energy management problem aims to achieve multiple objectives, such as minimizing energy purchased from the grid, maximizing the battery bank's state of charge (SOC), and reducing carbon emissions.Another approach combining particle swarm optimization with demand-supply management was proposed by [20] for designing an off-grid hybrid PV-solar-diesel-battery system for residential building electrification in arid environments.The study used a typical dwelling in Adrar, Algeria, as a case study and included a techno-economic performance analysis to evaluate the cost and energy benefits of incorporating demand-supply management into the system.The goal was to improve the energy cost and the building energy consumption for endusers.An artificial neural network (ANN) was also used to provide advanced energy management solutions [21].In Ref. [22], a new energy management tool for a residential microgrid composed of a photovoltaic and energy storage device was proposed.The tool used an ANN to estimate the programmable loads scheduling, considering current and previous day weather conditions and forecasted weather for the next day.The tool was used to optimize the utilization of the PV plant through the storage system, increasing the microgrid's independence from the traditional electrical grid.In Ref. [23], an ANN was successfully used for modeling and predicting the electricity consumption profiles of individual households, enabling the capture of the non-linear relationships and variability inherent in household-level electricity usage data.
A dependable Appliance Load Monitoring (ALM) system is also important for an efficient energy management system.ALM aims to provide data on energy consumption and achieve detailed energy sensing, allowing the system to identify appliances with high energy consumption and reschedule high power demand operations for off-peak hours [24,25].There are two main types of ALM: intrusive load monitoring (ILM) and non-intrusive load monitoring (NILM) [26].NILM is based on single-point sensing at the entrance of the smart home, while ILM is based on distributed sensing.Although ILM is more accurate, it has practical issues such as high cost and installation difficulties [27], while NILM is more cost-effective and has fewer installation requirements [28,29].NILM allows for the disaggregation of load data, providing insights into individual appliance-level energy consumption.
A novel ResNet-seq2seq-based NILM approach was proposed for the load disaggregation of residential houses integrating DERs [30].Also, the authors applied a post-processing technique to modify the network output and improve disaggregation accuracy.Moreover, the problem of identifying electrical loads connected to a house based on total electric current measurement was previously investigated [31].In addition, the authors proposed a NILM algorithm based on a convolutional neural network that allows for the simultaneous detection and classification of events without double processing, reducing calculation times.Also, an unsupervised disaggregation method based on an obtained controlled dataset was proposed using smart meters in a standard household, using soft computing techniques to identify the behavior of each device from aggregated consumption records [32].Also, the benefits of NILM approaches, such as providing personalized energy-saving recommendations, grid control, predictions, failure detection, and similar statistics for energy providers, were illustrated.Furthermore, a measurement system for NILM based on the Sweep Frequency Response Analysis (SFRA) technique and machine learning was previously presented [33].The system used a Support Vector Machine (SVM) algorithm to process the traces obtained using the SFRA measurement system.
Based on the literature survey, it is clear that energy management in residential microgrids is a complex task, and traditional energy management systems are often expensive and difficult to install, making them less practical for residential use.Moreover, a few researchers studied NILM techniques for this purpose.In addition, there is a need for the real-time monitoring and control of appliances to further optimize energy usage, reduce peak demand, and maximize the use of renewable energy sources.Therefore, this paper proposes a combination of NILM and the IoT to achieve these goals.The NILM technique itself has some limitations, such as modeling transient behaviors, adapting to changes over time, and limited data quality [34].IoT-enabled solutions can provide additional data streams, computational resources, and adaptive capabilities to overcome these limitations, leading to more robust and effective energy management systems.The IoT has previously been used individually for energy management within a single microgrid [35] or among multiple microgrids [36], as well as for the remote monitoring and control of distributed and isolated energy systems [37].By integrating NILM with the IoT, this approach can provide more comprehensive energy monitoring and management capabilities across a wider range of energy assets and applications.The unique contributions of this paper can be summarized as follows: 1.
Analyzing the load profile and the definition of a daily cycle of residential loads (i.e., home appliances), where the microgrid dynamic model is established in PSCAD/EMTDC.

2.
Presenting a detailed framework for using NILM results within an energy management system to optimize microgrid energy performance on a daily basis.

3.
Developing a NILM technique using an ANN to disaggregate loads where the particle swarm optimization (PSO) algorithm is used to optimize the neural network architecture to improve the accuracy of the NILM technique.

4.
Incorporating consumer behavior aspects using the ThingSpeak-based IoT platform for the load monitoring, data analysis, and visualization of the residential microgrid.The data are sent from ThingSpeak to smartphones, and alerts are received through Twitter.This study helps the consumer to control energy consumption by shifting appliances with high power to other times, decreasing grid load during peak periods, and maximizing PV production exploitation.The architecture of the residential microgrid based on the NILM technique and IoT is shown in Figure 1.

Methodology of the Proposed Energy Management
The proposed energy management system aims to optimize energy utilization in a residential microgrid.First, a detailed overview of the microgrid system design is presented, and the developed models for the electrical load, PV system, and battery are described.Then, the implementation of the NILM technique to enhance energy management and the steps of the NILM algorithm are discussed.
The PSCAD/EMTDC program can effectively facilitate the analysis and optimization of energy performance in a developed microgrid model through its ability to simulate the microgrid system at the microsecond time scale using detailed component models.This allows for the accurate emulation of transient events like faults and load switching, enabling the testing and optimization of advanced distributed energy resources and micro source controllers as well as protection relay coordination schemes.Therefore, PSCAD/EMTDC is a valuable tool for the detailed and repeatable simulation-based development and optimization of microgrid energy management systems.

Microgrid System Design
The system described in Figure 2 can be divided into four main components: photovoltaic plant, battery storage system, AC grid, and residential load.It is important to note that a bidirectional energy exchange was taken into account for both the input and output of the battery and grid.Additionally, it should be noted that the residential load and PV plant are defined by their respective output power flux (production from RES) and input power flux (required load).The power flow in the system is expressed as follows: where,  ,  ,  , and  are the power of the load, grid, PV, and charge/discharge of the battery, respectively.The key features and findings of the previous techniques in the literature, as well as the proposed technique, are summarized in Table 1.The paper is structured as follows.In Section 2, the microgrid system design used in this work is presented, including an overview of the electrical load, photovoltaic model, and battery model.Additionally, the energy management in residential microgrids is illustrated in this section, along with the NILM algorithm used in this work.The simulation results and corresponding discussions are presented in Sections 3 and 4, respectively.Finally, Section 5 provides the key conclusions drawn from the current study.

Methodology of the Proposed Energy Management
The proposed energy management system aims to optimize energy utilization in a residential microgrid.First, a detailed overview of the microgrid system design is presented, and the developed models for the electrical load, PV system, and battery are described.Then, the implementation of the NILM technique to enhance energy management and the steps of the NILM algorithm are discussed.
The PSCAD/EMTDC program can effectively facilitate the analysis and optimization of energy performance in a developed microgrid model through its ability to simulate the microgrid system at the microsecond time scale using detailed component models.This allows for the accurate emulation of transient events like faults and load switching, enabling the testing and optimization of advanced distributed energy resources and micro source controllers as well as protection relay coordination schemes.Therefore, PSCAD/EMTDC is a valuable tool for the detailed and repeatable simulation-based development and optimization of microgrid energy management systems.

Microgrid System Design
The system described in Figure 2 can be divided into four main components: photovoltaic plant, battery storage system, AC grid, and residential load.It is important to note that a bidirectional energy exchange was taken into account for both the input and output of the battery and grid.Additionally, it should be noted that the residential load and PV plant are defined by their respective output power flux (production from RES) and input power flux (required load).The power flow in the system is expressed as follows: P load = ∑ P grid + P pv ± P battery (1) where, P load , P grid , P pv , and P battery are the power of the load, grid, PV, and charge/discharge of the battery, respectively.

The Electrical Load and Photovoltaic Model
The load demand in this study is based on the Reference Energy Disaggregation Dataset (REDD) presented in Ref. [12], which is the first publicly available dataset used to support research in NILM.The dataset includes sub-metered and aggregate power data from six households, making it the most widely used dataset for evaluating disaggregation algorithms.Specifically, the dataset for building 2, which comprises data from nine appliances, is utilized in this study.Figures 3 and 4 illustrate the aggregated and disaggregated power consumption of the nine appliances in house 2 over a day.
In the microgrid system studied in this paper, a 2 kW photovoltaic (PV) system was implemented.Figure 5a illustrates the PV cell's equivalent circuit model, as presented in Ref. [38].The model includes Rs, which represents the PV cell's internal resistance, and Rp, which accounts for leakage current.The cell output voltage (Vpv) depends on temperature (T) and solar radiation (λ).The PV model parameters are listed in Table 2.

The Electrical Load and Photovoltaic Model
The load demand in this study is based on the Reference Energy Disaggregation Dataset (REDD) presented in Ref. [12], which is the first publicly available dataset used to support research in NILM.The dataset includes sub-metered and aggregate power data from six households, making it the most widely used dataset for evaluating disaggregation algorithms.Specifically, the dataset for building 2, which comprises data from nine appliances, is utilized in this study.Figures 3 and 4 illustrate the aggregated and disaggregated power consumption of the nine appliances in house 2 over a day.In the microgrid system studied in this paper, a 2 kW photovoltaic (PV) system was implemented.Figure 5a illustrates the PV cell's equivalent circuit model, as presented in Ref. [38].The model includes Rs, which represents the PV cell's internal resistance, and Rp, which accounts for leakage current.The cell output voltage (Vpv) depends on temperature (T) and solar radiation (λ).The PV model parameters are listed in Table 2.

Battery Model
The PV system utilizes different types of batteries, such as Lead-Acid, Li-ion, NiMH, and NiCd.Li-ion batteries are among the most widely used with PV systems, as per reference [39].In this work, the Li-ion battery model based on empirical data is used with a voltage of 4.1 V and a capacity of 850 mAh, as shown in Figure 5b [38].This model accounts for not only the steady-state characteristics of the battery but also its transient characteristics.The transient performance is modeled through variable resistance and capacitance, which are dependent on the battery's state of charge.The equations which describe the battery model are expressed as follows [38]: C transient_s (SOC) = −752.9e−13.51SOC + 703.6 R transient_L (SOC) = 6.603e −155.2SOC+ 0.04984 ( 6) The proposed model is designed to represent a specified number of battery cells (n) connected in a series, as indicated in Figure 6.The number of parallel modules is used to determine the Ampere-hour (Ah) battery rating.The SOC can be expressed by Equation ( 8) as follows: where: Ib: battery current (A); Q: maximum capacity of battery (Ah).
counts for not only the steady-state characteristics of the battery but also its transient characteristics.The transient performance is modeled through variable resistance and capacitance, which are dependent on the battery's state of charge.The equations which describe the battery model are expressed as follows [38]: The proposed model is designed to represent a specified number of battery cells (n) connected in a series, as indicated in Figure 6.The number of parallel modules is used to determine the Ampere-hour (Ah) battery rating.The SOC can be expressed by Equation ( 8) as follows: where: Ib: battery current (A); Q: maximum capacity of battery (Ah).
In this research, a bidirectional converter is used to efficiently charge and discharge the battery.The battery can only be charged when the output power generated by the PV system is greater than the load power and the SOC of the battery is below its maximum level.On the other hand, the battery is discharged when the PV output power is lower than the load power and the SOC is larger than the minimum level.There are two specific scenarios when the system is connected to the grid.The first scenario is when the PV output power exceeds the load power, and the battery SOC is larger than its maximum value.The second scenario occurs when the output power from PV is less than that of the load, and the battery SOC falls below its minimum value.In this research, a bidirectional converter is used to efficiently charge and discharge the battery.The battery can only be charged when the output power generated by the PV system is greater than the load power and the SOC of the battery is below its maximum level.On the other hand, the battery is discharged when the PV output power is lower than the load power and the SOC is larger than the minimum level.There are two specific scenarios when the system is connected to the grid.The first scenario is when the PV output power exceeds the load power, and the battery SOC is larger than its maximum value.The second scenario occurs when the output power from PV is less than that of the load, and the battery SOC falls below its minimum value.

Using NILM in Energy Management System
The energy management system in the context of NILM plays a crucial role in utilizing the disaggregated appliance-level energy consumption data to optimize energy usage and overall system performance.The EMS integrates the results provided by NILM into decision-making processes to achieve energy efficiency, cost savings, and grid load management.The following presents a discussion of the EMS in the context of NILM [34,40,41]: 1.
Real-time Monitoring: By utilizing the disaggregated data, the EMS can offer the real-time monitoring of energy consumption patterns.It allows users, whether building occupants, facility managers, or energy service providers, to understand how individual appliances contribute to the overall energy load.

2.
Load Forecasting: The EMS can use the historical disaggregated data to forecast future energy consumption patterns.This enables active decision-making, such as adjusting energy consumption schedules or optimizing energy resources to match anticipated demand.

3.
Demand Response: With a clear understanding of when and how different appliances are consuming energy, the EMS can implement demand response strategies.During peak demand periods or high energy cost intervals, the EMS can automatically control or adjust the operation of specific appliances to reduce overall energy demand and associated costs.

4.
Energy Optimization: The disaggregated data enables the EMS to identify energy consumption inefficiencies and opportunities for optimization.It can provide recommendations for load shifting, load balancing, and identifying energy wastage, helping to improve the overall energy efficiency of the system. 5.
User Engagement and Feedback: For residential or commercial users, the EMS can present disaggregated energy consumption data in a user-friendly manner, providing insights into which appliances are consuming the most energy.This empowers users to make informed decisions about their energy usage patterns and potentially adopt more energy-efficient behaviors.6.
Integration with Renewable Energy Sources: The EMS can optimize the usage of renewable energy sources, such as solar panels or wind turbines, based on the disaggregated data.It can prioritize running high-power appliances during periods of abundant renewable energy generation, maximizing the use of clean energy and minimizing reliance on grid power.7.
Maintenance and Fault Detection: By continuously monitoring the energy consumption patterns of individual appliances, the EMS can detect abnormalities or anomalies in energy consumption.Sudden deviations from the norm could indicate malfunctioning appliances, facilitating timely maintenance and reducing energy wastage.8.
Reporting and Analytics: The EMS can generate detailed reports and analytics based on the disaggregated data.These insights can be used for performance evaluation, energy management strategy refinement, and compliance with energy efficiency goals or regulations.
A residential microgrid is a localized system that combines renewable energy sources, energy storage, and residential loads to provide reliable power to consumers.It can operate in both grid-connected and islanded modes.This paper focuses on a residential microgrid composed of a utility grid, a small photovoltaic power plant, and a battery energy storage system.The residential loads in this microgrid are taken from the REDD datasets and include both shiftable and non-shiftable appliances.Shiftable appliances, such as washing machines and dishwashers, can be scheduled and controlled by an energy management system.Non-shiftable appliances, such as lights and refrigerators, cannot be scheduled.The study aims to optimize PV plant production by shifting non-essential electricity use to different times.
The proposed microgrid requires an effective EMS to operate optimally.This system manages the operation of domestic appliances in coordination with the photovoltaic plant, battery storage, and the utility grid, while ensuring compliance with any operational constraints.A key aspect of the EMS is its ability to shift appliances in order to achieve optimal performance.To accomplish this, the EMS must include load monitoring capabilities to identify the appliances currently in use and to determine which appliances can be shifted to maximize the exploitation of the PV production.Additionally, consumers can be given the option to control certain non-shiftable appliances, such as air conditioners and refrigerators, by setting temperature limits [42].This paper employs non-intrusive load monitoring for load disaggregation.

NILM Algorithm
Load disaggregation is a method used to divide the energy usage of a household into individual appliances.It allows for the identification of how electricity is being consumed by a particular household without the need for measuring devices on each individual appliance [43,44].By utilizing data from a single meter, the technique of load disaggregation can be used to predict the power consumption of each appliance from the aggregate power consumption of the house that is already obtained from the smart meter, Z = {z 1 , z 2 , . . . . . . ,z T }, for a given number of appliances, N, throughout T time periods [45]: 2 , . . ., q (2) T : : Then, the aggregated power consumption x(t) is calculated as follows: where q (i) t is the appliance load power at time t.
The error e(t) is the difference between the reading of the home aggregate meter and the total actual power consumption by all appliances in the building.This error comes from the total effects of measuring device operation and distribution line losses under real-time conditions.The NILM technique takes Z(t) as input and disaggregates it into a number of q NILM is a technique used to analyze energy consumption by breaking down total usage into the specific usage of individual appliances [46,47].This is accomplished by analyzing composite data collected from a single point of measurement and estimating the power consumption of each appliance.The process typically involves several key stages as follows [48]: A. Data collection: It is considered an essential step in the process of gathering electrical data.This can be performed using various devices, such as smart meters or acquisition boards, which measure key electrical parameters, including voltage, current, and power.These meters can operate at either low-frequency or high-frequency sampling rates.High-frequency sampling meters, for example, can measure electrical characteristics at rates between 10 kHz and 100 MHz by capturing thousands of voltage and current readings per second.These readings are then used to calculate active and reactive power values over one cycle of the alternating current waveform.On the other hand, low-frequency sampling meters measure electrical features at rates less than 1 Hz, reporting power measurements at intervals of 10 s or more.These meters are generally less expensive than their high-frequency counterparts.
In this work, the REDD dataset presented in [12], which is considered the first published available dataset, is used to support the research on NILM.The dataset comprises both sub-metered and aggregate power data from six households in the USA that were recorded for a short time (between a few weeks and a few months).Thus, it became the most often used dataset for assessing disaggregation techniques.Before utilizing the REDD datasets, it was not easy to compare different methods applied to NILM because each dataset may produce different results.The structure description of the REDD dataset is given in Table 3. B. Event detection and feature extraction: The next step after data collection is to further analyze the electrical data to acquire characteristics that may be used to identify events like changes in appliance status.The event is known as the variation in the appliance state over time.The process of detecting load switching operations, such as setting a threshold to acquire on/off states of appliances, is defined as event detection.
The event includes current and power changes which are detected in the electrical data collected previously using thresholds [48].Following the event detection, load features are extracted by steady-state, transient-state, and other approaches.The appliances give information about load signatures or features that differentiate one appliance from another.The features are related to the power characteristics, including the active power, the reactive power, and their respective harmonics [49].The steadystate analysis, transient-state analysis, and non-traditional appliance characteristics are the three main methodologies used by NILM techniques to analyze the energy signatures.When taking into account stable device states, the steady-state analysis may identify variations in load identification.Active and reactive power are two of the most often utilized steady-state signatures in NILM for monitoring on/off appliance activities.The amount of energy used by an appliance when it is in use is known as active power.Pure resistive loads have current and voltage waveforms that are always in phase and have no reactive power.A fully reactive load will result in a phase shift of 90 degrees and no actual power transmission.On the other hand, there is often a phase shift between the waveforms of voltage and current that absorb or produce reactive power, respectively, due to the load's capacitive and inductive components.Utilizing steady-state characteristics often has one major drawback; there is inadequate knowledge about the load performance.Similar power demand characteristics across various appliances might cause incorrect identification.
The transient-state study, on the other hand, concentrates on the transitional phases in the energy consumption profile.In contrast to steady-state signatures, where appliances with the same power demand characteristics can be clearly separated, it is discovered that the transient behavior of major appliances is unique and that their features are less overlapping.The necessity for a high sample rate to catch transients, however, is the main restriction.The last strategy focuses on identifying the unusual characteristics of the electrical devices to break them down [25,28].These features refer to additional new qualities that emerge from the previous two types of characteristics or from other factors, such as the time of day, how often an appliance is turned on and off, how often it is used, and how the use of several appliances is correlated with one another.
It will be important to use techniques that identify the appliances that are operating at a certain moment after the characteristics have been retrieved.Researchers have applied many experiments with different algorithms to solve the energy disaggregation issue due to the increased interest in this area.These disaggregation approaches may be divided into supervised, semi-supervised, and unsupervised categories.The individual appliance data must be trained for the supervised disaggregation algorithms to categorize the appliances currently in use.These supervised techniques may be divided into optimization and pattern recognition approaches.In optimization methods, the extracted features rely on comparison to locate the most similar match and discover load characteristics contained in a dataset, where the appliance signatures are trained using the event-detected power signals.These techniques have used genetic algorithms and integer programming.On the other hand, researchers in this field often employ pattern recognition algorithms.There are several supervised learning techniques that have been used in this category, including ANNs [50], genetic algorithms [51], hidden Markov models (HMM) [52], and decision trees [53].Unsupervised techniques may learn from the acquired data without prior training data, whereas semi-supervised methods need a small quantity of training data at the start of the process to perform the classification.
C. Identifying Load: This step is where the features extracted in the previous stage are used to classify and determine the status of each device and which devices are in use at a specific period.This process involves characterizing the unique signatures and features of each appliance, which requires information about the device's operating state.Appliances can typically be classified into four types.Type 1 includes devices with two states, such as toasters and lamps, which are either on or off.Type 2 includes devices with a finite number of operating states, such as stoves and washing machines.Type 3 includes appliances that have continuously variable power consumption, such as power drills and dimmer lights.Type 4 includes appliances that operate for extended periods at a constant power level, such as internet modems and smoke detectors.
In this study, a new algorithm is proposed that utilizes the PSO technique to optimize a neural network architecture for the purpose of load disaggregation and enhancing the accuracy of the NILM method.Regarding NILM, its main objective is to disaggregate the total electricity consumption of a household into individual loads based on the aggregate power measurements.This is a complex pattern recognition problem, and the ANN is a promising machine learning technique that can be used for NILM applications.However, training an ANN model for NILM requires careful optimization of the network hyperparameters, including biases and weights.The performance of the ANN-based NILM model can be highly sensitive to these hyperparameters, and finding the optimal configuration can be a time-consuming and challenging task.This is where the combination of ANNs and PSO can be beneficial.PSO is a population-based optimization algorithm that can be used to automate the process of tuning the ANN hyperparameters.The PSO algorithm explores the hyperparameter search space and finds the optimal configuration that minimizes the mean absolute error between the ANN-predicted appliance power consumption and the actual measurements.By coupling the pattern recognition capabilities of ANNs with the optimization power of PSO, the accuracy of the NILM process can be significantly enhanced.The PSO-based optimization ensures that the ANN model is configured to extract the most relevant features from the aggregate power data, leading to improved disaggregation performance.
The feed-forward neural network architecture has been used in this work, which consists of three layers: an input layer, an output layer, and a hidden layer.These layers are connected through biases (b) and weights (w).The process of optimizing the ANN model involves finding the optimal values of the biases and weights until the objective function is achieved.This is completed by repeatedly adjusting the values of biases and weights until the network's performance reaches the desired level [54].
Overall, the disaggregation of demand side energy management in NILM is a complex process that requires more steps.
(1) Data Preprocessing: The raw energy consumption data collected from smart meters, like the public datasets used in this work, are preprocessed to remove any inconsistencies and outliers.This may include normalizing the data, removing missing values, and transforming the data into a suitable format for the ANN algorithm.(2) Feature Extraction: Features are extracted from the preprocessed data that are relevant to the task of NILM.(3) Data Splitting: The preprocessed data are split into training and testing sets.The training set is used to train the ANN model, and the testing set is used to evaluate the performance of the model.( 4) ANN Model Selection: An appropriate ANN architecture is selected based on the complexity of the problem and the size of the dataset.Common ANN architectures used for NILM include feed-forward neural networks, recurrent neural networks, and convolutional neural networks.The feed-forward neural network has been used in this work.Feed-forward networks can be trained on diverse and large datasets to improve their accuracy and robustness in appliance recognition.Also, feed-forward networks can automatically learn hierarchical features from the raw electrical signal data.In NILM, this means that the network can learn to recognize patterns in the aggregated energy consumption data that correspond to different appliances turning on and off.The ability of feed-forward networks to capture complex nonlinear relationships is valuable for detecting subtle changes in the energy signal associated with different appliances.Feed-forward networks can be adjusted to suit the specific characteristics of different appliances and their energy usage patterns.This adaptability is crucial in building accurate disaggregation models for diverse sets of appliances.In addition, feed-forward networks can provide relatively fast inference times, making them suitable for applications where quick feedback on energy consumption disaggregation is important.(5) PSO Algorithm Selection: The PSO algorithm is selected and configured to optimize the ANN model's hyperparameters.The PSO algorithm uses a population of particles to search for the optimal solution, and the particles are updated based on their fitness and the social behavior of the swarm.( 6) PSO-ANN Model Training: The ANN model is trained using the selected PSO algorithm to optimize the hyperparameters.The PSO algorithm iteratively updates the hyperparameters of the ANN model, and the ANN model is trained on the training set using the updated hyperparameters.(7) Model Evaluation: The performance of the trained ANN model is evaluated on the testing set.This may involve calculating metrics such as the mean squared error (MSE), mean absolute error (MAE), or coefficient of determination (R-squared) to assess the accuracy of the model.( 8) Model Deployment: The trained and optimized ANN model is deployed in a production environment where it can be used to perform NILM in real-time.
To summarize, the PSO algorithm is used to optimize the hyperparameters of the ANN model, improving the accuracy and efficiency of the NILM system.The PSO algorithm iteratively searches for the optimal solution, and the ANN model is trained using the updated hyperparameters.The trained model is then deployed in a production environment and continuously monitored and updated to ensure its accuracy over time.
In this paper, the neural networks are trained using PSO.The steps of PSO are expressed as follows [55]: (1) Adjust the parameters of PSO: the inertia factors w min , w max , and the acceleration factors C 1 , C 2 ; (2) Initialize the particles population each of which has velocity V and position X; (3) Set the iteration number N = 1; (4) Calculate the fitness function of particles F N i = f X N i , ∀i and determine the best particle's index b; (7) Update particles' velocity and position: ; ∀i and ∀j; (8) Assess the fitness function , ∀i and determine the best particle's index b1; (9) Update Pbest of population ∀i: (10) Update Gbest of population: In this work, the objective function of the optimum optimizing of the ANN using PSO is defined as the mean absolute error (MAE) [56,57].
where P measured t and P predicted t are the actual and prediction values of the appliance's power consumption at time t, respectively.
The aggregated energy captured in more modern NILM systems has been sent to a server or cloud through the internet using various wireless communication protocols.The final procedure in the NILM is completed on a cloud server, after which the customer is informed through mobile apps of choices on the state of their appliances and how much energy they are using.This will enable the client to reduce their energy usage and save money.In addition, new technologies such as the IoT are used with NILM techniques during the management of consumption peaks.In addition, there are some time-of-use pricing programs or discount offers to motivate consumers to shift their demand from peak periods to off-peak periods.
The IoT plays several key roles in energy management systems by enabling the remote monitoring and control of assets like switching devices; this allows utilities for oversight regarding the energy usage, production, losses, and equipment performance in real-time [58].The IoT also facilitates demand response programs through the automated control of consumer appliances and systems based on energy pricing signals to better match supply and demand.In addition, the IoT platform connects with consumers via mobile/web interfaces.

Results
The primary objective of this study, as outlined in the introduction, is to optimize the utilization of PV plant production by applying the NILM approach.The simulation results will be presented in two stages.First, the performance of the residential microgrid will be evaluated, followed by an analysis of the results obtained from the NILM algorithm.

Performance of Residential Microgrid Results
The residential microgrid model is simulated using PSCAD/EMTDC X4 software.Figure 7 illustrates the load variation over 24 h for building 2 in the REDD dataset, as well as the solar radiation, PV production, output power from the grid, battery power, and battery's state of charge.It can be observed that during the period from 12 AM to 6 AM, there is no solar radiation and thus no output power from the PV system.The microgrid is connected to the grid during this period to feed the load.On the other hand, solar radiation is present from 6 AM to 6 PM, and the PV system generates output power to supply the load and charge the battery.Finally, from 6 PM to 12 AM, there is no solar radiation, and the load is supplied from the battery and the grid, as the PV system is not producing any power.
The IoT plays several key roles in energy management systems by enabling the remote monitoring and control of assets like switching devices; this allows utilities for oversight regarding the energy usage, production, losses, and equipment performance in realtime [58].The IoT also facilitates demand response programs through the automated control of consumer appliances and systems based on energy pricing signals to better match supply and demand.In addition, the IoT platform connects with consumers via mobile/web interfaces.

Results
The primary objective of this study, as outlined in the introduction, is to optimize the utilization of PV plant production by applying the NILM approach.The simulation results will be presented in two stages.First, the performance of the residential microgrid will be evaluated, followed by an analysis of the results obtained from the NILM algorithm.

Performance of Residential Microgrid Results
The residential microgrid model is simulated using PSCAD/EMTDC X4 software.Figure 7 illustrates the load variation over 24 h for building 2 in the REDD dataset, as well as the solar radiation, PV production, output power from the grid, battery power, and battery's state of charge.It can be observed that during the period from 12 AM to 6 AM, there is no solar radiation and thus no output power from the PV system.The microgrid is connected to the grid during this period to feed the load.On the other hand, solar radiation is present from 6 AM to 6 PM, and the PV system generates output power to supply the load and charge the battery.Finally, from 6 PM to 12 AM, there is no solar radiation, and the load is supplied from the battery and the grid, as the PV system is not producing any power.There are certain days when solar radiation is low, or the total load is high, making it necessary to manage power consumption to optimize the utilization of PV production and reduce power consumption during the day.Energy management, particularly load monitoring, is crucial for this purpose.This led to the use of the NILM technique, based on the PSO algorithm and ANN for load disaggregation.The PSO algorithm is utilized for optimizing the neural network architecture, which improves the accuracy of the NILM technique.

NILM Algorithm Results
The ANN-PSO algorithm is applied to datasets from building 2 of the REDD study, with five appliances, the fridge, microwave, kitchen outlet, dishwasher, and stove, selected as a case study.The data are preprocessed before using the NILM algorithm.The data of aggregate load are not suitable for direct use since the load data are obtained at a different sampling rate: 1 Hz for the aggregate load data and 1/3 Hz for the load data of individual appliances.Also, some data are discontinuous, so the aggregate load data are downsampled to 1/3 Hz.The input data (input layer of ANN) to the algorithm refers to the total power consumption of the building, and the target (output layer of ANN) is the disaggregated power consumption of the appliances in the building.Based on the disaggregation algorithm used in this work, the neural network is a feed-forward type created using the feed-forward net function in MATLAB 2024a; the default activation functions are tansig for the hidden layer and purelin for the output layer.Also, there are five neurons in the single hidden layer, m input neurons based on the size of the input data, and o output neurons based on the size of the target data.So, there are m neurons in the input layer, five neurons in the hidden layer, and o neurons in the output layer.The ANN-PSO algorithm parameters are shown in Table 4. Figures 8-12 show a comparison of the actual and predicted load results for the fridge, microwave, kitchen outlet, dishwasher, and stove, respectively.It can be seen that the algorithm was successful in accurately estimating the power consumption of the appliances.

ANN-PSO Parameter Value
The number of hidden neurons n Furthermore, in order to validate the model's accuracy, a correlation coefficient (R) is used as a metric.The correlation coefficient ranges between -1 and +1, where values close to +1 indicate a high level of performance and a positive linear relationship.
The formula used for calculating R between two sets of data, X and Y, is given by the following: where the variables are defined as follows: n is the number of data points in the sets X and Y; x represents the ith data point in set X; y represents the ith data point in set Y; x is the mean of the data points in set X; y is the mean of the data points in set Y.
Table 5 illustrates the correlation coefficient values obtained from the simulation results.A high correlation coefficient value means that the model accurately predicts the appliances' power consumption.Table 5 illustrates the correlation coefficient values obtained from the simulation results.A high correlation coefficient value means that the model accurately predicts the appliances' power consumption.Table 5 illustrates the correlation coefficient values obtained from the simulation results.A high correlation coefficient value means that the model accurately predicts the appliances' power consumption.In addition to the correlation coefficient analysis, an accuracy analysis is also performed using the MAE method, as expressed by Equation ( 12), to further evaluate the difference between the predicted and measured consumption of each appliance obtained from the algorithm.The MAE is one of the most important matrices in most of the papers on NILM techniques.So, the MAE has been used to be able to compare the results with the other methods in the previous work.The MAE values for each appliance are illustrated in Table 6.It could be noted that the MAE values range from 1.4164 to 29.0456, indicating a high consistency between the measured and predicted results, thus demonstrating the efficiency of the proposed algorithm.In addition, using a public dataset enables the evaluation of the results obtained compared with other techniques presented by previous researchers.A comparison is performed between the MAE values of the most common three appliances used in state-of-the-art methods and the ANN-PSO algorithm, as given in Table 7.The best-performing approach is emphasized in bold in each column.It could be noted that, compared with the other approaches, the ANN-PSO approach achieves good performance and produces the best MAE values, where the MAE values are the lowest when using PSO to optimize the ANN algorithm.Also, the total MAE of other methods is calculated by adding the lowest value of the MAE for each appliance and dividing it by the total  In addition to the correlation coefficient analysis, an accuracy analysis is also performed using the MAE method, as expressed by Equation ( 12), to further evaluate the difference between the predicted and measured consumption of each appliance obtained from the algorithm.The MAE is one of the most important matrices in most of the papers on NILM techniques.So, the MAE has been used to be able to compare the results with the other methods in the previous work.The MAE values for each appliance are illustrated in Table 6.It could be noted that the MAE values range from 1.4164 to 29.0456, indicating a high consistency between the measured and predicted results, thus demonstrating the efficiency of the proposed algorithm.In addition, using a public dataset enables the evaluation of the results obtained compared with other techniques presented by previous researchers.A comparison is performed between the MAE values of the most common three appliances used in state-of-the-art methods and the ANN-PSO algorithm, as given in Table 7.The best-performing approach is emphasized in bold in each column.It could be noted that, compared with the other approaches, the ANN-PSO approach achieves good performance and produces the best MAE values, where the MAE values are the lowest when using PSO to optimize the ANN algorithm.Also, the total MAE of other methods is calculated by adding the lowest value of the MAE for each appliance and dividing it by the total Table 5 illustrates the correlation coefficient values obtained from the simulation results.A high correlation coefficient value means that the model accurately predicts the appliances' power consumption.In addition to the correlation coefficient analysis, an accuracy analysis is also performed using the MAE method, as expressed by Equation (12), to further evaluate the difference between the predicted and measured consumption of each appliance obtained from the algorithm.The MAE is one of the most important matrices in most of the papers on NILM techniques.So, the MAE has been used to be able to compare the results with the other methods in the previous work.The MAE values for each appliance are illustrated in Table 6.It could be noted that the MAE values range from 1.4164 to 29.0456, indicating a high consistency between the measured and predicted results, thus demonstrating the efficiency of the proposed algorithm.In addition, using a public dataset enables the evaluation of the results obtained compared with other techniques presented by previous researchers.A comparison is performed between the MAE values of the most common three appliances used in state-of-the-art methods and the ANN-PSO algorithm, as given in Table 7.The best-performing approach is emphasized in bold in each column.It could be noted that, compared with the other approaches, the ANN-PSO approach achieves good performance and produces the best MAE values, where the MAE values are the lowest when using PSO to optimize the ANN algorithm.Also, the total MAE of other methods is calculated by adding the lowest value of the MAE for each appliance and dividing it by the total number of appliances used in this work (three appliances).When this value is compared with the total MAE of the same appliances using the ANN-PSO algorithm in this work, the value of the MAE decreases from 23.42 to 15.191, which means that the error decreased by 35.14%.Consequently, using PSO to optimize the ANN successfully predicted each appliance's power consumption from the total household power consumption with a minimum error.The results obtained from the proposed algorithm can be used to generate recommendations for reducing energy consumption by identifying specific uses of high-energyconsuming appliances.The goal is to pinpoint the usage patterns leading to high power consumption to decrease it.To achieve this, it is crucial to employ an algorithm that improves the accuracy of the NILM technique.The method has demonstrated high accuracy in identifying the appliances.The consumer can utilize this information to manage energy demand and optimize the utilization of PV plant production.Furthermore, the accuracy of the disaggregation algorithm can assist the consumer in making informed decisions to shift energy usage from peak hours to off-peak times.
The total aggregated and consumed disaggregated power of the appliances in house 2 in the REDD dataset, as well as the time-of-use (ToU) rates and solar radiation during the day, are shown in Figures 13a and 13b, respectively.It could be noted that many appliances with high power consumption work in peak hours with high tariff values according to the ToU electricity rate and also at low solar radiation.As a result, the customer can achieve cost-effective choices and pay lower prices.The energy cost varies depending on the time of day, with ToU rates being used to determine the energy cost at any given time.In other words, ToU rates are electricity rates used for billing customers that vary in price per kWh of electricity depending on the time of day.Electricity pricing fluctuates based on the time of day, day of the week (weekday or weekend), and time of year, with summer months typically having higher rates than winter months.By using NILM techniques and integrating new technologies such as the IoT [65,66], customers can control their home appliances to shift energy usage from peak to off-peak hours.This allows for maximized PV production exploitation, energy conservation, and cost savings, as illustrated in Table 8.
Smart Cities 2024, 7, FOR PEER REVIEW 22 time.In other words, ToU rates are electricity rates used for billing customers that vary in price per kWh of electricity depending on the time of day.Electricity pricing fluctuates based on the time of day, day of the week (weekday or weekend), and time of year, with summer months typically having higher rates than winter months.By using NILM techniques and integrating new technologies such as the IoT [65,66], customers can control their home appliances to shift energy usage from peak to off-peak hours.This allows for maximized PV production exploitation, energy conservation, and cost savings, as illustrated in Table 8.ThingSpeak offers various applications that simplify integration with web services, social networks, and other APIs, making it easier to work with IoT data.These are two examples of these applications: the React app and the TimeControl app [69].The React app enables users to set up specific actions based on certain conditions, also known as "reactions".For instance, when a channel reaches a specific condition, such as a power consumption threshold, the React app can trigger a tweet or generate a ThingHTTP request.The ThingTweet app, which is a part of the React app, allows users to send warning messages to consumers via Twitter when a specific condition is met.For example, if the power consumption of a particular appliance exceeds a certain threshold, the ThingTweet app can send a message to the consumer's Twitter account, warning them that the appliance is in use and encouraging them to take action to reduce their energy consumption, as shown in Figure 16.This allows for the real-time monitoring and control of appliances, ThingSpeak offers various applications that simplify integration with web services, social networks, and other APIs, making it easier to work with IoT data.These are two examples of these applications: the React app and the TimeControl app [69].The React app enables users to set up specific actions based on certain conditions, also known as "reactions".For instance, when a channel reaches a specific condition, such as a power consumption threshold, the React app can trigger a tweet or generate a ThingHTTP request.The ThingTweet app, which is a part of the React app, allows users to send warning messages to consumers via Twitter when a specific condition is met.For example, if the power consumption of a particular appliance exceeds a certain threshold, the ThingTweet app can send a message to the consumer's Twitter account, warning them that the appliance is in use and encouraging them to take action to reduce their energy consumption, as shown in Figure 16.This allows for the real-time monitoring and control of appliances, making it easier for consumers to manage their energy usage.The TimeControl app, on the other hand, enables users to schedule specific actions at pre-determined intervals.For instance, the app can send the power consumption of appliances to the customer at regular intervals, such as every hour or every day, as shown in Figure 17.This allows consumers to track their energy usage over time and make informed decisions about their energy consumption.The information provided by the TimeControl app can also be used to control appliances accordingly.For example, if the power consumption of a particular appliance is too high, the app can trigger an action to turn off the appliance or to notify the consumer to take action.This can help reduce energy waste and promote more efficient energy usage.
Smart Cities 2024, 7, FOR PEER REVIEW 24 making it easier for consumers to manage their energy usage.The TimeControl app, on the other hand, enables users to schedule specific actions at pre-determined intervals.For instance, the app can send the power consumption of appliances to the customer at regular intervals, such as every hour or every day, as shown in Figure 17.This allows consumers to track their energy usage over time and make informed decisions about their energy consumption.The information provided by the TimeControl app can also be used to control appliances accordingly.For example, if the power consumption of a particular appliance is too high, the app can trigger an action to turn off the appliance or to notify the consumer to take action.This can help reduce energy waste and promote more efficient energy usage.making it easier for consumers to manage their energy usage.The TimeControl app, on the other hand, enables users to schedule specific actions at pre-determined intervals.For instance, the app can send the power consumption of appliances to the customer at regular intervals, such as every hour or every day, as shown in Figure 17.This allows consumers to track their energy usage over time and make informed decisions about their energy consumption.The information provided by the TimeControl app can also be used to control appliances accordingly.For example, if the power consumption of a particular appliance is too high, the app can trigger an action to turn off the appliance or to notify the consumer to take action.This can help reduce energy waste and promote more efficient energy usage.

Discussion
This paper aims to optimize the utilization of PV plant production by applying the NILM approach.The simulation results presented in the study are divided into two stages.First, the performance of the residential microgrid is evaluated, followed by an analysis of the results obtained from the NILM algorithm.An algorithm based on the ANN and PSO has been used for load disaggregation.The data are preprocessed using the NILM algorithm, which is applied to datasets from building 2 of the REDD study, with five appliances selected as a case study.The results obtained from the proposed algorithm can be used to generate recommendations for reducing energy consumption by identifying specific uses of high-energy-consuming appliances.Also, the method has demonstrated high accuracy in identifying the appliances, and the consumer can use this information to manage energy demand, which leads to optimizing the utilization of PV plant production.
The proposed study also discusses the importance of employing an algorithm that improves the accuracy of the NILM technique, and the method has demonstrated high accuracy in identifying the appliances.The accuracy of the disaggregation algorithm can assist the consumer in making informed decisions to shift energy usage from peak hours to off-peak times.This can result in lower power consumption and cost savings, especially with smart home plans that offer variable pricing based on the time of day.The presented work also introduces the IoT based on the ThingSpeak platform for load monitoring and data analysis.The data can be sent to ThingSpeak from smartphones, instant visualizations can be created, and alerts can be received through web services, such as Twitter.The study shows that ThingSpeak provides various applications that facilitate easy integration with web services, social networks, and other APIs.

Conclusions
In this work, an efficient NILM-based energy management system for residential users in microgrids has been proposed.The battery energy storage system is incorporated into the microgrid's energy management system.The results clarified that the system is able to control power flow and minimize power fluctuations effectively.To optimize the

Discussion
This paper aims to optimize the utilization of PV plant production by applying the NILM approach.The simulation results presented the study are divided into two stages.First, the performance of the residential microgrid is evaluated, followed by an analysis of the results obtained from the NILM algorithm.An algorithm based on the ANN and PSO has been used for load disaggregation.The data are preprocessed using the NILM algorithm, which is applied to datasets from building 2 of the REDD study, with five appliances selected as a case study.The results obtained from the proposed algorithm can be used to generate recommendations for reducing energy consumption by identifying specific uses of high-energy-consuming appliances.Also, the method has demonstrated high accuracy in identifying the appliances, and the consumer can use this information to manage energy demand, which leads to optimizing the utilization of PV plant production.
The proposed study also discusses the importance of employing an algorithm that improves the accuracy of the NILM technique, and the method has demonstrated high accuracy in identifying the appliances.The accuracy of the disaggregation algorithm can assist the consumer in making informed decisions to shift energy usage from peak hours to off-peak times.This can result in lower power consumption and cost savings, especially with smart home plans that offer variable pricing based on the time of day.The presented work also introduces the IoT based on the ThingSpeak platform for load monitoring and data analysis.The data can be sent to ThingSpeak from smartphones, instant visualizations can be created, and alerts can be received through web services, such as Twitter.The study shows that ThingSpeak provides various applications that facilitate easy integration with web services, social networks, and other APIs.

Conclusions
In this work, an efficient NILM-based energy management system for residential users in microgrids has been proposed.The battery energy storage system is incorporated into the microgrid's energy management system.The results clarified that the system is able to control power flow and minimize power fluctuations effectively.To optimize the storage system operation and increase the reliability of the residential microgrid, the NILM technique has been used to disaggregate the power consumption, which helps the consumer control the appliances in the house and maximize the PV production exploitation.
The accuracy of the NILM technique has been improved using the PSO and ANN algorithms.Applying this to the Reference Energy Disaggregation Dataset shows that the PSO-optimized ANN can predict the appliance power consumption from the aggregated power of the home without the need for a smart meter at each appliance.Furthermore, an accuracy analysis was performed using the MAE method to evaluate the difference between the measured and predicted power consumption of the same appliance obtained from the algorithm, and it was found that it achieved better performance.The MAE values are in the range of 1.4164-29.0456,indicating a high level of consistency between the measured and predicted results.This eliminates the need for a smart meter in every appliance, which is a major advantage of NILM and reduces the installation cost and complexity.Additionally, the ThingSpeak platform has been used to transfer the data output from the NILM technique to the consumer, which enables them to control appliances by shifting usage from one time to another, optimizing the exploitation of the PV plant production and reducing power consumption.
Future work for the current study could involve testing the proposed NILM-based energy management system in a real-world residential microgrid to validate the simulation results.The study can also investigate integrating other energy storage systems and/or additional renewable energy sources and studying their impact on the energy management system.Moreover, the work can be further extended to study the economic benefits of the proposed NILM-based energy management system and its impact on reducing energy costs for residential users.

SmartFigure 3 .
Figure 3. Aggregated power consumption of 9 appliances of house 2 for one day.

Figure 3 .
Figure 3. Aggregated power consumption of 9 appliances of house 2 for one day.

Figure 3 .
Figure 3. Aggregated power consumption of 9 appliances of house 2 for one day.

Figure 4 .
Figure 4. Disaggregated power consumption of 9 appliances of house 2 for one day.

Figure 4 .
Figure 4. Disaggregated power consumption of 9 appliances of house 2 for one day.

Figure 3 .
Figure 3. Aggregated power consumption of 9 appliances of house 2 for one day.

Figure 4 .
Figure 4. Disaggregated power consumption of 9 appliances of house 2 for one day.

Figure 5 .Table 2 .
Figure 5. (a) PV cell model; (b) accurate battery model.Figure 5. (a) PV cell model; (b) accurate battery model.Table 2. Parameters of PV system.Parameter Value Band gap energy 1.1 eV Effective area per cell 0.01 m 2 Ideality factor of diode 1.5 Parallel connected cell strings per module 2 Parallel connected module strings per array 1 Parallel resistance per cell (Rp) 1000 Ω Reference cell temperature (T) 25 • C Reference irradiation (λ) 1000 W/m 2 Saturation current at reference conditions per cell 10 −9 A Series connected cells per module 900 Series connected modules per array 1 Series resistance per cell (Rs) 0.02 Ω Short circuit current at reference conditions per cell 0.0025 kA Temperature coefficient of photocurrent 0.001 A/K

Figure 6 .
Figure 6.Developed model of equivalent (n) series cells of batteries.Figure 6. Developed model of equivalent (n) series cells of batteries.

Figure 6 .
Figure 6.Developed model of equivalent (n) series cells of batteries.Figure 6. Developed model of equivalent (n) series cells of batteries.

Figure 7 .
Figure 7. (a) Load variation for one day; (b) solar radiation during the day; (c) solar production; (d) grid output power; (e) battery power; and (f) battery SOC.Figure 7. (a) Load variation for one day; (b) solar radiation during the day; (c) solar production; (d) grid output power; (e) battery power; and (f) battery SOC.

Figure 8 .
Figure 8.Comparison of the measured and predicted power consumption of fridge.

Figure 9 .
Figure 9.Comparison of the measured and predicted power consumption of microwave.

Figure 10 .
Figure 10.Comparison of the measured and predicted power consumption of kitchen outlet.

Figure 8 .
Figure 8.Comparison of the measured and predicted power consumption of fridge.

Figure 8 .
Figure 8.Comparison of the measured and predicted power consumption of fridge.

Figure 9 .
Figure 9.Comparison of the measured and predicted power consumption of microwave.

Figure 10 .
Figure 10.Comparison of the measured and predicted power consumption of kitchen outlet.

Figure 9 .
Figure 9.Comparison of the measured and predicted power consumption of microwave.

Figure 8 .
Figure 8.Comparison of the measured and predicted power consumption of fridge.

Figure 9 .
Figure 9.Comparison of the measured and predicted power consumption of microwave.

Figure 10 .
Figure 10.Comparison of the measured and predicted power consumption of kitchen outlet.Figure 10.Comparison of the measured and predicted power consumption of kitchen outlet.

Figure 10 .
Figure 10.Comparison of the measured and predicted power consumption of kitchen outlet.Figure 10.Comparison of the measured and predicted power consumption of kitchen outlet.

Figure 11 .
Figure 11.Comparison of the measured and predicted power consumption of dishwasher.

Figure 12 .
Figure 12.Comparison of the measured and predicted power consumption of stove.

Figure 11 .Figure 11 .
Figure 11.Comparison of the measured and predicted power consumption of dishwasher.

Figure 12 .
Figure 12.Comparison of the measured and predicted power consumption of stove.

Figure 12 .
Figure 12.Comparison of the measured and predicted power consumption of stove.

Figure 13 .
Figure 13.(a) Hourly total aggregated power consumption; (b) hourly disaggregated power consumption of appliances with corresponding ToU rates and solar radiation.Figure 13.(a) Hourly total aggregated power consumption; (b) hourly disaggregated power consumption of appliances with corresponding ToU rates and solar radiation.

Figure 13 .
Figure 13.(a) Hourly total aggregated power consumption; (b) hourly disaggregated power consumption of appliances with corresponding ToU rates and solar radiation.Figure 13.(a) Hourly total aggregated power consumption; (b) hourly disaggregated power consumption of appliances with corresponding ToU rates and solar radiation.

Figure 16 .
Figure 16.Twitter message to consumer at a certain condition.

Figure 16 .
Figure 16.Twitter message to consumer at a certain condition.Figure 16.Twitter message to consumer at a certain condition.

Figure 16 .
Figure 16.Twitter message to consumer at a certain condition.Figure 16.Twitter message to consumer at a certain condition.

Figure 17 .
Figure 17.Twitter message to consumer indicating a power consumption alert.

Figure 17 .
Figure 17.Twitter message to consumer indicating a power consumption alert.

Author Contributions:
All authors have contributed to the preparation of this manuscript.Conceptualization, Q.H. and D.-E.A.M.; methodology, R.R., Q.H. and A.S.Z.; software, R.R.; validation, Q.H., O.B. and J.L.; formal analysis, R.R. and D.M.Y.; investigation, A.S.Z. and D.M.Y.; resources, X.L.; data curation, R.R., A.S.Z. and D.-E.A.M.; writing-original draft preparation, R.R., A.S.Z. and D.-E.A.M.; writing-review and editing, Q.H., O.B. and J.L.; visualization, A.S.Z., D.M.Y. and X.L.; supervision, Q.H. and O.B.; project administration, D.-E.A.M.; funding acquisition, D.M.Y. and X.L.All authors have read and agreed to the published version of the manuscript.Funding: This work is based upon work supported by the Science, Technology and Innovation Funding Authority (STIFA), Egypt under grant number 44193; and the National Key Research and Development Program of China under Grant number 2022YFE0120400.

Table 1 .
Summary of various EMSs for residential microgrids.

Table 3 .
REDD house level description.

Table 6 .
MAE between the measured and predicted values at different appliances.

Table 7 .
MAE values using different algorithms in the literature compared to the ANN-PSO algorithm.