Smart grid is an intelligent power generation, distribution and control system. ZigBee, as wireless mesh networking scheme low in cost, power, data rate, and complexity, is ideal for smart grid applications. Unfortunately, almost all ZigBee channels are overlapped with wireless local area networks (WLAN) based on 802.11 specifications, resulting in significant service degradations in interference scenarios. We propose a frequency agility-based interference avoidance algorithm, which utilizes Energy Detection (ED) and active scan to perform smart channel selection. This algorithm can detect interference and adaptively switch nodes to "safe" channels to dynamically avoid WLAN interference. Our proposed scheme was empirically evaluated in terms of the packet error rate (PER) using a ZigBee and Wifi coexistence testbed, and the results were compared with our analytical results. The measurement results show the algorithm efficiently mitigates the effect of WiFi interference upon ZigBee networks.