This has happened to me a number of times. I'm not entirely sure what causes it, but I think you're hovering between waking and sleeping, at least that's how it feels to me.