Magnesium is a great supplement in general. You can definitely have too much in your system and that is undesirable, but a bit before bed time along with 1-3mcg of melatonin work well for me. It is nice after workouts. I use magnesium glycinate in powder form, which is more bioavailable than some forms as well.
I also find sauna before bed is good. I have a bed chiller so I can crank up the sauna before bed and not sweat a lot. Generally if I sauna and take the aforementioned supplements I sleep well. Exercise also seems to help me out a lot. If I exercise during the day, and a 4-5 times that week in general, I tend to sleep well.
Your report matches my experience as well!
Funny how it's basically do all the things you're supposed to do - exercise, diet, stress management - then sleep is then easier.
Mg or melatonin have 0 effects on me, Mg helps if I over-exercise but thats for muscles regeneration.
I dont have problems normally, just cant sleep in high altitude, 3000m is already showing mild effects. Guess what, I do/did quite a bit of mountaineering, its easy to get above 5000m in himalayas, highest I've been in tent attempting to sleep before summit push was 6000m on Aconcagua. Tried both Mg and melatonin up there over multiple nights, 0 improvements. I had highest O2 blood level measured in 5500m by doctor (mandatory there) from whole group.
Physical effort makes better sleep for literally everybody, thats age old knowledge and I havent met a single exception yet.
Sauna and then a lukewarm shower to cool down is also great.