FitBit unable to authorize

hey guys. tried for a few days now and always got the Invalid client_iderror until i tried another browser.
Then i got the Invalid redirect_uri parameter value error

BertrumUK tipp (exchanging the local IP in the browser adress to the nabu casa worked for me.
So i got redirected to the authtication process but when i click “Allow” i get an ERROR 404

Any ideas?

Exactly the same here. Running HA OS. Drives me crazy not have this working.

If someone has this working with Nabu Casa and HA OS, I’d reeeally appreciate info on how to achieve that.

I moved over to HAOS last week and I cannot get it to authenticate at all now and it throws a 500 error after I allow all the available sensors. I deleted my old API setup at Fitbit and started a new one but it is still the same. The logs show this error -

Detected I/O inside the event loop. This is causing stability issues. Please report issue for fitbit doing I/O at homeassistant/components/fitbit/sensor.py, line 362: result = self.oauth.fetch_access_token(data.get("code"), redirect_uri)

Someone has logged a new issue here

There is a now a fix for this by modifying the Fitbit sensor.py file. If you add the 3 files as a custom component and restart HA the authentication should not go through.

Further help and a link to the files are in my GitHub repository here

Thanks again to @Yusi for supplying the fix.

1 Like

Thank you for this! Had given up on Fitbit in HA

A slight change since you posted it

http:
  base_url:

has been deprecated and after adding my DNS url to Settings > General > External / Internal URL (https://home.assistant) and restarting I was able to setup the integration

If it fails take a look at the URL


What worked for me is to open the new url in another browser (Firefox)

Glad you got it working!

hello
y have problems to autorize. do you know if the problem comes again?

Yes you can use this integration without exposing HA to the internet - I just got it working by enabling HTTPS using this guide I found on the Github issue tracker: https://gist.github.com/ammgws/d3fb6d197e6036e496d4fee17e22a84f

2 Likes

Can this work for 2 fitbit account?

THANK YOU to everyone in this thread and the few others on the topic. I feel like it more or less works as instructed on the integration page, but my gosh is it absolutely underexplained and without much needed details. I’d almost rather redo all my Tuya before needing to figure this one out again…

Help someone else out. Write up your experience and post it here. I have a PV6, but haven’t the skills to set this up.

1 Like

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.

6 Likes

My experience was slightly different. As I was on my internal domain when I started, when I came to auth it tried to use the internal IP address. When the fitbit auth error appeared, I just replaced the IP with the https Casa address.

Great tutorial :slight_smile:

1 Like

Hi Brian,
Yes, I think I did that the first time I installed the integration. I’ve installed it twice on 2 different HA setups. The second was to document what I did, both for here, and also so I had a record of how I did it if I ever had to do a reinstall. I used the external URL as the Fitbit app requires an HTTPS address to set up the app.

1 Like

Just in case it was missed earlier, you can actually set it up without using an external URL if you do something like this: https://gist.github.com/ammgws/d3fb6d197e6036e496d4fee17e22a84f

Of course if you already have an external URL then I guess it doesn’t matter, but just putting it out there again for those of us who want to keep their HA instance local only.

I think the main two main issues with this integration are:

  1. Clunky setup process

  2. Fitbit changing their API to enforce HTTPS as of a couple of years ago

The first issue should be solved if someone is willing to do the work mentioned here: Clarify that only HTTPS can be used in fitbit by ammgws · Pull Request #57116 · home-assistant/core · GitHub

The second issue should hopefully be solved once a new release of HA is made that has this PR included: Clarify that only HTTPS can be used in fitbit by ammgws · Pull Request #57116 · home-assistant/core · GitHub

Hello @Shortland

I followed your steps but the step below does not work:

I do not get a notification thus I can’t go to next step. Any idea?

UPDATE-------
The problem was that you absolutely need to have filled the external and internal URL in your Configuration. Otherwise the notification won’t appear. Once I did that, I could follow up on your tutorial and I managed to link some Fitbit sensors in my HA. I know it was mentionned by @Shortland, I just thought I had already done that because I am using an external DuckDNS link for my HA.
Capture d’écran, le 2022-03-04 à 09.38.55

Mant thanks for this manual. It works for me.

Does anyone know if it is possible to add a second fitbit to home assistant?

Thanks.
Koen

Where is this CONFIGURATION?
I can’t find any Configuration in my HAOS installation excelt the yaml file and it doesn’t look at all like this.
So basically even though I have it setup to work with HTTPS I don’t know where to tell it, and the Fitbit script says it can’t find it.