The other things that are not habits
Restless legs. Unpleasant sensations in the legs in the evening with a strong urge to move them, better when you move and worse when you are still. It has its own treatment and it is sometimes as simple as a blood test.
A body clock problem. You cannot get off before three or four whatever you do, but you sleep perfectly well once you do. That is not insomnia and the treatment is different, built around light timing rather than around habits.
Medication. If your sleep changed when a prescription changed, tell whoever prescribed it. Do not stop anything to test the theory.
Acting out dreams, walking, or shouting in your sleep. That gets looked at, and for some people it matters more than it sounds.
And low mood, loss of interest or hopelessness alongside the bad nights, in which case the sleep may be a symptom rather than the problem, and the course you want first is the one on depression.