I'm not sure exactly how they know, especially in an indoor environment. It MUST be something to do with water pressure, though, or at least air pressure on the water.
I do know, however, that, before the spring rains in Thailand, the water gets a little old. Then spring comes, and it begins to rain and rain and rain. All kinds of new food comes in, and the abundance of fresh, slightly cooler water stimulates spawning. The lightning does excite them. It's storming hard outside right now, and the Bettas jump at the thunder, and then immediately start working hard on their nests.
These are their natural cues for spawning, because it signifies that there will be plenty of food and plenty of fresh water to ensure that their young survive.