Tsunamis are destructive natural disasters that can cause severe damage to property and the loss of many lives. To mitigate the damage and casualties, tsunami warning systems are implemented in coastal areas, especially in locations with high seismic activity. This study presents a method to identify the placement of near-shore detection sensors by minimizing the tsunami detection time, obtained by solving the two-dimensional shallow water equations (SWE). Several benchmark tests were done to establish the robustness of the SWE model, which is solved using a staggered finite volume method. The optimization problem is solved using particle swarm optimization (PSO). The proposed method is applied to different test problems. As an application, the method is used to find the optimal location of a detection sensor using data from the 2018 Palu tsunami. Our findings show that detection time can be significantly reduced through the strategic placement of tsunami sensors.