So in this scenario what I do working from home is spend a lot of the work day that day doing my laundry or whatnot. Then after 5 PM no one will be interrupting me so I then look at the code. I probably do this at least one day every week. Maybe I shift the schedule around - I work Tuesday night and do my laundry Wednesday afternoon. This is a scenario where the interruption is fully external.
If I am not being interrupted...some things I sometimes have to kick myself to do at first, but then I can go for an hour or more. This would include going to the gym, or, I don't know, studying what a monad is. I just have to determine I'll start doing, but once I am doing it I am not distracted.
The last thing that I have to kick myself doing even while doing it. I sometimes had to do this in college - I had to do a lot of studying for something which was not my major, which I did not care much about etc., and it was purely to pass the class and get a grade. Actually these things used to get a lot of other things on my things to do list done - I'd say, I will clean the living room tonight, not study Lewis structures or whatever. There's not much solution to this other than just kicking yourself back to the task.
While things being as they currently are we always have to kick ourselves a little to do some things the whole way through. At some level it becomes psychologically untenable and you just have to face the fact that you don't enjoy doing whatever. For example - at college I enjoyed most of my Computer Science classes, reading the material, doing the homework etc. I even enjoyed some of the books we'd be assigned in English classes and that sort of thing. Some classes I did not care about, and had to kick myself to study. But that is normal. However, if I was not interested in computer science and had to kick myself to study everything, it becomes more untenable. It's not going to work psychologically or in general. Although in retrospect, some things I didn't realize the use of until later. Like my graph theory class I generally found boring, but then my next class was a data structure class where I made use of nodes and trees and graphs, and the graph theory came in handy.
Also - as some other people here said - wake up after a good sleep, shower, have a clean environment around you, eat decent foods, get a good deal of cardiovascular exercise etc. Take at least one day a week to just relax.