So, I have looked in to this. I even had a fitbit that i was hoping to use to determine if I fell asleep at night and turn off lights in my home automation system.
The down side I ran into is this. I had fitbit setup with ifttt since that was something it could interface with. The sleep detection worked. HOWEVER. It only actually posted info to IFTTT when you woke up, at that point, all sleep related data was submitted. So it didn't track it real time.
I have been looking in to how to integrate sleep in to my HA but also like you mentioned quality of sleep. The fitbit utilizes motion to determine "restless" sleep. Attaching a bunch of sensors to myself doesn't seem like it would yield comfortable natural sleep. So potentially stuff like a mesh of piezo sensors under a mattress topper would work. that would detect when the values change indicating turning, movement.
Temperature should be easy (fitbit probably does it, i had a cheap one so it did not).
If you want to get crazy (which if i had time i would go this route) you can get a fitness watch with a certain chip in it, and reprogram it.
That's what he did. This could be REALLY REALLY cool. You could code in your own parameters and what not, since it's bluetooth LE you could track it via phone or just remote sensors.
Once you have some basic "restless" night tracking you could do some experimenting (even with the fitbit).
- track your sleep for a week or 2 to get a baseline of how much time each night you sleep "restless"
- change thermostat temp up/down - track again and compare.
- monitor body temp and see if warmer/colder = restless. find sweet spot.
- integrate body temp monitor to HA system to control thermostat to keep you correct temp
If you make any progress, definitely let me know, i would be interested to see what you come up with!