As a result of the exponential increase in energy consumption, energy shortages, and augmented energy costs have become a significant problem for households. Solar cells are used in many homes and/or buildings to address these problems. However, managing renewable energy sources in homes can be difficult due to the irregular nature of renewable energy production. Internet of Things (IoT) devices can provide real-time data on energy production and consumption, offering a promising solution to this issue. The current study proposes a framework based on IoT and blockchain technology for home energy management by predicting future energy consumption patterns and optimizing energy use in real time. The blockchain module facilitates peer-to-peer energy trading between renewable energy-generating homeowners and consumers. The proposed framework was tested employing a dataset based on smart homes with solar panels and wind turbines. The results manifest a reduction in energy costs and a possible 30% increase in their traditional gain.