Giving up coffee completely, and tea after my breakfast cup, has been sparing me those hours of lying awake in the middle of the night. Writing alone can play some havoc with sleep though. The last book was especially weird ... I'd snap awake in character at 2am, and since those characters were actually disembodied spirits looking for their chance to reincarnate I had no idea at all where or who I was, or indeed for a while what a human body was. Then I'd get up and trot across to the writing studio for a couple of hours, writing whatever episode had been coming through. One night was especially wild (this was at home in Santa Fe), confronting a black bear in the darkness who had emerged from our woodland to tip over the trash cans in search of food.
Now I'm just waking early. 4.30am today. Moved my book on to the close of its chapter, penned down some ideas for what is to come, but really too out of it with lack of sleep to write well beyond that.