Wow, a tough question and one that still eludes me.
First of all, thank you for your honesty.
Second, I have a strange idea that is in the literature about addiction and was suggested to me, eat chocolate when you want to act out. It has some chemical affect that works similarly (not a full proof option and certainly if you are getting into bed naked its going to be much more difficult.)
There is a line I've heard many times from my sponsor and others: God is soooo strong that even if I walk into a bar, pour a drink, lift it to my lips and tilt the glass, He can knock it out of my hands ---- but historically, He doesn't!
I need to put myself in my right mind at night. I check in with someone before I go to sleep and talk explicitly about my intentions. I walk the "tape" through to the end and imagine cleaning up that mess (yuch) I try some relaxation techniques (meditation) to get out of "that" zone. And before I go to sleep I daven to Hashem, in my own words, and ask Him to help me stay clean for one more night.
Hope some of this helps.