Fitbit / Google Fit sync on a Synology NAS

Fitbit and Google Fit logos

Fitbit does not natively integrate with Google Fit on Android.  However Prevaeen Kumar Pendyala has developed an excellent open source Python based utility to perform the data synchronisation.

You can read more about his utility here:
https://pkp.io/blog/fitbit-to-googlefit-sync/

And download the code, and access his installation instructions here:
https://github.com/praveendath92/fitbit-googlefit

The code will work on any computer, and detailed instructions/video are provided for installing on Windows, MAC or Linux.  The purpose of these instructions is assist with deploying on a Synology NAS.  The benefit of using your NAS is you don't have to remember to turn on your computer.

The first step is to login to the web page of your NAS.  The screenshots provided are from DSM 6.1.

Open the Package Center, and install Python3:

Login to your NAS using the command line interface using ssh (preferred) or telnet.  If you haven't already done so, you will need to enable terminal services in the Control Panel:
Note that only users in the administrators group can access the command line interface.

Go to the utility GitHub repository: https://github.com/praveendath92/fitbit-googlefit
And copy the Download ZIP URL:

Download the latest file to your NAS:
> wget https://github.com/praveendath92/fitbit-googlefit/archive/master.zip
...
2017-10-22 23:10:16 (197 KB/s) - 'master.zip' saved [126988]
Extract the archive, and update file paths.  Note I've installed it under my home directory ~/fitbit, alter this path as required.
> 7z x master.zip
...
Everything is Ok

Folders: 3
Files: 15
Size:       224955
Compressed: 126988

> rm master.zip

> mv fitbit-googlefit-master/ fitbit

> cd fitbit
Download the python script for installing PIP. This is a package installer that can install packages from the Python Packaging Authority (PyPA).
> wget https://bootstrap.pypa.io/get-pip.py
...
2017-10-22 22:27:42 (5.57 MB/s) - 'get-pip.py' saved [1595408/1595408]
Run the PIP installer using sudo:
> sudo /var/packages/py3k/target/usr/local/bin/python3 get-pip.py
Password: *********
Collecting pip
  Using cached pip-9.0.1-py2.py3-none-any.whl
Collecting setuptools
  Using cached setuptools-36.6.0-py2.py3-none-any.whl
Collecting wheel
  Using cached wheel-0.30.0-py2.py3-none-any.whl
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-9.0.1 setuptools-36.6.0 wheel-0.30.0
Remove the installer file.
> rm get-pip.py
Use PIP to install virtualenv using sudo:
> sudo /var/packages/py3k/target/usr/local/bin/pip install virtualenv
Collecting virtualenv
  Using cached virtualenv-15.1.0-py2.py3-none-any.whl
Installing collected packages: virtualenv
Successfully installed virtualenv-15.1.0
Now create the virtual environment for running the fitbit sync utility:
> /var/packages/py3k/target/usr/local/bin/virtualenv fitbitenv
Using base prefix '/volume1/@appstore/py3k/usr/local'
New python executable in /volume1/homes/mark/fitbit/fitbitenv/bin/python3
Also creating executable in /volume1/homes/mark/fitbit/fitbitenv/bin/python
Installing setuptools, pip, wheel...done.
Load the virtual environment settings, and download the required packages:
> source fitbitenv/bin/activate

> pip3 install -r requirements.txt
...
lots of output
Register your application on the Fitbit Developer Console as described here.  Then copy and paste the Client Id and Client Secret values into the following command:
> cd auth

> python3 auth_fitbit.py -i ClientId -s ClientSecret --console
Copy and paste the URL in your web browser.  After authentication by Fitbit, copy the redirected URL, and paste back into the Python utility.

Likewise register your application on the Google Developer Console as described here.  Then copy and paste the Client Id and Client Secret values into the following command:
python3 auth_google.py -i ClientId -s ClientSecret --console
Copy and paste the URL in your web browser.  After authentication by Google, copy verification code, and paste back into the Python utility.

Check and update the config.ini as required.  I used the default date range, and only updated the items to sync.

Perform sync:
cd ~/fitbit

> python3 app.py
Lastly, I created a script to run the Fitbit sync utility.  Substitute your username in the path.
> cat ~/bin/fitbit_sync 
#!/bin/sh
cd /var/services/homes/username/fitbit
source fitbitenv/bin/activate
python3 app.py
Finally, configure a scheduled task to run the script periodically.

Comments

Popular posts from this blog

Resolving FOSCAM connection dropouts

Building an automatic chicken door opener

TVersity media serving to the Astone AP-300