## 2 System Architecture and Components
### Energy Storage System Model  
The energy storage system consists of electrochemical devices that are able to store energy either from AC or DC sources. The ESS can be considered as a load during charging and a controlled generator during discharging. In order to prevent the ESS from undercharging and overcharging, the ESS is  
Figure 4: Predicted output power from the photovoltaic panels. Figure 3: Arrival and departure time of 100 electric vehicles (EVs) at the university parking lot. limited by its minimum and maximum energy storage, as given in Equation (3). We considered an ESS with a maximum charging and minimum discharging of 80% and 20%, respectively. \[\left\{ \begin{array}{l}P_{ESS,min}<\beta\times P_{ESS}<P_{ESS,max}\\ 0.2<SoC_{ESS}<0.8\end{array} \right. \tag{3}\]  
**3. Proposed Optimal Energy Management Algorithm**  
The main objective of the energy management system is to minimize the total power consumption from the main power grid, as given in Equation (4). \[Min\ P_{grid,ts}=P_{Building,ts}+\sum_{i=1}^{N}\alpha_{i,ts}\times P_{EV}^{i} \times\eta+\beta_{ts}\times P_{ESS}\times\eta-\gamma_{ts}\times P_{PV} \tag{4}\]  
where \(P_{grid,ts}\) is the amount of power consumption from the main power grid at time _ts_, \(P_{Building,ts}\) is the building power consumption at time _ts_, \(P_{EV}^{i}\) is the charging/discharging capacity of an EV at time _ts_, \(P_{ESS}\) is the charging/discharging capacity of the ESS at time _ts_, and \(P_{PV}\) is the generated power from the PV system at time _ts_. The coefficients \(\alpha\), \(\beta\), and \(\gamma\) are related to EV, ESS, and PV, respectively, as shown in Equations (5)-(7). \[\alpha_{i,t}=\left\{ \begin{array}{l}-1,\qquad EV\textit{ is discharging at ts}\\ 0,\qquad EV\textit{ is not participate at ts}\\ +1,\qquad EV\textit{ is charged at ts}\end{array} \right. \tag{5}\]  
\[\beta_{t}=\left\{ \begin{array}{l}-1,\qquad ESS\textit{ is discharging at ts}\\ 0,\qquad ESS\textit{ is not participate at ts}\\ +1,\qquad ESS\textit{ is charged at ts}\end{array} \right. \tag{6}\]  
\[\gamma_{t}=\left\{ \begin{array}{l}0,\qquad PV\textit{ output is not available at ts}\\ +1,\qquad PV\textit{ output is avaiable at ts}\end{array} \right. \tag{7}\]  
In this work, the proposed optimal energy management algorithm (OEMA) assigns different priorities to EV charging by considering the status of the building's power consumption, PV output and ESS. We assume that time is slotted and indexed by an integer in \(T\) = {1,2, 3,..., \(T\)}, where \(T\) is the time-period. The time-period is 24 h consisting of time slots. The time slot size (\(\Delta ts\)) is 15 min. The main objective of this work is to minimize EV charging costs while balancing the load profile of the power grid. We calculate the required number of charging timeslots (\(Nt\)) for each EV based on Equation (8) where \(SOCreq\) is the desired SOC of the EV battery for the user for the next trip (departure time), \(Bev\) is battery capacity, \(P_{c}\) is charging rate and \(\eta\) is the coefficient of charging power rate. \[N_{t}=\frac{SOC_{trip}\times B_{ev}}{P_{c}\times\eta\times\Delta ts} \tag{8}\]  
The EV charging cost is given in Equation (9) where \(C\) is the minimum EV charging cost, \(C_{elc}\)(\(ts\)) is the charging cost, \(P_{c}\) is the charging rate, and \(\eta\) is charging efficiency. \[C=Min\ \sum_{ts=1}^{Nt}C_{elc}(ts)\times P_{C}\times\eta \tag{9}\]  
Figure 5 illustrates the main flow chart of the proposed algorithm. The algorithm includes three main parts: ESS, PV output and EV charging/discharging with the user's preferences. The UEMS receives monitoring data from different sub-systems through communication networks. The major roles of the UEMS are:  
**Step 1**: -Initiition. * New day begins _ts_ = 0. * Get the day-ahead load profile of the engineering building and PV output. * Get SOC of ESS. **Step 2**: -Check Status of ESS. * Check time period (off, mid, on). * Check ESS status at current _ts_ then decide on the participation of ESS.