@Rory's got some excellent ideas, and I'd like to add a more theoretical / esoteric spin based on my experience. It may help you frame WHY you're not motivated.
After working at an office my whole life, I went freelance in 1999. I had the exact same problems you did. The change of clothes wore off after a while, so did my dedicated home office. Then I ran across the idea of the Third Place. Having a background in mythology and symbolism, I'm always intrigued by threes. Three points define a plane; a stable, even surface. For me, that represents balance. The third place is essential to balance with work & home.
Working in an office, you have your home, you have the office, and you have (usually) another space that you frequent to socialize. A favorite restaurant, coffehouse, bar, gym, store, mall, etc. However, working at home, two of your three spaces are the same. Imbalance. This, I postulate, is why you're successful at the library.
Eventually, I decided to work from a neighborhood coffeeshop a couple times a week. These were usually centered around client meetings instead of my visiting their sites. Even two half-days a week out of the home office really helped me be more productive when I got back to it. Having that third space really helped me stay motivated about the work, and in retrospect, it wasn't that I was unmotivated to work, but I was unmotivated to be in the same HOUSE, sometimes for days on end! It's as if cabin fever was preventing me from focusing on the work to be done.
Taking a break from my home office and keeping my mind on "balance" really helped me overcome what you're going through right now. Perhaps it can help you, too! Good luck!