I've worked from home for the last 11 years.
Prior to that, I've also been working from home - but not for an employer - for school.
When I made the jump to become a freelancer in 2008, it wasn't a hard shift. I was used to study all alone.
Before going on, I suggest doing one thing. Take this personality type test and see what that site tells you.
I'm an introvert, I am independent and I like doing things alone.
This post is heavily influenced by this fact, and you might find that what I say is madness if you're an extrovert who needs people around to be productive.
The first suggestion I have for you is to have a dedicated office space. It does not need to be in another building, but it might be necessary if you have lots of people in your house. I do have a dedicated room, with a door I can close. It's very helpful because it avoids.. interruptions.
There's something impossible to stop in the world, and it's interruptions. But as creative workers or developers we need to go in the zone and do deep work as much as we can.
Try to minimize interruptions as much as you can. Have fixed times where have "at work" time. Remind everyone you are working when you close your office door. It's like you're 50 miles away when the door is closed. Minimize interruptions from coworkers, too.
But when interruptions come from within you, they are called distractions. Use apps like SelfControl to stop all possible distractions. Turn your phone down.
Some people work better with schedules. Some like using the Pomodoro technique to set timers. I can't do that, for some reason it does not work after the first 2-3 pomodori.
I am lucky enough to work by myself, without a team I need to report to. I did work with teams in the past, however. My general recommendation is to find (if possible) a team that's all remote. Avoid job situations where you are the only person remote (unless you are a freelancer). Over the long haul it's stressful and demotivating.
With remote teams it's become normal to have a chat open all day, but I never liked the chit-chat happening and the stress coming from people mentioning you while you are away from work.
Remove all notifications, close the chat when you are doing important work. Chats can happen.
Same for emails. Close your email client, and remove work emails from the phone.
Some people like having a routine. I worked on teams where I was expected to have some kind of hours, but as a very independent-minded person I really disliked that. I like to work when I'm the most ready for it. But I know many people need fixed hours, or they get lost. You know yourself best, pick what suits you.
What about social interactions? Have a hobby. I am involved with some sports and I do a lot of hiking, with friends too. Also, having non-tech friends is a great refresher at times. But thanks to my personality type I can spend days without a lot of social interactions with people. Get a dog. It's a great way for casual chit chat with people. Or new friendships, too. Some people like going to meetups or conferences. I don't. Twitter and YouTube provide me the professional network I can learn from, without having to move to a city.
Find a sport. It's really important. As mentioned it can also help with social interactions, and if you sit all day, it's mandatory to get up at some point and do something.