YorkshireIoT / ha-google-fit

Home Assistant Google Fit Custom Component
MIT License
98 stars 9 forks source link
google-fit home-assistant home-assistant-integration python

Google Fit Home Assistant Custom Integration

GitHub Release HA Installs GitHub Activity GitHub Downloads

License hacs

Project Maintenance GitHub Sponsors BuyMeCoffee

[!CAUTION] Due to Google deprecating the Fit API (see below), Google are blocking any new developers signing up to this API. As such, any new user wanting to use this integration who has not already signed up to the Fit API will not be able to. To anyone affected by this, I'm as annoyed and disappointed as you ☹️

[!WARNING] Google is shutting down the REST API on 30th June 2025. As this integration relies on this API, it will no longer work after this time.

Additional information (and maybe solutions if they come along) can be found on Issue #250.

This integration interfaces with the Google Fit REST API to provide Google Fit data within Home Assistant.

Example

This integration will set up the following platforms.

Platform Name Description Infrequent Update
sensor active_minutes_daily Active Minutes. Reset daily.
sensor calories_burnt_daily Calories burnt (kcal). Reset daily.
sensor basal_metabolic_rate Base Metabolic Rate (kcal). Calories per day based on weight and activity.
sensor distance_travelled_daily Distance travelled (metres). Reset daily.
sensor heart_points_daily Heart Points earned. Reset daily.
sensor height Height (metres).
sensor weight Weight (kilograms).
sensor body_fat Body Fat (percentage).
sensor body_temperature Body Temperature (celsius).
sensor steps Number of steps taken. Reset daily.
sensor deep_sleep Deep sleep time over the past 24 hours. May not be available depending on sleep data provider.
sensor light_sleep Light sleep time over the past 24 hours. May not be available depending on sleep data provider.
sensor rem_sleep REM sleep time over the past 24 hours. May not be available depending on sleep data provider.
sensor awake_time Awake time during a sleep session over the past 24 hours. Not overall daily awake time. May not be available depending on sleep data provider.
sensor sleep Overall sleep time over the past 24 hours.
sensor blood_pressure_diastolic Most recent Diastolic blood pressure reading.
sensor blood_pressure_systolic Most recent Systolic blood pressure reading.
sensor heart_rate Most recent heart rate measurement.
sensor resting_heart_rate Most recent resting heart rate measurement.
sensor blood_glucose Latest blood_glucose measurement (mmol/L).
sensor hydration Total water consumed. Reset daily.
sensor oxygen_saturation The most recent blood oxygen saturation measurement.

Please note, there is a delay (roughly 30-60 minutes) between sensor measurements being recorded on the Google Fit app and the data then being available to query of the rest API. As such, although this integration polls the API more frequently than this it will take at least this length of time for your data to appear in Home Assistant. It is not instantaneous.

Prerequisites

Authentication Configuration

I will not try to duplicate what has already been documented countless times before as it will no doubt become out of date.

Instead, follow the instruction in the Official Home Assistant Docs for Google Mail under the "Generate Client ID and Client Secret" section, replacing instructions for 'Gmail API' with 'Fit API'.

Installation

HACS (Recommend)

Prerequisites

HACS Installed in Home Assistant: Home Assistant Community Store

Steps

  1. Go to HACS
  2. Go to Integrations
  3. Click Explore & Download Repositories
  4. Find the integration as Google Fit
  5. Click install.
  6. Restart Home Assistant.

Manual

  1. Using the tool of choice open the directory (folder) for your HA configuration (where you find configuration.yaml).
  2. If you do not have a custom_components directory (folder) there, you need to create it.
  3. In the custom_components directory (folder) create a new folder called google_fit.
  4. Download all the files from the custom_components/google_fit/ directory (folder) in this repository.
  5. Place the files you downloaded in the new directory (folder) you created.
  6. Restart Home Assistant

Setup

Setup is done completely in the UI. Go to your integrations page by clicking the button below.

Open your Home Assistant instance and show your integrations.

Click "+ Add Integration", search for "Google Fit" and follow the steps. If you have set the app you created in the Credentials configuration to publish (which you should've done to avoid re-authentication problems) then you will probably see a warning step asking if you want to proceed.

You can hit "Advanced", then "Proceed" as you are the 'developer' of the app, as you created the app and credentials in your own account.

Setup Example Screenshots

Add Integration Add Credentials Choose Google Account Unverified Warning Access Request with Scopes Link Account Finished

Configuration

The following options can be tweaked after setting up the integration:

Option Description Default
Update interval Minutes between REST API queries. Can be increased if you're exceeding API quota 5 (minutes)
Infrequent Sensor Multiplier Multiply the update interval by this for less frequently updated sensors, e.g. height. This reduces unnecessary API queries. 12 (so default 5 mins update interval changes to an hour)

Unknown Sensor Behaviour

All sensors in this integration can be grouped into two categories; cumulative or individual. This is due to how data is reported in your Google Fit account. Every piece of data is only associated with a time period and has no underlying logic for running totals.

For example, steps are reported like this in your account:

There is then some built-in logic in this integration to work out what sensor we're dealing with, and to either sum up these values over a logical time period, or to just take the latest known value, when the sensor is something like height.

If you're interested in all the underlying logic, it's contained in api.py.

The behaviour of this integration when there is no data available in your account differs depending on the sensor category.

Cumulative sensors will use 0 as their base value and this will be their value in Home Assistant if their is no data in your Google Fit account for that sensor.

Individual sensors will only report a value if they can find some data in your Google Fit account. Otherwise, they will show Unknown.

Unavailable

Besides Unknown, there is an additional Home Assistant sensor state; Unavailable.

This state has nothing to do with if there is or isn't data in your account. It indicates some error in the fetching of the data. Your internet has stopped working, or maybe the Google servers are down. In some cases, it may also indicate there is a bug with this integration. If that is the case, please report it as a bug.

There are no plans to ignore these data fetching issues and retain the last known sensor value. The reasoning for this is:

Adding Multiple Accounts

Multiple Account

Use the following steps to setup additional Google Fit accounts in Home Assistant.

  1. Go through all the steps in Authentication Configuration for the second account, e.g. create a completely separate application cloud application, enable Fit API and create new credentials.
  2. Go to Integrations and click the 3 dots in the top right to go to Application Credentials.
  3. Click "Add Application Credentials", select "Google Fit" as the integration and add in the newly created credentials.
  4. Go through the configuration flow, making sure to pick the correct new Google account when prompted.
  5. Once completed you should now see multiple Google Fit integration credentials in the table.
  6. Go back to integration, click "Add Integration", search for Google Fit and then choose the newly created credentials as the implementation when prompted.

Reconfiguring badly configured credentials

If you made a mistake somewhere when configuring your credentials, whether with the Google Cloud Console or within Home Assistant, you need to delete not just the integration to be prompted to reconfigure but also the 'bad' credentials.

To do this, go to the Integrations page and click the 3 dots in the top right and go to "Application Credentials". From there you can select the credentials and remove them.

Application Credentials

Contributions are welcome!

If you want to contribute to this please read the Contribution guidelines