I've got some good news for you. There is nothing wrong with your child's listening skills and he feels safe in your home environment.
Given how there are no problems in school and how he's able to do the exact opposite of what you're asking of him you can be sure he fully understood what you asked but chooses not to do it.
What is happening here is that he's experimenting with his boundaries. He has these interesting questions like "What happens if I don't do what they ask of me? Can I get away with more things if I ignore my parents? Can I decide things for myself? ...". There is also ofcourse just the natural curiosity of learning new things. How can a child know why it is dangerous to jump head first down a chair for example? Maybe you're just saying no because you don't enjoy doing it yourself right?
The most important thing to keep in mind here is to be consistent in what the rules are. Things like never running around with scissors, what the maximum screen time is in your house, what to do to prepare for dinner/lunch, no jumping on the sofa, getting 1 cookie at around 4 O'clock, ...
Once they internalise those rules you probably don't need anymore than a stern look to get him to comply again. If however you sometimes give in and break the rules, they immediately learn that they should nag you more next time in hopes of you breaking those rules again in their favor.
If he actively tries to go against what you are asking you can show him a child-apropriate concequence. This highly depends on the situation but the usual way to handle "you NEED to do what I ask for this thing" is to put them in time-out if they don't. Forcibly (without causing physical harm ofcourse) put them into a designated corner of the room/hallway/bathroom/... and don't let them out until they show they understood what you ask of them and then comply with it.
There are also a lot of situations where a child needs to be able to experiment in a somewhat "controlled dangerous" environment. Which encourages them to think for themself whether or not something new is a good idea or not. With my 2 year old, we explicitely tell him not to stand on our couch, but will only forcibly set him down if he starts running around on it. If after a warning he falls off and somewhat hurts himself (we do prevent him falling from too high or towards a table for example) then I just respond with "I told you not to stand on the couch" while hugging him and letting him cry for a bit. This way he quickly learns that it's typically a smart idea to listen to us and that he probably should not walk around on the couch (though obviously he is going to try again to learn how to balance himself better to solve the issue rather than not standing on our couch ...).
I personally also use a highly different stern-ness for things my son really needs to listen to immediatly and things he might try to act up on (but is still not permitted to do). Consider the difference between "oh no, don't tickle me!" which encourages him to try to tickle me and "NO! That pan is really hot! you'll burn yourself" while pulling away his hand. In the latter case he'll at least approach the pan way more carefully if he does try to see if it's the pan he shouldn't be touching (and a more gentle pulling his hand away with "the pan is hot, no touching" to make the rule clear).
One more thing to keep in mind is how much attention your boy gets from you. There is always the possibility that he just wants to get any reaction out of you, and if you don't want to give him possitive attention then at least he'll force you to give negative attention instead. If you suspect this to be the case, try to give as little attention to his negative behaviour as possible and try to encourage more possitive behaviour using attention as a reward. "If only you would put your shoes and jacket on quickly, then we would have a little more time to jump around and picking you up outside. If you keep dawdling we'll have to leave without all that fun." Obviously you should actually throw him around for a bit if he does listen right away after saying something like that. And ofcourse try to make some more time to play with them (this is really draining to do, I know, but at least more fun than dealing with their cry for negative attention instead)
Besides everything above there is one really important thing to consider that almost everyone does wrong. When your child isn't listening, did you ask him to do something or not to do something?
This actually makes a huge difference in a lot of situations. For example if you tell him "don't stand on the chair" they'll usually blank out for a second and then continue to try to stand on the chair because they didn't really have a fun alternative to consider. If instead you tell him "a chair is meant to sit on. So sit down" they are more likely (though no guarantees here) to comply and sit down on the chair (at least for a little while).
A trick that helped me to word things better for small children is to imagine them responding with "then what should I do?" after anything I asked. If there is an answer to it (play with something else, sit down, color on the paper instead of the table) then that answer should have been included in the question/command.
Once you fully understand this difference between telling them what to do instead of what not to do there are surprisingly little situations where you actually can only say what not to do (like "don't touch hot things").