I suck at it, so I have to trick myself into working. Setting a timer is a huge help. 20-30 minutes is my sweet spot. Sometimes I'll get on a roll and keep going after the timer goes off. If not, I'll break for 5 or 10, take the dog out, get more tea, then set the timer again.
I also have daily and weekly goals to meet. (for me daily = 5 day work week) More importantly, I set quarterly goals for big projects.
One of my writing groups has an online chat platform and I often do sprints with other writers, which is HUGELY motivating, because I want to have more words than they do at the end of the sprint. LOL