Moisture can be detected because of the varying resistance between the unconnected ends of two wires. If moisture is present, the resistance between the ends of the wires will fall. The circuit is shown below
Suppose there is moisture present, then the resistance between X and Y will fall. The resistance between the emitter and bas will rise therefore, and if it rises above 0.6V current will flow between base and emitter and transitor will switch on. The bulb will then light.
The circuit can be used to turn on at a certain moisture level and to detect liquids, or detect when liquid has reached a certain level. by varying the resistance R.