The answer is yes. If your mind can send you into panic mode then you can also train your brain to send yourself into relaxation mode. This is one of the main ideas behind CBT (cognitive-behavioral therapy).
The other day I was thinking about my last job and how I never said a proper goodbye to my coworkers because I left suddenly due to the panic and thinking I had a heart condition, etc. In my mind I was back at work saying goodbye, trying to explain why I was away for so long with people dismissing anxiety and panic as "no big deal", hugging coworkers, visiting different departments, etc. My mind couldn't tell the difference between where I really was (home) and where I was imagining myself to be. I had the same thought... if my mind can scare me into an attack thinking that I was really at work, then I can do the same to relax myself. As the attack started I kept my eyes open, looked around, and reminded myself "You're at home, you're in a safe place, you're not at the office, there are no threats, no dangers...." The attack was MUCH shorter time-wise than usual. So yes, you can train your brain to stop having these "false alarms"
The nighttime attacks thing may be something different though. In your case it sounds like you may have a recurring dream in which case you may want to try to analyze what it means, if you believe dreams have meaning. Are there any trust issues between you and your friend or husband? Are you afraid that your husband might not feel the same way about you as you do about him? Do you feel like you're a burden on him for having anxiety? That kind of thing.
Other people (myself included) will wake up in the middle of the night in the middle of a full-blown panic attack. I used to look forward to sleep because I thought of it as being the one time, the one moment when I wasn't anxious. Only when I'm asleep could I find peace. Then I started waking up in the middle of an attack. I recently read something that talks about how before you go to bed you may be worrying about stuff and causing yourself anxiety. As a result of these thoughts your muscles tense up. This is an automatic self-protective function; like you're getting ready to defend yourself. When you fall asleep your muscles instantly relax. But your mind and body think "crap, I can't relax... I need to be on guard and alert". This sets off fear in your mind which leads to the panic attack, which in turn wakes you up. According to what I read it usually happens shortly after falling asleep. But in my experience it's been usually in the middle of the night.
Hope that helps and I wish you the best!!