Habit Dash allows you to connect various devices and export a CSV file for free. There is a lot of code on the backend to clean the data and also calculate other fields (such as sleep stage percents).
Disclosure: I’m the founder of this app. Right now the data is at the daily level only, but we’re adding intra-day data soon (such as workouts, heart rate, respiration, SpO2, etc.)