Internet of Things (IoT) is a groundbreaking technology which recently enjoyed a large increase in interest as it connects both digital and physical worlds together and allowing different devices with various capabilities to share their resources to perform a demanded task. Most of IoT objects are heterogeneous by their nature and are supplied with limited battery life. Therefore, distributing tasks among these objects is a big challenge. One of the primary objectives of task allocation algorithms is minimizing the energy consumption while maximizing the task allocation reliability. In this paper, we address the problem of task allocation in IoT as an optimization problem. We develop a nature-inspired meta-heuristic algorithm with heterogeneity aware heuristics to tackle the formulated problem. The proposed algorithm aims to ensure reliable task allocation while boosting the energy efficiency and the stability period of the network. Extensive experimental analysis of the proposed algorithm is realized using MATLAB and OMNET++ simulation scenarios. The results are compared with the most relevant algorithm in the literature and the superiority of the proposed algorithm in terms of energy efficiency has been proved.