This has been one of the most frustrating and under-explained integrations I have installed. The official instructions at home-assistant.io/integrations/fitbit lack a lot of detail and I’ve had problems with the sensor install, authorisation and 500 server errors.
Here is what I have found to work for me:
Homeassistant running on Raspberry Pi 4 Model B
Home Assistant OS 6.6
core-2021.11.4
supervisor-2021.10.8
Fitbit needs a secure URL (https) for the callback url. I’m using my nabu.casa address for this. in Homeassistant, go to Configuration->General and scroll down to External/Internal URL box. Enter your external URL in BOTH boxes.
External URL: https://xxxx.ui.nabu.casa
Internal URL: https://xxxx.ui.nabu.casa
Next go to github.com/BertrumUK/fitbit
and download the 3 files: init.py manifest.json sensor.py
In Homeassistant, open your file editor and in /config/custom_components/ create a new folder called fitbit. Load the 3 files to this folder.
Back in the config folder, open configuration.yaml and add your fitbit sensors you want to track and save the file:
sensor:
- platform: fitbit
clock_format: 12H
unit_system: metric
monitored_resources:
- "body/weight"
- "devices/battery"
- "activities/heart"
- "activities/steps"
Restart Homeassistant.
Once you have restarted, under Notifications in the side menu, a new notification will have appeared. Click on it and then click on configure. This will give you the parameters required to configure your Fitbit app.
Go to dev.fitbit.com/apps/new to create a new app on Fitbit for your integration. (If you do not have a fitbit dev account you will need to create one)
Fill in the form on the screen. Most boxes are required so I used my nabu.casa address for them all.
The important one is the callback URL: https://xxxx.ui.nabu.casa:8123/api/fitbit/callback
Note, Homeassistant shows a trailing “/” but I found this caused me an error, so I left it off and it worked fine. Be sure to pick “Personal” for the OAuth type.
Take note of the OAuth 2.0 Client ID and Client Secret as you will need these in Homeassistant.
Return to Homeassistant and open the file fitbit.conf in the configuration folder. Note, you still have the fitbit configuration box open at this point, so I got around this by opening a second instance of my HA and editing the file there. Fill in the Client ID and Client Secret that Fitbit provided in the app and save the file.
Then click the blue “I have Saved My Client ID and Secret Info” button.
Click on Configure again and Homeassistant will prompt you to authorise the Fitbit app with Homeassistant
Here is where I had issues with the “500 server error. Server got itself in trouble”
DO NOT click on the link, instead copy it, and replace your casa address with your internal address
Change
https://xxx.ui.nabu.casa/api/fitbit
to
http://192.168.xxx.xx:8123/api/fitbit
Post this to a new browser window
Fitbit will respond with an error: unauthorised client in url
Copy the full URL in the browser window:
Replace the client_id and redirect_url
client_id is the one you entered to fitbit.confg
redirect_url is your casa address
OLD URL
https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=23XCDQ&redirect_uri=http://192.168.xxx.xxx:8123/api/fitbit/callback&scope=activity+heartrate+nutrition+profile+settings+sleep+weight&state=Zmo69Wkex96S3QHIL70xcpyqAA3PebPi
NEW URL
https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=[ENTER CLIENT_ID HERE]&redirect_uri=https://xxx.ui.nabu.casa/api/fitbit/callback&scope=activity+heartrate+nutrition+profile+settings+sleep+weight&state=Zmo69Wkex96S3QHIL70xcqAA3PebPi
Copy and paste this new URL in a browser window
The Fitbit authorisation should appear. Select “Allow All” and click on the “Allow” button. A small file will download, ignore it, it just contains a text string “Fitbit has been successfully authorized! You can close this window now!”
Return to Homeassistant and the configuration box should have vanished and you should have sensors from Fitbit in your entities list, e.g. sensor.weight, sensor.steps, etc.