The best way I know is taking some time to do something fun and interesting away from screens, or at least away from screens as the focal point. For me during a stressful startup phase, this took me from working every day, evening, weekend save for an hour or two hike every two weeks to taking a hike or walk every day (before work and/or in the evening), even if just a few minutes. Eventually I went from burning time working inefficiently (& not caring how long anything took) to working more effectively and productively without having to uselessly burn so much time. I had a lot of interests in nature and hiking already though, so that helped, so my secondary advice is that whatever it is should have some exercise aspect to it but also be tied to an interest - exercise for the sake of exercise isn't generally too sustainable in the longer term (how many folks do you know with an unused gym membership?).
More specifically how I stayed motived to keep walking/moving was tying other interests to it. I've become pretty decent at wildlife photography (an hour a day for a few years and that'll happen), I made maps of all the local hiking trails on Google Maps and Open Street Maps, I learned to identify and find various wildlife species (birds, insects, wildflowers) and report rare ones found to those who are looking for them, I snowshoe in the winter and cycle during the other seasons as well. Now it's all normal enough to me I actually want to get my coding done efficiently and effectively as I don't think of myself having all kinds of time to fix issues later.
Some other ideas though, which can help keep you in good shape too:
I'm sure there's many other things that can be thought of... if you get bored with whatever you choose, go to something else immediately. Switch things up. Set goals. A daily goal is best otherwise it is easy to procrastinate (e.g., twice per week means a lot of "oh I'll do that tomorrow").