Clustering and Fuzzy Logic-Based Demand-Side Management for Solar Microgrid Operation: Case Study of Ngurudoto Microgrid, Arusha, Tanzania

Department of Materials and Energy Science and Engineering, Nelson Mandela African Institution of Science and Technology, P.O. Box 447, Arusha, Tanzania Water Infrastructure and Sustainable Energy Futures, Nelson Mandela African Institution of Science and Technology, Nelson Mandela Rd, P.O. Box 9124, Arusha, Tanzania Electrical Engineering Department, Saint Augustine University of Tanzania, P.O. Box 307, Mwanza, Tanzania


Introduction
Electrical energy has been one of the most unsubstitutable and flexible sources of energy [1]. It is a vital resource in boosting the economy of any country. erefore, electricity intake is on the ever-increasing side leading to unreliable and low grid efficiency [2]. Meeting this ever-increasing demand means overexploiting the limited resources by establishing new power plants [3]. Towards meeting sustainable energy goals, microgrids have gained popularity as a worldwide trend of exploring green energy technologies [4][5][6]. Microgrids' challenges regarding reliability and stability have compelled many types of research on how to match demand with the available supply [7][8][9]. Also, finding appropriate ways of energy saving through customer-utility involvement has led to the concept of demand-side management (DSM) [10].
rough DSM, moderating power consumption and decreasing peak demand have become the most significant concern of both customers and utility companies [11,12]. erefore, in achieving sustainability, reliability, and stability of any electricity grid, DSM is indispensable and unavoidable [11].
DSM refers to programs seeking to modify consumers' energy consumption through efficiency improvements or shifting loads on the electric grid's customer side [13]. ey encourage customers to consume less during peak hours and more in off-peak hours through financial incentives and behavioural change [10,14]. DSM can be categorized as energy efficiency and demand response (DR) as illustrated in Figure 1. Energy efficiency programs encourage users to consume less energy while enjoying the same service level through energy-efficient devices [15]. DR programs target the demand profile whereby customers may either reduce their consumption during peak periods without altering the off-peak periods [16][17][18] or shift some loads from peak hours to off-peak hours due to high prices imposed during peak periods [13,16]. DR consists of intended electricity consumption pattern adjustments by end-users aiming at altering the total energy consumption or the timing and level of a sudden rise in demand [16,19]. It has three main categories: time of use (ToU), direct load control, and load shifting. ToU method is when there are no fixed electricity prices; instead, different prices are set for other usage times, and high fees are imposed during peak loads. e electricity price is determined by how much and when electricity is used [20].
In the direct control method, utilities have access to enduser customers and limit customers' electricity usage by switching down some of the appliances during peak demands. Most of the appliances suitable for direct load control are heavy loads such as refrigerators, air conditioners, and cooling devices [21]. Load shifting is shifting loads from peak to off-peak times to allow even distribution of the load. is method does not change the overall energy consumed; as an alternative, it keeps the demand and supply to the required possible level to increase system efficiency.
Apart from the mentioned programs, DSM makes use of various methods such as electricity tariffs [22], incentives [23], penalties [24], power-saving technologies, and government policies [25][26][27]. Incentive mechanisms are programs wherein a customer is being paid a monetary amount for his ability to reduce load during peak hours. is amount is separate from their standard rates of electricity applied, and it can be carried out as bill rebates or cash compensation [28,29]. e pricing mechanism uses different prices apart from ToU to reveal the cost and value of electricity within that hour. It is divided into two: real-time pricing (RTP) and critical peak pricing (CPP). RTP rates a varying price throughout the day by dividing a day into slots while CPP is when the electricity market charges differently depending on the supply cost of electricity [30]. DSM and DR can be used interchangeably.
By tradition, utilities have been managing demand from their side through reducing transmission losses and increasing generation capacities without success [31]. rough DRPs, successful energy management is possible; however, when usage patterns and customers' behaviours are taken into account, more realistic results can be attained since they are crucial towards success load management and decision making [32].

Related Works and Contribution
Referring to the available literature works, different researchers have implemented energy management in the electricity market using fuzzy logic. Yuan et al. (2018) proposed an energy management strategy based on fuzzy logic to distribute generated energy depending on the load demanded adequately. e method presented an improvement in the overall performance of the system [9]. On the other hand, Nehrir et al. (1999) implemented a customerinteractive DSM strategy using fuzzy logic to shift the water heater's usage pattern [33]. Results offered the possibility of flattening the load profile through fuzzy rules.
Similarly, through the fuzzy controller, three parameters were taken into account: cost, demand, and comfort. e benefit of renewables was analyzed to show how they impact cost and energy saving. Results showed better improvement of load profile through shutting down of loads during peak hours [34].
Also, the application of fuzzy logic has been realized in hybrid microgrids for energy management and supervisory control [35][36][37][38]. Multiagent energy management based on fuzzy logic was introduced, aiming at managing energy in a stand-alone renewable energy system [39]. Ravibabu et al. (2009) developed a fuzzy-based DSM controller to reduce peaks by prioritizing vital loads during peak hours [1]. He did not take care of the customers' comfort, and the research was limited to a single house. Another implementation of a fuzzy-based DSM was done for the residential customers of a grid-connected microgrid by assuming that both the loads and generations are noncontrollable. e simulation results of 25 rules presented improvement in the profile [40].
Furthermore, a DSM for residential customers was employed using the multiscale and multilayer method. Each household was equipped with its control system to limit loads during peak periods [41]. A multiagent-based DR was proposed based on the multistep hierarchical algorithm for a multimicrogrid system to ensure its reliability and cost reduction.
e method proved to be more cost-effective compared to conventional energy management systems [42]. A dynamic pricing DR was illustrated using reinforcement learning, which took care of the service provider's benefit and customers' cost reduction. Simulation results promised a balanced and reliable power system with reduced energy and operation cost [43]. To improve grid resilience and provide a cost-optimal solution for system operators, both mixed-integer linear and nonlinear approximation were used. e MINLP result is too large for nonlinear and nonconvex networks to provide efficient solutions [44].
On the other hand, providing an optimal solution using mixed-integer linear programming is time-consuming and slow, especially for larger datasets [45]. Most of the explained energy management system relies on traditional methods such as abstract and deterministic rules, which mainly encounter disadvantages like their inability to guarantee optimal results, especially when there are any fluctuations in the variables. Besides, abstract works usually approximate reality and rely on the developer's experience, hence sometimes unrealistic [43]. e significant advantage  of fuzzy logic over others is that no mathematical modelling is needed for the controller design. e outputs and inputs of a fuzzy controller are mapped with membership functions, and final rules are set to obtain the desired outcome [46]. Also, upon an unexpected change in the system parameters, no modifications are required in the controller, and since the outputs depend on the effects of the inputs, the same rule base can still be used [47].
Generally speaking, many DSM methods based on fuzzy logic have been implemented; however, most of these studies did not take care of the customers' usage patterns and their load types. Also, demand response programs in electricity markets have predominantly been conducted in developed countries compared to developing ones [10,48,49]. Obtained results may not be feasible to most developing countries' load profiles due to less flexible loads and even low per capita energy consumption [2]. Moreover, the behaviour point of view in developing countries with many isolated microgrids is different from well-established countries with reliable power. erefore, the present study aims at bridging this gap by developing a DSM based on fuzzy logic to control other clusters of customers independently to enhance customer participation since energy management is following how much and when they consume electricity. In this study, clustering and load limiting reduce the burden to low energy users as they do not influence peaks in the system. e study has utilized data collected from Ngurudoto solar microgrid, Arusha, Tanzania. e proposed method presents the potential of balancing energy in the microgrid based on the load limiting.
e new contributions of this work can be listed as follows: (i) A new fuzzy logic-based DSM approach has been proposed to match microgrid customers' real situations in the developing world with a vast difference in consumption (ii) e clustering approach has been used to facilitate customer prioritization; hence, low energy users did not suffer energy management burden (iii) e adopted method can enhance or trigger the DSM's embracement since the benefit is equally distributed depending on the potentiality of energy usage (iv) Customer usage pattern has been well established, which helps the power provider and customers plan for both energies, comfort, and cost-saving properly

Data Collection.
Consumption data were collected from a solar battery microgrid called Ngurudoto based in Arusha, Tanzania. It has a 7.5 kW capacity with wireless and communication modules for data communication, as shown in Figure 2. Electricity consumption was recorded using smart meters installed in each house. For each intelligent meter, real-time data were recorded using a combination of remote sensing devices, a data logger, and a remote PC. Collected demand data were analyzed using Microsoft Excel, Python, and Matlab. Fuzzy logic was done using MATLAB R2018a software.

K-Means
Clustering. K-means clustering is an unsupervised machine learning algorithm in which the grouping is done based on similarities and differences. It requires the following inputs: e methodologies involved in K-means clustering are summarized in Figure 3 and explained as follows: (i) e first step involves randomly initializing the value of K, which represents the number of clusters to be formed. e optimal value of K can be calculated using the elbow method. (ii) Distance between the data points and the initialized cluster centres is calculated by using the sum of square distance as follows: (iii) Depending on the minimum distance obtained, data points are grouped to the nearest cluster centres. (iv) e new centroid is calculated from the groups of data points moved to the same group, i.e., μ � data points in a certain cluster/total data points in that cluster (v) e mean is now repositioned as a new centroid. (vi) is process is repeated to all the clusters until there is no change in cluster centroids representing the clusters formed.

Case Study.
e main objective of this study was to design a DSM model for load management during peak hours. e microgrid located in Arusha, Tanzania, was considered as a case study whereby connected houses were grouped according to their usage patterns through clustering. e loads were also grouped into two groups: vital and nonvital, as illustrated in Table 1 to appreciate their importance. By applying DSM based on load priority and direct load control techniques, consumption was limited through cutting off nonvital loads during peak hours to supply power to the vital loads. Figure 4 represents the proposed model for controlling the loads according to their priority during peak hours. F1, F2, F3, and F4 are the fuses connected to the houses' nonvital loads in the respective clusters. e clusters suitable for energy management were selected according to the energy usage resulted from load profile classification. is selection helped prevent low energy users from the burden of the high cost of energy management. e fuses have a control signal from the fuzzy controller which trip off during peak hours when the load exceeds the Advances in Fuzzy Systems set limit.
is mechanism allows shutting down of only nonvital loads leaving the vital loads connected. e selection of loads is based on customer priority. e fuzzy logic controller being the central part of the circuit has two inputs: time and comparator. A comparator compares the reference set maximum current and the current flowing while the timer in the input time checks whether it is peak or off-peak. e outputs of the two are then fed to the fuzzy controller. A controller's output sends the desired control signal to the connected houses to limit the power consumption.

Fuzzy Logic Controller.
e fuzzy controller is an artificial intelligence system that can be used to either reduce, control, or modify power consumption. It works so that only consumers' priority loads are connected during peak hours, and within the off-peak hours, loads can be increased without exceeding the limit. e general working mechanism of a fuzzy controller contains the following components: (i) Input (ii) Fuzzification (iii) Inference engine (rules) (iv) Defuzzification (v) Output

Fuzzy Membership Functions.
For all the input and output variables, fuzzy membership functions are essential for defining linguistic rules that govern their relationships. For this case, the trapezoidal membership function is used for input time, as shown in Figure 5. Figure 6 shows zmf and smf, the most appropriate membership function for the feedback or comparator. For the output signals, constant and linear membership functions were used, as shown in Figure 7.
e most crucial task in the designing of the fuzzy controller is the development of the fuzzy rules. e number of rules always depends on the number of considered membership functions for both input and output blocks. In this study, the fuzzy controller is designed to limit power usage during peak hours by switching off some of the loads depending on the priority set. In this study, several rules are used, a few of them being mentioned below: (i) If time is off-peak (am) and feedback is < set current limit (A), then cluster 3 is all, cluster 4 is all, and cluster 8 is all (ii) If time is peak (am) and feedback is < set current limit (A), then cluster 3 is all, cluster 4 is all, and cluster 8 is all (iii) If time is off-peak (pm) and feedback is < set current limit (A) then cluster 3 is all, cluster 4 is all, cluster 8 is all (iv) If time is low and feedback is medium, then cluster 3 is no change, cluster 4 is no change, and cluster 8 is no change (v) If time is peak (am) and feedback is > set current limit (A), cluster 3 is vital, cluster 4 is vital, and cluster 8 is vital (vi) If time is off-peak (am) and feedback is none, then cluster 3 is all, cluster 4 is all, and cluster 8 is all (vii) If time is peak (pm) and feedback is > set current limit (A), cluster 3 is vital, cluster 4 is vital, and cluster 8 is vital (viii) If time is off-peak (pm) and feedback is none, then cluster 3 is all, cluster 4 is all, and cluster 8 is all

Case Study.
is study proposed fuzzy logic-based load management for an isolated solar microgrid. Twenty-two residential houses were considered whereby the K-means clustering algorithm was performed on the collected realtime electricity consumption data using the Scikit-Learn Python package [50]. Clustering was done to identify customers' typical usage pattern, grouping them into respective clusters and hence controlling their demand according to how they consume power. Load limiting and load priority techniques were used for the individual clusters to achieve a flatter load profile.
Clustering with K-means gave ten groups of clusters as per Figure 8, which was obtained using the elbow method that determines the number of clusters from the sample data provided. e results are represented by the elbow point or the first turning point of the graph where a small decrease in the error sum is observed. e appropriate K value is at number ten from the data used, as indicated in Figure 8. erefore, the number of clusters found is ten. From the cluster results in Figure 9, houses have been grouped based on similar usage pattern. All the clusters demonstrated variations in demand which indicated that there is a need for DSM. Apart from the usage patterns, clusters 3, 4, and 10 represented households falling in the highest use cluster. Given solar-powered microgrids, these customers may be regarded as potential users who mostly decide or influence the system's overall peak demand. On the other hand, clusters 6 and 9 consist of the lowest electricity users; one may assume that their primary usage is for lighting and phone charging. In the context of DSM, these customers should not be burdened with either the high prices or switching off some loads since they do not influence peaks in the system. e remaining clusters, 1, 2, 5, 7, and 8, represent medium-use customers.
is study's clustering results have shown great potential for a successful DSM program due to the proper load balancing technique. Clusters help identify customers responsible for energy management by assessing their degrees of peak generation. e importance of clustering results can be supported by Hannes et al. (2019), who explained that customers would strongly participate in any program if only they generate profit from it [51]. Figure 10 shows the composition of houses in each cluster. Cluster 2 represents a group with most customers while clusters 4, 6, 8, 9, and 10 each have only one customer, indicating that they have unique usage patterns.
From the results obtained, one individual house for each cluster of interest was chosen as a case study for DSM. e choice was made based on the highest consumer in each cluster to cater for the worst-case scenario. Table 2 shows the     Advances in Fuzzy Systems   e grouped customers were then characterized by both pattern and magnitude of consumption. By using the collected demographic data, different types of customers falling into each consumption category and load profiles were characterized. Figure 11 shows the relationship between different demography attributes and power usage for all the houses. Results show that the highest energy consumer is in house 14, falling under cluster 3. High consumption customers also tend to have indoor businesses, as explained by house number 14, which has a bar business. ese results are further supported by authors in ref. [52] who analyzed customers' consumption patterns in Tanzanian rural microgrids. From the demographic results, it is clear that the number of house members and their indoor businesses influences electricity usage. Medium-use customers represented by house number 10, falling under cluster 10, show considerable electricity usages. According to the survey data, one may argue that electricity consumption is due to many students who claimed to be using electricity for studying purposes. e argument is in correlation with the study by Elizabeth et al. (2020), who suggested that medium energy households' presence was due to school children's presence [53]. e same applies to house number 8, which seemed to have a significant consumption since they owned a small shop. House numbers 1,9,19,20, and 21 characterized the small users since they contain either a single family member or a more significant number of older adults who do not consume a considerable amount of energy due to their lifestyles. e present study tries to accommodate the low energy users by proposing a DSM mechanism which did not burden them since their electricity usage was not significant in the system peak generation. e surface viewer in Figure 12 shows the three-dimensional plot of three parameters: time, power, and the cluster power output after fuzzy logic DSM. e graph shows managed clusters 3, 4, and 8. In cluster 3, the off-peak dates represented by days before 14 were uncontrolled since the set power limit was not reached. is situation allows both vital and nonvital loads to be switched on similar to how Nehrir et al. (1999) explained the water heater operation scheduled during off-peak hours [33]. Peak days in the range of 18-22 marked the concentration area whereby the fuzzy logic controller helped limit the power usage to 1300 W using a 7.5 A fuse. e yellow colour shows the shaved or clipped area after DSM, which is the operator's target. For cluster 4, the allowable load was set as 800 W during peak hours. Load limiting was done via a 4 A fuse which shut down excess loads observed on the 21 st day. Likewise, in cluster 8, all the loads were limited to 600 W during peak hours. Excessive loads found in the range of 24-26 days were shaved to 600 W, as depicted in the diagram. Figures 13 and 14 show the rule viewer of the outputs for clusters 3 and 4, respectively. e rule viewer is used to show the effectiveness of the output. From these diagrams, two points were taken into consideration: off-peak and peak periods. On the sixth day, cluster 3, represented in Figure 13 represents the off-peak points. A feedback current of 2.99 A corresponding to a power of 657.8 W gave an output power of 657 W after fuzzification.
e results show almost the same energy before and after fuzzification, indicating that the loads were not managed or shifted. In the exact figure, peak points are represented by the 17 th day. e power observed was 1738 W single-phase, which gave a feedback current of 7.9 A to the controller, and hence, the power was limited to 1000 W by switching off nonvital loads.
Similarly, cluster four, represented by Figure 14, shows the results during off-peak and peak periods. Load curtailment is observed during peak hours while nothing was done during off-peak hours. e fuzzy controller achieved the above through the feedback current received. Figures 15-18 represent the monthly load profiles before and after implementing DSM for clusters 3, 4, 8, and 10, respectively. e results show that the generated power can be fully utilized except during peak power periods by implementing fuzzy logic-based energy management scheme as the author depicted in ref. [9]. Before optimization, the load demand is higher than the set limits. After applying a fuzzy logic controller, closer to a flat load profile is seen, which helps avoid system collapse and blackouts, especially during peak hours. e profiles clearly show that each cluster's peaks have been restricted to match the corresponding limits set. Also, the overall load profile before and after implementing fuzzy logic DSM is shown in Figure 19. ere is a significant reduction in demand during peak periods due to the clusters that have taken part in DSM.
ese results show more improvement in the design and implementation than that reported by Ravibabu et al. [1] since many houses have been included in the clustering approach. Also, with this approach, small electricity consumers are not taken into consideration until when they satisfy for DSM. Figure 20 shows energy savings for different days in a month and the overall energy saving per month. e graph shows the power saving of almost 3700 W per month. e amount of saving achieved is very significant in the DSM context, and it assures the system stability in case of peak loads. Different energy savings are also observed for different days due to the variable nature of demand [54]. Moreover, on the 3 rd , 5 th , 7 th , 11 st , 13 th , 14 th , 16 th , 19 th , 22 nd , and 24 th days, the savings are approximately close to zero, and one may argue that no load was either shifted or switched off. In this scenario, the argument can be that most of the houses were in the offpeak range, hence retaining the same energy before and after DSM. Likewise, the highest energy saving was achieved on the 27 th day, and one may suppose that several nonvital loads were shut down to avoid overloading the system. It is clear from the obtained results that, with fuzzy logicbased energy management strategy, demand profiles can be levelled, and available generation can be optimized Advances in Fuzzy Systems appropriately to meet consumers' needs. Since the proposed method tried to operate the loads partly, the system's efficiency can be improved. e above observation is in line with ref. [55] and further supported by ref. [33]. On the other hand, since both the customers' load demand and the power generated from solar microgrids are uncertain and stochastic, the fuzzy logic controller has proven to be the most efficient and effective method compared to mathematical

10
Advances in Fuzzy Systems models discussed by the authors in ref. [9].

Conclusion
e available gap between demand and supply due to the increase in electrical appliances, leading to a shortage of electricity during peak usage, is pronouncing. DSM programs offer an enhanced chance to exploit consumption diversity and accordingly reduce the peak demand for electricity. Shifting loads from peak to off-peak or switching off some loads during peak hour's period can be a challenge to specific customers; hence, exploiting their usage pattern through clustering leads to more flexible DSM techniques. In this work, the fuzzy logic-based DSM programs are used as a load limiter to control loads during peak hours. is control mechanism helps in the proper utilization of the available power at a given time by giving priority to vital loads depending on the preference set by customers.
Moreover, the proposed program favours all kinds of customers, hence encouraging their participation in DSM. erefore, this study is essential to guarantee energy saving and customer satisfaction. It can be further extended to account for cases where consumers are given incentives for their willingness to participate in the DSM program.

Data Availability
e data used to support the findings of this study will be available upon request.

Conflicts of Interest
e authors declare that they have no known competing for financial interest or personal relationships that could have influenced the work reported.

Authors' Contributions
is paper was a collaborative effort between the authors. e authors contributed collectively from the idea development to manuscript preparation.