The Internet of things (IoT) enables a diverse set of applications such as distribution automation, smart cities, wireless sensor networks, and advanced metering infrastructure (AMI). In smart grids (SGs), quality of service (QoS) and AMI traffic management need to be considered in the design of efficient AMI architectures. In this article, we propose a QoS-aware machine-learning-based framework for AMI applications in smart grids. Our proposed framework comprises a three-tier hierarchical architecture for AMI applications, a machine-learning-based hierarchical clustering approach, and a priority-based scheduling technique to ensure QoS in AMI applications in smart grids. We introduce a three-tier hierarchical architecture for AMI applications in smart grids to take advantage of IoT communication technologies and the cloud infrastructure. In this architecture, smart meters are deployed over a georeferenced area where the control center has remote access over the Internet to these network devices. More specifically, these devices can be digitally controlled and monitored using simple web interfaces such as REST APIs. We modify the existing K-means algorithm to construct a hierarchical clustering topology that employs Wi-SUN technology for bi-directional communication between smart meters and data concentrators. Further, we develop a queuing model in which different priorities are assigned to each item of the critical and normal AMI traffic based on its latency and packet size. The critical AMI traffic is scheduled first using priority-based scheduling while the normal traffic is scheduled with a first-in–first-out scheduling scheme to ensure the QoS requirements of both traffic classes in the smart grid network. The numerical results demonstrate that the target coverage and connectivity requirements of all smart meters are fulfilled with the least number of data concentrators in the design. Additionally, the numerical results show that the architectural cost is reduced, and the bottleneck problem of the data concentrator is eliminated. Furthermore, the performance of the proposed framework is evaluated and validated on the CloudSim simulator. The simulation results of our proposed framework show efficient performance in terms of CPU utilization compared to a traditional framework that uses single-hop communication from smart meters to data concentrators with a first-in–first-out scheduling scheme.