Unmanned aerial vehicle (UAV)-assisted wireless sensor network (WSN) data transmission is a hot topic of research in recent years. This article mainly focuses on the energy consumption optimization of WSN data transmission with the assistance of UAVs. First, we established a communication coverage model for UAV-WSN and derived the energy consumption of data transmission for UAV-WSN, determining the optimal number of cluster heads (CHs) under different UAV flight heights. Second, we built a model for the energy consumption of WSN data transmission and the UAV flight height, and determined the optimal flight height of the UAV, while also dividing the UAV task area into segments. Then, we proposed a model that dynamically optimized the UAV data collection position according to the CH location, which can further reduce the energy consumption of CHs during data transmission. Finally, we used simulation experiments to verify the feasibility and effectiveness of our proposed scheme.