## 2 Experimental Setup and Proposed Method
### Battery Sizing and Modeling
\[E_{PV}+E_{bd}+E_{sg}=E_{ld}+E_{bc}+E_{bg}, \tag{4}\]  
\[-P_{max}\leq P_{ESS}\leq P_{max}, \tag{5}\]  
\[-SOC_{min}\leq SOC(t)\leq SOC_{max}, \tag{6}\]  
where \(E_{PV}\) is the PV energy generation (kWh), \(E_{bd}\) is the battery discharge energy (kWh), \(E_{sg}\) is the energy transferred to the grid from PV + ESS (kWh), \(E_{ld}\) is the load demand energy (kWh), \(E_{bc}\) is the battery charge energy (kWh), \(E_{bg}\) is the energy transferred to the load from the grid (kWh), \(P_{max}\) is the maximum discharge power of the ESS, \(SOC_{min}\) is the minimum charge stage of the ESS, and \(SOC_{max}\) is the maximum charge stage of the ESS. The proposed method's flow chart is shown in Figure 5. The proposed algorithm evaluates the SOC, energy consumption, energy generation, irradiance, etc., and operates the rooftop PV system with ESS support considering the introduced scenarios in this study. Energy management begins with the evaluation of environmental and electrical inputs. The power generated by the PV system is calculated using real-time irradiance and temperature data and is evaluated together with the electricity consumption profile of the factory. At this point, one of the basic decision variables determining the energy management strategy is the radiation level, as the power output of PV panels is directly related to it. Although panels can produce power at low irradiance, the amount of power produced increases rapidly as irradiance increases. In this study, the threshold irradiance value was  
Figure 5: The proposed algorithm for ESS support for a rooftop PV system. selected as 500 W/m\({}^{2}\). When irradiance exceeds this level, The power generated by PV panels can be transferred to the grid. At lower irradiance levels, it is more appropriate to store the energy produced by panels in batteries or use it for internal consumption. In other words, since PV production below this threshold value is generally insufficient to meet the load demand, the missing energy is provided by the battery or the grid. If the irradiance level exceeds this threshold value, PV production not only fulfills load consumption but also begins charging the battery. When the battery is full, and the instantaneous production still exceeds the demand, and the excess energy is transferred to the grid. In this process, the energy flow is managed dynamically depending on the battery's state of charge (SOC). When the maximum SOC limit is reached to prevent the battery from being overcharged, the battery stops charging and the excess energy is directly transmitted to the grid. Similarly, a minimum SOC limit is determined to prevent overcharging, and when this level is below, the battery is restricted from supplying power to the load. The model also incorporates economic optimization by considering time-dependent fluctuations in electricity prices. At certain times of the day, when the cost of electricity purchased from the grid is low, the battery can be charged from the grid to minimize the high-priced grid use in the following hours. On the other hand, during hours when electricity prices are high, the battery can be discharged to feed the load and reduce the electricity drawn from the grid. This approach is integrated with demand-side management strategies.