Internet of Things (IoT) is an environment that contains different embedded devices interacting with each other to perform tasks related to information collection, communications and processing. Successful applications of loT aim to interconnect objects with various capabilities within the same heterogeneous network. The goal is to allow network entities to cooperate and make their resources available in order to perform the demanded task. However, assigning tasks to group of heterogeneous objects that are equipped with limited resources poses a challenging task. The most limited and valuable resource for variety of loT objects is battery power. Therefore, minimizing the energy consumption in task allocation process is one of the primary objectives. Currently, almost all existing studies employ heuristic optimizations to cope with different aspects of task allocation problems without considering different energy levels of network entities. In this paper, we address the problem of task allocation in loT applications. We model the problem as a single objective optimization problem with the main goal to minimize the energy consumption. First, we propose two protocols with different objective models to minimize the energy expenditures. Then, considering the different energy levels of network entities, we inject heterogeneity-aware heuristics into these protocols to maintain well balanced energy consumption. Thus, we develop two more protocols to maximize the stability periods, viz., to prolong the time interval before the death of the first virtual object in each task group. We extensively evaluate the proposed protocols using different measurements and benchmarking parameters and compare them with the most relevant algorithm in the literature. The results show that the proposed protocols are superior to existing work in the literature in terms of both total energy consumption and stability. (C) 2018 Elsevier B.V. All rights reserved.