1 Introduction

Photovoltaic technology (PV) based microgrids have become widely viable due to the availability of solar energy, reliability and cost reduction of PV modules and user-friendly policies and incentives by most countries worldwide [1]. These microgrids also lower the electricity bills of consumers through several user-friendly policies in some countries. However, solar power generation exhibits variability caused by a number of variables, like PV panel orientation, location, temperature, humidity, and fluctuating radiation levels [2].

These changes lead to large differences between the minimum and maximum generation within 15 min to an hour, as well as significant variations in the generated power in the short time scale (1 s to 1 min), known as solar ramps. As a result, a sudden decrease in energy output could harm or hasten the depreciation of traditional backup power sources such as diesel generators [3]. On the other hand, predicting solar generation is complicated due to the need to consider the aforementioned factors [4].

Smart energy management systems (EMSs), which are supported by AI, are used to address these issues [5]. By utilising forecasting and optimisation techniques, EMSs play a significant part in effectively regulating the generation sources and load demand [6, 37]. EMSs provide efficient answers to problems that conventional solar microgrids face, such as the best network setup, real-time power flow control [7], load scheduling, peak shaving, and other concerns. Furthermore, EMSs can be modified to accomplish different goals spanning economic, environmental, social, and technical elements [8].

In addition to its operational advantages, EMSs offer a supervisory interactive user-machine interface that enables users to securely monitor and regulate their energy consumption [9]. Moreover, EMSs provide trustworthy decentralised trading options that are safe and dependable for users and the main grid, enabling an energy exchange system that is more effective and resilient [10].

The fact that the inverters must synchronise with the grid in order to operate means that when there is a power outage, the generated power cannot be used, which is one of the main issues with conventional grid-connected solar microgrids [11]. This causes large losses and has the potential to speed up system degradation [12]. This issue can be resolved in a variety of ways, including by switching out the inverters, adding storage, or synchronising the inverters with diesel generators. However, from an economic or environmental standpoint, these solutions are expensive and do not serve the primary goal of installing solar panels [13].

The term "optimal power flow" (OPF) of microgrids is used when a controlling system is employed to provide the ideal operation state of microgrids by maintaining steady power flow while abiding by all restrictions and limitations [14]. It can be modelled in three different ways: scheduling, where the EMS is assigned to determine the best schedule for every grid component while abiding by all limitations over a certain time horizon [15]. The second problem is known as a unit commitment (UC) problem, where the goal is to reduce overall operating expenses which is likely to have ESSs [16]. Finally, dispatching is the process of reducing the cost of fuel and gas emissions from diesel generators or any other pollution generators used in microgrids [17].

Moreover, EMS for peak-shaving and tariff reduction is proposed in [18] by adding ESS. Customers are divided into classes based on their consumption using the extreme learning machine (ELM) and k-means algorithms. Load forecasting is done using SVR, and system reliability and peak shaving requirements are optimised using a MILP model and linearization technique.

Optimal network configuration (ONC) refers to the process of determining the locations and capacity of each component in microgrids that are optimal [19]. In order to reduce power losses and system fluctuations, ONC can be implemented using optimisation techniques [20, 21] or other software, such as HOMER [22]. Furthermore, ONC also includes transmission issues. As a result, EMSs are created to determine the best network configuration for new systems while taking into account all the variables and limitations [23].

Khan et al.'s [24] overview of microgrid-related issues and solutions was succinct, but it did not mention any research gaps or the benefits and drawbacks of the various approaches. Papadimitrakis et al. [25] present metaheuristic methods for handling the intricacy of microgrid management issues. Nosratabadi et al. [26] studied the microgrid and virtual power plant scheduling problem with a focus on dependability, modelling approaches, demand response, problem-solving approaches, uncertainty, etc.

A number of Metaheuristic techniques are implemented for developing smart energy management systems. Multi-objective muti-Verse Optimizer (MVO) is presented in [27] to optimize the renewable factor, cost of electricity, and power losses of a microgrid and found to be superior. An adaptive Differential Evolution algorithm is used in [7] for OPF with real-time pricing. Bacterial Foraging Optimization is implemented in [28] for a unified OPF controller. The main challenge in metaheuristics is not to converge at local minima therefore, two methods are followed by metaheuristics that are exploration and exploitation. To achieve better optimisation results, the algorithm should balance between those two methods to ensure searching the neighbourhood space as well as the global space [29].

Grey Wolf Optimiser (GWO) has a great balance between those two methods and evaluated in the literature for many problems and found to be efficient. GWO is used in [30] for battery sizing for different scenarios, and compared with genetic algorithm (GA), particle swarm optimization (PSO), the Bat algorithm (BA), and the improved bat algorithm (IBA). GWO showed outstanding results and superior performance compared with other algorithms in terms of solution quality and computational efficiency. GWO is also utilised in [31] for microgrid battery sizing problems and compared to PSO, artificial bee colony, GA and gravitational search algorithm, and found to be more accurate. An ensemble short-term forecasting approach and GWO are proposed in [32] for microgrid scheduling. GWO aims to minimize the operating cost of a grid-connected residential microgrid and showed an excellent performance under three scenarios. Oppositional Gradient-based GWO is proposed in [33] for optimal operation of microgrids and compared with other techniques showing better performance for reducing the cost and pollution.

1.1 Novelty and contribution

The novelty of this study is to develop a smart energy management system that can control the load demand and the power supply in order to reduce the power losses and supply the loads when there are power outages. The model consists of two parts, first a forecasting model using ANN for solar power generation. The second part is a load demand controlling system that utilises the grey wolf optimization technique to control and decide which loads can be supplied based on the forecasted power generation. This system is developed in order to be further implemented for a 400kWp grid-connected solar system installed at the Centre of Excellence in Energy Science & Technology, Shoolini University in India to reduce the power loss and the use of diesel generators.

The rest of the article is divided into 3 sections; Sect. 2 explains methodology. Section 3 presents the results and discussion followed by conclusions drawn and follow-up research in the last section.

2 Methodology

In this section, the methodology followed to develop and evaluate a real-time smart energy management system under real conditions is described.

2.1 Experimental setup

This study aims to reduce the losses of a 400 kWp grid-connected solar system installed at Shoolini University in India by developing a smart EMS. Therefore, a lab. scale prototype is developed in order to test the behaviour of the EMS under real conditions and in real-time scenarios. A 12 V DC microgrid is established as shown in the schematic diagram Fig. 1 to simulate the real system and study the expected benefits from the proposed system. A 40 Wp solar PV panel with a DC-DC converter are used to represent the solar PV system and a 12 V 10A power supply represents the main grid. 8 different loads, including different sets of LEDs, are connected using relays to simulate different buildings with different load profiles that vary from 0.35 W up to 5.5 W. The load profile of each building is generated randomly whereas each load rate is considered to be constant. Moreover, to simulate the net-metering concept, a separate resistor is connected individually to dump the surplus generation.

Fig. 1
figure 1

Block diagram of an experimental microgrid setup with a smart energy management system

Two INA219 sensors are used to measure current, voltage, and power from the panel and grid, and a separate one to measure the power exported to the grid. A Raspberry Pi 4 module is used to control the system and the proposed EMS is implemented using Python. Moreover, a user-machine supervisory system is developed to allow users to add new loads and to monitor and display consumption and generation. The lab-scale experimental microgrid setup with a smart energy management system is shown in Fig. 2 and the components used are given in Table 1.

Fig. 2
figure 2

Lab scale microgrid experimental setup with smart energy management system

Table 1 The components used in the setup

The experiments were conducted at the outdoor solar PV research facility of the Centre of Excellence in Energy Science and Technology, Shoolini University, Solan, India in June 2023.

2.2 Power generation forecasting using ANN

A simple time-series ANN model is designed to forecast the power generation by the PV module based on the previous data which are the last three readings. In this study, parameters like solar radiation, temperature, humidity, etc. are not considered as those sensors are not available. However, only one PV panel is used and other controllable parameters like tilt angle, azimuth, orientation, and cleanliness are fixed so that the ANN model can efficiently predict the generation [34]. Moreover, the model’s error is always subtracted from the output so that no damage can happen when the generation is less than the demand.

2.2.1 Artificial neural networks

The fundamental feed-forward neural network architecture consists of three layers (input, hidden, and output), each with a number of nodes, which only allows data to be fed in one direction [35]. Equation (1) uses weights "w" to connect these layers, mapping the inputs "x" to the desired output "Y" based on their correlation. where,\({\prime}\beta \mathbf{^{\prime}}\) denotes the bias, and \({\prime}\delta {\prime}\) denotes to the activation function used.

$$Y = \delta ( w*x + \beta )$$
(1)

The weights of the ANNs are randomly initialised using a variety of methods, and during the training mode, they are changed using learning algorithms such as backpropagation, Levenberg–Marquardt, or occasionally metaheuristic methods employing Eq. (2).

$${w}_{new}= {w}_{old} - a E$$
(2)

where 'a' stands for learning rate and 'E' for error. The cost function, which can be any function, is used to calculate the error; however, mean squared error (MSE) is selected for this study.

2.3 Smart load demand controlling system

A smart decision-making system is developed to control the load demand when the main grid is off. Based on the power generation forecasts the system will decide which loads are to be supplied while it ensures that the maximum load is supplied.

The proposed system's flow chart is shown in Fig. 3. First, the controller will read the sensors’ values, then it will check if the grid is on or off. If the grid is on, then the system will be dependent on the grid signals, and it will import and export the required and surplus power in accordance with the demand–supply values. On the other hand, when the grid is off, the proposed system will control both the demand and supply and make sure that the voltage remains stable at or above the threshold (10 V). When the voltage drops below this level, the controller will immediately interfere to stabilize the voltage. First, the ANN model will forecast the current power generation of the PV module, and based on that the GWO will assess whether the loads can be supplied or should be shed to maintain both objectives, first decrease losses by maximizing the used power from solar and second by keeping the system stable with voltage above 10 V.

Fig. 3
figure 3

Flow chart of the proposed smart energy management system

Indeed, the performance of any optimizer varies significantly when the problem dimensions increase. However, in this study, a small number of decision variables are used that makes the optimization problem easier for any optimizer. Therefore, Grey Wolf Optimizer is chosen for this task due to its competitive behaviour, in terms of accuracy and speed, that is shown in the literature [31].

2.3.1 Grey wolf optimizer

GWO is a metaheuristic method that draws inspiration from the natural behaviour of grey wolves [36]. According to the hierarchy of wolves' leadership, four different sorts of wolves are responsible for hunting, encircling, and attacking victims. Figure 4 depicts the procedure for locating the ideal solution, and it may be summarised as follows:

  1. 1.

    Initialise the population at random with N wolves, with each wolf standing in for a different load combination.

  2. 2.

    Calculate the fitness of each particle which is the difference between load and generation.

  3. 3.

    Sort the particles based on their fitness values.

  4. 4.

    Start phase one which is “Encircling prey”.

  5. 5.

    Calculate the value of \(\overrightarrow{a}\) which decreases from 2 to 0 linearly as per the Eq. (3)

    $$\overrightarrow{a}=2*(1-\frac{i}{I})$$
    (3)

where “i” is the current iteration number, and “I” is the maximum iteration number.

Fig. 4
figure 4

Flow chart for Grey Wolf Optimizer-based Smart Energy Management System

Compute the value of coefficient vectors \(\overrightarrow{A}\, and\, \overrightarrow{C}\)

$$\overrightarrow{A}= 2*\overrightarrow{a}*\overrightarrow{{r}_{1}}-\overrightarrow{a}$$
(4)
$$\overrightarrow{C}= 2* \overrightarrow{{r}_{2}}$$
(5)

where \(\overrightarrow{{r}_{1}}\, and\, \overrightarrow{{r}_{2}}\) are random values between 0 and 1.

Start the “Hunting” phase which requires updating the positions of the wolves according to the information from the best wolves

$$\overrightarrow{D}=|\overrightarrow{C}*\overrightarrow{{X}_{i}(p)} - \overrightarrow{{X}_{i}}|$$
(6)
$$\overrightarrow{{X}_{i+1}}= \overrightarrow{{X}_{i}(p)}- \overrightarrow{A}*\overrightarrow{D}$$
(7)

where \(\overrightarrow{{X}_{i}(p)}\) the prey position, and \(\overrightarrow{{X}_{i}}\) the wolf position

$$\overrightarrow{{D}_{a}}=\left|\overrightarrow{{C}_{1}}*\overrightarrow{{X}_{a}} - \overrightarrow{{X}_{i}}\right|, \overrightarrow{{D}_{B}}=\left|\overrightarrow{{C}_{2}}*\overrightarrow{{X}_{B}} - \overrightarrow{{X}_{i}}\right|, \overrightarrow{{D}_{g}}=|\overrightarrow{{C}_{3}}*\overrightarrow{{X}_{g}} - \overrightarrow{{X}_{i}}|$$
(8)
$$\overrightarrow{{X}_{1}}= \overrightarrow{{X}_{a}}- \overrightarrow{{A}_{1}}*\overrightarrow{{D}_{a}} , \overrightarrow{{X}_{2}}= \overrightarrow{{X}_{B}}- \overrightarrow{{A}_{2}}*\overrightarrow{{D}_{B}}, \overrightarrow{{X}_{3}}= \overrightarrow{{X}_{g}}- \overrightarrow{{A}_{3}}*\overrightarrow{{D}_{g}}$$
(9)
$$\overrightarrow{{X}_{i+1}}=\frac{\overrightarrow{{X}_{1}}+ \overrightarrow{{X}_{2}}+ \overrightarrow{{X}_{3}}}{3}$$
(10)
  1. 8.

    Repeat steps 4 to 7 “I” times.

  2. 9.

    Return the best wolf in the population which is the optimum solution that gives the command to shed the loads or not.

The system aims to minimise the losses and stabilise the system during power outages, to achieve that GWO has to make sure that the generated power matches with the demand. In case the load is more than the generation, the algorithm will shed some loads to keep the system stable. The objective function in (11) is employed to do this:

$$F\left(x\right)=min \left|\sum_{i=0}^{N}{x}_{i}*{r}_{i}*{w}_{i} - {P}_{pv}\right|$$
(11)
$$\mathrm{s}.\mathrm{t}. \sum_{i=0}^{N}{x}_{i}*{r}_{i} \le {P}_{pv}$$

where N is the number of loads, \({x}_{i}\) are the decision variables, \({r}_{i}\) is the rate of load i, and \({P}_{pv}\) is the forecasted power generation. \({w}_{i}\) represents the priority of the loads which is considered to be the same for all loads in this study. However, this system can be employed when the solar plant's capacity is insufficient to meet the entirety of the load demand. In such instances, it prioritizes supplying power exclusively to critical loads. Moreover, to maintain voltage stability, the system continually monitors the voltage level through a sensor. If a voltage drop is detected, the process is iterated with an alternative forecasting value, ensuring that critical loads receive an uninterrupted power supply and voltage stability is preserved.

3 Results and discussion

The power generation data of the module are collected for different days and conditions then the ANN model is trained on this data in order to predict the generation for the next minute based on the previous three readings. The ANN model’s behaviour is shown in Fig. 5, the forecasts as close to the real values with an error of 0.3 W of mean absolute error (MAE). It is noted that the error increases when there is a sudden change in the generation which is due to using a simple forecasting model and not taking into consideration other factors. However, this model is sufficient for the prototype as it serves the purpose of the study.

Fig. 5
figure 5

ANN forecasts as compared to the actual power generation from the PV module

The value of MAE is considered to be the safety threshold that is subtracted from the generation forecasts in order to ensure a high level of forecasting confidence to protect the devices in case of low generation in case of any sudden voltage drop.

Then the entire setup is installed under real conditions in order to practically evaluate the proposed system considering random loads and two different conditions, cloudy and sunny days. Moreover, the solar generation is considered to start from 6:00 up to 18:00 in the day and the system is tested on two different days under two conditions cloudy and sunny.

The first test is carried out on a cloudy day, Fig. 6 shows the power plots for all the generated (185W), imported (927.5W) and exported (1.9W) power along with the actual load and the unsatisfied load. The negative value of the grid represents the exported power, which is much less in this scenario due to low generation from the PV module, whereas the percentage of the generation to the total load is 15% only. The unsatisfied load is found to be 111.2 W for the entire day and 37.4 W excluding the loads when there is no solar generation. This value represents about 33.6% of the total unsatisfied. The supplied load during power outages is 27.7 W which is 42.6% of the load demand during the power outage.

Fig. 6
figure 6

PV System Performance on a cloudy day (June 29, 2023)

It was noted that the controller is most likely to shed all the loads in this scenario as the power generation is very low as compared to the load and at some points it has taken decisions to supply the demand according to the power generation forecasting model.

To evaluate the performance of the system in terms of voltage stability, the DC Bus voltage is analysed throughout the time when solar generation exists. As shown in Fig. 7 the EMS always tries to maintain the voltage above the 10 V threshold, however, due to faulty forecasts at some points the voltage drops below this level. This can be addressed by developing a more accurate model that considers all important parameters that impact the generation.

Fig. 7
figure 7

DC bus voltage during solar hours on a cloudy day (June 29, 2023)

In the second scenario, the system is tested on a sunny day. The performance of the system is shown in Fig. 8. The total power generation is found to be (1513 W) which is higher than the total load therefore the exported power is more than the imported one with a 67W difference. As depicted by the yellow line, the sold (negative) power is high and in total the generation almost matches the consumption with a percentage equal to 102%. The unsatisfied load, shown in green, is found to be 40W for the entire day all are found out of the solar time while 100% of the load is supplied during the existence of solar generation.

Fig. 8
figure 8

System performance on a typical sunny day (June 30, 2023)

It was noted that the controller did not shed any of the loads in this scenario as the power generation matches the loads and at some points, it has taken decisions to supply the demand according to the power generation forecasting model.

To check the stability of the system, the DC voltage is plotted during the solar hours. As shown in Fig. 9, the system is more stable when it is fully sunny. This is due to higher forecasting accuracy and higher generation which can fulfil the load demand.

Fig. 9
figure 9

DC bus voltage at the solar hours on a sunny day (June 30, 2023)

Table 2 represents the system’s measures under two different scenarios. The system can reduce the losses in the conventional solar microgrid by 42.6% on a cloudy day and 100% on a sunny day.

Table 2 The system performance under different conditions

The results show that forecasting errors have many effects on the system's behaviour. When, forecasts are less than the actual generation, in this case, the system voltage will remain stable however, there will be partial losses in generation and some loads will be unsatisfied. In contrast, high forecast values result in connecting load demand more than the generation that is reflected by the voltage drop which may be harmful for the appliances.

4 Conclusions and follow up research

In this study, a novel smart energy management system is developed that forecasts power production using an artificial neural network and controls the load using Grey Wolf Optimiser. The system is tested for addressing conventional solar microgrid problems and enhancing its performance during grid outrage. The proposed system offers a promising solution that ensures reliable power supply, reduces energy losses, and hotspot development in PV modules. Based on the results following conclusions are drawn:

  • It is found that smart energy management systems empowered by AI can efficiently solve the conventional grid-connected solar microgrid problems.

  • ANN model is utilised to forecast the power generation for a lab-scale experimental microgrid and found to be efficient. However, for large microgrid systems with more complicated conditions, a more robust model is required to be developed.

  • Grey Wolf Optimizer has given accurate decisions for a small number of decision variables. However, it must be extensively tested when implemented for large-scale conventional microgrids.

  • This solution is less expensive than other available solutions as it requires few sensors and relays.

  • The system has shown an efficiency of reducing the losses in conventional solar microgrids up to 42.5% on a cloudy day and 100% on a sunny day.

  • It is found that the forecasting model plays a vital role in managing the load. It should be accurate enough to keep the system stable and prevent the voltage drops. Therefore, other parameters should be considered for more complex systems.

The prototype microgrid setup has shown promising behaviour under real conditions for controlling and monitoring the load demand and energy supply of conventional microgrids.

4.1 Follow up research

The developed smart energy management system will further be implemented to improve an existing conventional grid-integrated 400 kWp solar microgrid installed on the rooftops of different buildings in the university campus, catering to the needs of different loads [37,38,39]. The present study results will further be utilised for follow-up of earlier microgrid-related studies and conventional systems worldwide.