Full details here, but in summary: Take 2mg of melatonin 20 minutes before bed, and train yourself to think only of boring things and/or nothing after you lie down. Falling asleep becomes MUCH easier and more predictable.
1.5 mg seems to work for me, but I can't really tell because I stopped drinking coffee at the same time. I'll stop the melatonin and see if I really need it.
Thus spake Eliezer:
It seems that many here might have outlandish ideas for ways of improving our lives. For instance, a recent post advocated installing really bright lights as a way to boost alertness and productivity. We should not adopt such hacks into our dogma until we're pretty sure they work; however, one way of knowing whether a crazy idea works is to try implementing it, and you may have more ideas than you're planning to implement.
So: please post all such lifehack ideas! Even if you haven't tried them, even if they seem unlikely to work. Post them separately, unless some other way would be more appropriate. If you've tried some idea and it hasn't worked, it would be useful to post that too.