  We consider the residential energy storage management system with integrated
renewable generation, with the availability of bidirectional energy flow from
and to the grid thorough buying and selling. We propose a real-time
bidirectional energy control algorithm, aiming to minimize the net system cost,
due to energy buying and selling and battery deterioration and inefficiency
from storage activities, within a given time period, subject to the battery
operational constraints and energy buying and selling constraints. We formulate
the problem as a stochastic control optimization problem. We then modify and
transform this difficult problem into one that enables us to develop the
real-time energy control algorithm through Lyapunov optimization. Our developed
algorithm is applicable to arbitrary and unknown statistics of renewable
generation, load, and electricity prices. It provides a simple closed-form
control solution only based on current system states with minimum complexity
for real-time implementation. Furthermore, the solution structure reveals how
the battery energy level and energy prices affect the decision on energy flow
and storage. The proposed algorithm possesses a bounded performance guarantee
to that of the optimal non-causal T-slot look-ahead control policy. Simulation
shows the effectiveness of our proposed algorithm as compared with alternative
real-time and non-causal algorithms, as well as the effect of selling-to-buying
price ratio and battery inefficiency on the storage behavior and system cost.
