The need for energy saving and environmental adaptation, has made governments and electric power industries around the world to turn their existing power grids into smart grids. Meanwhile, telecommunication networks play an important role in converting current networks into smart grids. The Wireless Sensor Networks (WSNs) include a large number of low-cost, small, and multi-functional sensor nodes that communicate wirelessly. WSNs are considered as a powerful technology for various applications of the smart grids for reasons such as the ability to run in specific environments, fault tolerance, lower power consumption, automated configuration, rapid development, and low cost. Despite the above advantages, the WSNs face the critical limitation of data transmission latency due to the low connectivity in dense environments. The main goal of this research is to figure out and present methods of media access with the ability to distinguish, prioritize and dela, for wireless sensor networks in smart grids. This goal is achieved by presenting a priority and delay aware method in order to improve the network reliability by dynamic adjustment of the media access control parameters in WSNs. The media access control parameters are the number of back offs, exponent back off, number of retransmissions, and contention window that are optimally adjusted according to the changes in clear channel assessment. In the proposed method, the particle swarm optimization method is exploited to determine appropriate values for the media access parameters.