Lastly, be absolutely certain that door is locked.
Well, that's the secret, isn't it? When I was a teenager (a bit off-topic) my parents didn't like me to lock my bedroom door. Mom would barge in without knocking, her motherly privilege, I presumed, and that caused some embarrassing incidents. Curiously my Dad never did that, always knocked first. I guess men just understand these things.
Just as bad was that after I had cum, as a kid I would pass out almost instantly with the relaxation & release I would feel. My Mom walked in a few times, making me startle back awake, but in time to see me sprawled out on the bed, pants to my knees, my soft dick still in my hand. Oh, well...
But as for not being able to wank when sleeping in a different place, my problems were a college dorm, and later enlisted barracks in the Army.
My college roommate was always coming in without warning the first 2 weeks of the new semester, until I learned his schedule. Our room doors couldn't be locked. I had to be celibate 2 whole weeks, and when I finally managed the feat I almost drowned in my own cum, I think the greatest amount in my life until my first gay sex many years later.
The Army enlisted barracks while in training were impossible. I tried jerking on my side under the sheets, but that didn't work well, with the flat bunk bed springs squeaking. Guys sleeping right next to me ruined my focus.
Until one night I woke up around 3 AM to go pee, and ended up jerking off into a urinal while standing, first time I ever did that (nor had to). Also first time in nearly 3 weeks, I was really getting desperate. Later on I was able to wank sitting down in a closed toilet stall, even with guys coming into the latrine. I wondered how many other guys were also doing that.
Something I couldn't do initially, until we were relocated into modern barracks that didn't have commodes without dividing partitions, all of us previously just sitting out in an open latrine, wiping our asses in full view next to each other. Basic Training 45 years ago was very... "basic". Our training Sergeants assured us it was preparing us for combat field living conditions.