It was a DILD.

Maintaining lucidity is a skill you must learn and develop for yourself, over time. There are a lot techniques that can help, but you need to find something that works well for you.

Some techniques you may want to try include the classics: spinning, rubbing your hands together, and feeling objects in your environment.

A multitude of things could have caused you to wake up. It's hard to say exactly what it was without more detail.