Energy Management in Homes and Residential Microgrids