I believe and I am not pointing fingers at you @GoldenTiger. For a lot of people habits are crutches borne out of laziness and instant gratification. We can spend months, sometimes years ingraining a new habit. Then suddenly we experience a moment of relapse we loose focus and we are back to our old habits. Hence the old saying old habits die hard.
When you are at a mental or physiological low I believe we loose sight of our goals and revert back to our old bad habits. I have had similar experiences due to the abuse I have to deal with from the past.
I think the question you might have to ask yourself is what is causing you to have these moments of loosing focus. Is it personality what i mean by this is lack of will power ?. Is it addictive ? something to do with drugs, alcohol ?.
The biggest killer is the environment well it was for me. For example if you are an alcoholic and want to give up drinking. You need to disconnect form friends who you go out drinking with ?. Are you feeling lonely ? if so it might mean you have to rid yourself of all those things that keep you at home like netflix, youtube, porn etc.
The examples i give might be extreme but I am just trying to clarify my take on what I believe might be causing this.