You have to be honest about the best way to motivate yourself. In the speech "You and your Research," Richard Hamming[1] talks about how he uses his ego against himself. When he went on sabbatical to write a book, he told everyone he was going to finish by the time he got back. He wouldn't dare suffer the embarrassment of failing to finish!
Me? I respond well to A. small, well-defined tasks and B. limits. I get A. by breaking tasks up into tiny modules, and by using Git to make lots of small feature branches. I also write TODO lists with lots of 30-minute jobs.
I get B. by using LeechBlock[2] to restrict access to websites for periods of 1 hour. When I combine A. and B., I usually can find something that'll put me working long enough to get into the zone.
Having an interest in your projects also helps :)
[1] http://www.cs.virginia.edu/~robins/YouAndYourResearch.html