For me, it boils down to 3 things. Pre-planning, habits and elimination. I have written about each separately on my blog http://www.new2code.com/2016/06/deep-work/
I plan a lot of stuff on my Google Calendar. My whole days are planned in advance including free time. When I am learning a new language, I set aside time for study. If a friend asks me to hang out, I can just check to see if I have prior commitments. I also have the regular gym slot and after 2+ years, I am simply routine when it comes to exercising.
Next, learn how to build habits and routines. This saves a ton brain power. There is a great video on habit building
http://www.youtube.com/watch?v=AdKUJxjn-R8
Also, check out a book by Charles Duhigg called The Power of Habit.
Finally, cut out the news and as much information as possible. Not watching the news added a ton of happiness to my life. This also cuts out distractions. Check out something called the Low Information Diet which goes into more detail as well as a book called Deep Work by Cal Newport
I also wrote a guest post on the blog Simple Programmer that goes into more detail on the willpower.motivation side of things https://simpleprogrammer.com/2016/09/07/limited-willpower/
I hope that helps. Largely I don't believe in long-term motivation, it is more to do with becoming routine.