The popularity of the Internet of Things (IoT) continues to grow as information and related technologies advance. By integrating the virtual and physical worlds, the IoT creates a unified communication framework for connected devices such as sensors and other equipment. Smart homes are one of the most common and useful applications of IoT technology, attempting to simplify users' lives while also optimally monitoring events within the home. With the rise of smart home systems based on the IoT, data transfer related to the home has become commonplace. Many sensors are installed in internet-connected devices in a smart home to collect data about events within the home. These sensors must collect data from their surroundings and send it to the smart gateway at home, where appropriate applications can access it. Because IoT networks are wireless, secure data transmission in smart homes is critical. Data collected from sensors embedded in smart home devices may be lost during transmission for various reasons. Therefore, creating a secure communication method in IoT networks is essential for collecting data from smart homes. This study presents a secure data aggregation approach for smart homes based on the IoT, using a multi-agent approach. A multi-agent strategy is used to determine the ideal pathways between IoT network nodes and the gateway integrated in the IoT network, providing a secure data aggregation protocol in the smart home setting. In this protocol, the fitness function, which is a mix of network quality-of-service metrics, is used to weight secure agents along the path. Additionally, a fallback route based on the proportionality function value has been devised for secure data transmission in the event that the primary data transmission route fails or is not successfully received. The simulation results show that the proposed method not only improves the data delivery rate compared to older methods but also increases the dependability of the routes found in the IoT network in the smart home.