As already mentioned, you need to take this to your confessor.
However, let’s see what we see in what you have written.
First of all, please review the section of the Catechism on
Mortal and Venial Sin.
Note the requirements for a sin to be Mortal - Grave matter, Full knowledge, and Full consent of the will.
So my question is this: I committed a grave sin while still sleepy–I had just woken up. I had thought that I committed a grave sin of thinking impure thoughts just before and that I was already in the state of mortal sin.
OK, so to start with you would not have been in a state of mortal sin at this point. Yes it is grave matter and you may even have been aware that it was grave matter, but in the sleep state one is unable to truly give full consent.
I had reasoned that the sin of impure thoughts was mortal before committing the second grave sin. While committing the second grave sin I had full knowledge and everything–I would definitely consider this a grave sin if I had been awake. Does the fact that I was sleepy/half-asleep at that time mitigate my consent, or was I even sleepy at the time judging from the fact that I had already reasoned out whether a previous sin was mortal?
Frankly, it is my opinion that this does meet the criteria in the Catechism for mortal sin. By your own admission you had already thought about the sinful nature and the gravity of the matter before committing the second act. This presence of mind indicates a control of the will.
There certainly may still be some mitigation here due to your sleepiness and as others have said, take it to your confessor and talk it over with him.
In the meantime, make a good, sincere, act of contrition.
May God Bless you on your Journey.
Peace
James