According to Coleridge’s Preface to Kubla Khan, the poem was composed one night after he experienced an opium influenced dream after reading a work describing the Tartar king Kublai Khan. Upon waking, he set about writing lines of poetry that came to him from the dream until he was interrupted by a person from Porlock. The poem could not be completed according to its original 200-300 line plan as the interruption caused him to forget the lines.
I think Coleridge was on laudanum, not sleepiness.
Laudanum or opium itself...
From Wikipedia: