How do the molecules of one type 'know' there are less number of the same type on the other side of a semipermeable membrane? Does it have to do with the overall energy state of the system?
It's ultra simple: for molecules small enough to pass through, a given proportion of them on one side will pass through. Same "law" on each side. So, naturally, the most populated side (i.e., largest number of the given kind of molecule per unit volume) will invade more and thus win the balance of transfer.
Now, the density of a kind of molecule on one side also depends of how many competitors fight for the same space there. And if on one side lays molecules too large to pass through, there will be less room here for the small ones, and thus a smaller density of them. Which will mechanically settle an unbalance resulting as a (virtual) sucking of small molecules.
That why pure water injected in biologic tissues tends to explode the cells, while very salty water tend to dry them.
Osmosis is not water moving down a concentration gradient. Consider dextrose 5.4% Vs saline 0.9%. there is equilibrium but the water concentrations are quite different. Osmosis is an empirical law related to the gas laws. Vant Hoff did not understand it and he got the first novel chemistry prize for describing it.