NOTE: From my experimentation, every sync tends to cause my Mi Fit app on my phone to momentarily disconnect from my band and sometimes causes the app to stop running in the background. So be aware of that and use this script at your own risk.
This requires you to have a google account linked to your Mi Fit App
In order to export your Mi Fit data to Google Sheets, you will first need to create a spreadsheet from Google Drive. Once you created your spreadsheet, go to Tools > Script Editor to open the Google Apps Script page.
This will open up the Google Apps Script IDE:
Name the project whatever you wish by clicking the "Untitled project" and add the Oauth2 library by doing the following:
Click the "+" button on Libraries in the sidebar
Add the following script ID for the OAuth2 library and choose the latest version
Before you can use the library, you must register your script in the API Console. To do this, go to console.cloud.google.com/apis and complete these steps:
Click on Select a project on the top bar then click on New project
Give a name to the project and click the CREATE button
Once the project is created, before you can create a client ID you will need to configure the consent screen:
- Click OAuth consent screen in the left sidebar
- For User Type check External and hit CREATE
- Fill out the App info with a name and email and click "Save and Continue"
Once the OAuth consent screen is click on Credentials in the side bar
Click CREATE CREDENTIALS at the top and click on OAuth client ID
For Application type choose "Web Application" and give it a name
Find your Script ID by going back to the google scripts editor under Project Settings in the left menu
Under Authorized redirect URIs, add this url replacing SCRIPT_ID with your script ID from the previous step and click CREATE:
Once you created the OAuth client, copy the following code below into code.gs in your script editor overwriting what was there and copy both the Client ID and Client Secret and paste them into the following code replacing YOUR_CLIENT_ID and
YOUR_CLIENT_SECRET on line 1 and 2 and on line 3 change the year to year you first synced data from your band:
Once you have done that, go back to your spreadsheet and reload it. You should now have an extra tab labeled "Mi Fit" at the top next to "Help".
To use the script you need to first click authorize and sign in to the Google account linked to your Mi Fit app.
The first time you attempt to authorize you will get this popup
Simply hit "Go to <project name>" to continue. Click Authorize again and a sidebar will pop up asking you to Sign with Google. Choose the google account you linked to your Mi fit App. Once it's logged in, click sync and you should have the your data.
The Spreadsheet will feature the following columnns and data:
- Walk or Run Distance
- Walk Speed
- Walk Average Heart Rate
- Sleep Duration (Total)
- Resting Heart Rate
- Sleep Duration separated by Sleep Stage
- PAI score
- Sleep Stress (Average of all stress measurements taken during sleep)*
- Average Stress of the day*
Morning Readiness (My attemp at mimicking the ways other HRV apps take 1 HRV measurements in the morning)*
*Must have All Day Stress tracking enabled
Top comments (5)
Thanks for sharing! I am looking to use this for a school project. Problem is, I am getting this error after trying to sync in google sheets:
TypeError: Cannot read property 'tp' of undefined
Do you have any idea how I can fix this?
I have followed the whole thing but I am getting a ReferenceError: OAuth2 is not definedDetails error and I am not sure where did I go wrong or the method is deprecated?
Hey, G Oh. While sync-ing the sheets I am getting the error:
TypeError: Cannot read property 'user_id' of undefined.
Kindly fix the problem for me.
Good day! For some reason the heart rate data doesn't show. Would you happen to have any idea why this is happening? Thanks!
Some comments may only be visible to logged-in visitors. Sign in to view all comments.