How can I avoid peeing at night?

The only way I don’t pee at night is by not consuming liquids for 5 hours before going to bed.

In practice this is extremely difficult and leaves me dizzy, a headache and very thirsty by the time I go to bed, so I don’t do it anymore.

If I do pee, it’s often a while before falling back asleep, such as 1 hour on average. I pee once or twice a night.

Are there any tips and tricks to avoid peeing at night?