How does a Venus fly trap know when to spring the trap? If you look at this video, you'll see that the trap only closes when the prey has meandered towards the middle of the trap. The plant knows that its prey has (1) reached the middle, and (2) is big enough to eat because it feels the insect. The large black hairs on the lobes of the trap are mechno-sensitive triggers that tell the plant that they've been touched, much like the hairs on your arm let you know when a fly has landed. To close, at least two of the trap's hairs have to be touched within about 20 seconds. A small bug can't touch two hairs that quickly, but a large one can. Once the bug (or small animal) touches two hairs, an electric signal, very similar to signals in our own nerves, initiates the trap closing.
Chapter 3 of WHAT A PLANT KNOWS is entitled "What a Plant Feels", and provides many more details on how the Venus flytrap and other plants feel their environment.