Intelligent energy storage