After looking in vain for a setting or third party app to give me reminders so that I hit my 250 steps during my goal hours, I've hacked together various pieces to send myself SMS alerts for free. Yes, I tried fitminder.io, but his implementation uses Fitbit's notion of active time, which lead me to more than a few gray dots on my dashboard.
For those interested in implementing this, you'll need:
- A google account (my particular implementation uses a Google Sheet and Google Apps Scripting)
- A Fitbit Developer account
- My script, found here.
- A little time (and some javascript understanding) for fine tuning if my settings don't suit you
Before I dive any further in, credit where credit is due, I started with Simon Bromberg's intraday code located in his github account here, and, in fact, I'll be heavily plagiarising his readme instructions in my own instruction set. Also, he has a nice UI and additional menu to configure his script.... Yeah, I didn't do that. modifying anything I've added will require working with the code, sorry. Finally, several chunks of Simon's code are superfluous to my goal... but I did not take the time to clean them up and remove them... If you're professional and/or very OCD about code, feel free to clean it up. I just ask that you share the result back with the community.
With no further delay, implementation instructions:
- Create a new Google spreadsheet, click Tools > Script editor... then copy and paste the contents of the pastebin file (see above) into the script editor and save. Return to the spreadsheet and refresh the page (Note: actually click the refresh button or select it from the menu; the keyboard shortcut is overriden on Google Sheets, at least in Google Chrome). A couple seconds after the page reloads you should see a "Fitbit" menu at the top.
- Add the Oauth2 Google Script library to your project by clicking Resources > Libraries... (menus inside the script editor). Then search for the OAuth2.0 library by typing in the project key "MswhXl8fVhTFUH_Q3UOJbXvxhMjh3Sh48" and hitting Select. More info on that library on its Github page. Select the latest version and click Save.
- Find your project's key by clicking on the 'Fitbit' menu inside your spreadsheet and clicking 'Setup'. A popup window may appear asking you to Authorize your application. Click 'Continue', sign into / select the Google account you want to authorize the application on (doesn't really matter which account, this has nothing to do with your Fitbit account). Then it will show you the permissions the application is requesting, click 'Allow'. Then the 'Setup Fitbit Download' panel should appear. Copy the text adjacent to 'Project Key' in the popup. You will need that in subsequent steps.
Go to https://dev.fitbit.com/apps and log in. If you haven't already, register a new app by clicking at the top right.
- For OAuth 2.0 Application Type select 'Personal' [the personal option gives you access to your own intraday (minute to minute) data. This doesn't work without that!].
- Default access type Read only.
Other fields at top: Application Name, Description, Application Website, Organization, Organization Website put whatever you want, just need to put something.
Add the following inside the callback url box:
https://script.google.com/macros/d/YOUR_PROJECT_KEY/usercallback
(Replace YOUR_PROJECT_KEY with the project key you got from step 3).
Agree to the terms, and tap register. Then you will be directed to a page with credentials. Keep your 'OAuth 2.0 Client ID' and your 'Client Secret' keys handy.
- Inside your spreadsheet (not the script editor), select 'Setup' from the 'Fitbit' menu (refresh if the Fitbit menu isn't visible at the top). In the appropriate fields in the 'Setup Fitbit Download' panel copy in your 'OAuth 2.0 Client ID', 'Client Secret' from the previous step, and your project key from step 3. Then click 'Save Setup' and the panel will disappear. Note: you can put whatever you like in the start/ end dates... my script ignores these fields entirely.
- In your spreadsheet, click 'Authorize' from the Fitbit menu and a sidebar will show up on the right. Click the word 'Authorize' in the sidebar. A page will open up with the Fitbit login page. Log in to the Fitbit account you would like to download data from in the new window, authorize the application by clicking 'Allow', and then close the tab when it says "Success you can close this tab".
- Set target number of steps, time range, and allowed notification hours. As written, the script checks for 125 steps in the last 30 minutes, and is allowed to send me notifications from 7 AM to 8 PM. Change the target steps on line 40, timeframe on line 38 and start and stop times on 44 and 46 respectively.
- Set notification target. The script sends notification via email. Set this email address on line 413. I have set mine to send the email to an SMS gateway so that I receive my notifications via SMS. A quick google search should turn up how to accomplish the same for your provider. In case you, as I, want to use a Google Voice number as your notified email address, follow the directions found here.
- Set script to run on a timer. On your script editor page, Click the 'Resources' menu and choose 'Current project's triggers'. Click the 'Add a new trigger' link. Choose 'refreshTimeSeries' in the Run dropdown. Under Events choose 'Time-driven' and then choose how frequently you want it to run. I have mine set to run every 15 minutes.
Congrats, you should now start receiving idle alerts based on your Fitbit activity!!
A few parting thoughts:
- Yes, this is VERY hack-y. I would much rather receive a notification from the app on my phone. However, Fitbit corporate wants to handle alerts via band vibration, which requires a firmware update. As such, who knows if or when previous devices will ever get this functionality.
- I'm going to guess that like me, you often have times were your Fitbit doesn't background sync to the app properly. This WILL lead to nags when they may not be appropriate... see #1. In my case, it at least leads me to check the app and sync to see where I actually stand.
- Many features could be added to this, and all of my configurable variables COULD be added into the setup menu.... I'm going to take the tack of a typical FOSS dev here, and say WorksForMe™ and YouHaveTheSource™. In seriousness, I probably won't do much more to this, as it's basically doing what I want now. I did want to get it out to the community, based on the desire for such a feature. Please feel free to build upon this. I stood on the shoulder of giants to get it to its current height.