I watched a TV documentary about insomnia years ago, and one of the things was how much our minds influence our sleep, eg. if we think we are not going to sleep, then we don't, and they did some tests to prove this.
I have to actively stop myself being negative if I can't get off to sleep, or if I wake up in the night. If I start thinking "Oh God, look at the time. I'll never get back to sleep", then I'm doomed.
I read somewhere that it's good to have a "sleep story" to tell yourself, so I launch into my sleep story and find that 80% of the time I can get back off to sleep. Sometimes I also do some mental Qi Gong and visualise myself going through one of the "exercises" and this works too.
But having said that, since March with all the stress of living alone and shielding during lockdown, I don't feel up to risking a sleepless night and the subsequent after-effects, so I take Valerian drops and either Phenergan or Zopiclone before bed every night. I try to follow the same sleep regime - supper, close up, bed with a book and the cat, lights off at the same time.