Sustainable cities are widely adopting the standards of the Internet of Things (IoT) in almost every domain, e.g., smart grids (SG) to provide services to a sustainable community. It enables two-way communication to manage the energy resources, where routing protocol has a significant role in communication. The diversification of IoT networks arises many challenges for the routing protocol for low power and lossy networks (RPL). The dynamic and lossy environment is one of the key challenges in various IoT networks, specifically SG. RPL does not able to adjust its link metric efficiently against the dynamic and lossy environment, which have a great impact on the performance metrics. To address this issue, we have introduced cognition in RPL by integrating learning automata with the objective function (LA-OF). Learning automata (LA) is applied to expected transmission count (ETX) to tune it according to the environment. LA learns through interacting with the environment and yields the best ETX values, afterwards the environment is monitored to trace down the instability in the environment. The proposed LA-OF is compared with standardized techniques MRHOF and OF0. The simulation results show a significant improvement with overall 7.04% in PRR, 17.52% in energy consumption, and 18.72% in overhead.