The Role of IoT in Smart Grids: Balancing Energy Supply and Demand