\begin{align*}&\text{To find the time when both lights turn on simultaneously again, we need to calculate the least common multiple (LCM) of 5 and 8.} \\&\text{Prime factorization of 5:} \\&5 = 5^1 \\&\text{Prime factorization of 8:} \\&8 = 2^3 \\&\text{The LCM is found by taking the highest power of each prime that appears:} \\&\text{LCM}(5, 8) = 2^3 \times 5^1 = 8 \times 5 = 40 \\&\text{Thus, the number of seconds before both lights turn on simultaneously again is} \\&\boxed{40 \text{ seconds}} \\\end{align*}