Countermeasure for Drain Flys
I've read that pouring oil, such as vegetable oil, into a drain will put a film on top of the water in the trap and that this will dramatically slow the evaporation of the water. When you anticipate that water won't be run through a drain for a long period of time, you could preemptively add oil to that drain.

This might leave an objectionable ring around the inside of a toilet bowl, but for other drains, maybe it's worth a shot.