Simple Fitbit Weather
The goal of this project is to simplify access to weather data inside Fitbit OS applications.
The code to get weather from API provider is based on fitbit-weather.
The main differences are :
- This module was made to reduce work on Fitbit devices (client app script size and memory usage).
- Periodic update is made by the companion app.
- The companion app refresh weather data when the user opens the mobile application.
- It is built with TypeScript.
- It includes types definitions and comments to show documentation in Visual Studio Code.
- Weather providers are declared in specific files (you could pull request to add new providers with less impact on the existing code).
Providers and Data format
Weather providers available at this time :
Provider list could be extended, the list is not closed. Open an issue if you have ideas of providers that could be added (or pull request if you know TypeScript).
How does it work?
The companion application is responsible for :
- Fetching data from weather API.
- Periodicity refreshes data.
- Refresh data when the Fitbit mobile app is open.
- Send new data to the Fitbit Device.
The Fitbit app only has to read local data. I receive notification when the UI has to be updated with new data.
Via the companion application, you could set :
- Refresh intervals (for background tasks).
- Data age (to avoid too many call to the API. If the mobile app has fresh data, it will not call the provider).
1. Install the module
You could use any package manager to install this module. It was tested with npm, pnpm and yarn.
npm install simple-fitbit-weather --save-dev
2. Request user's permissions
Your application should have access to :
access_internet: requested to download weather data.
access_location: requested to know the location of the user to download weather data.
run_background: requested to allow task to run in the background on the mobile.
package.json should be like this (you could request more permissions, it is not a problem) :
If permissions are not well set, you will not have exceptions :
- The user will not have weather data.
- Condition will be
- Others data will stay empty or
0for numéric values.
3. Initialize the companion app
companion folder the
index.ts file have to :
- Import the module.
- Initialize the module.
;// Init weatherweather.initialize;
4. Initialize the device app
Import the module and call the
When the Fitbit device boot, the
applyWeather method will be called if data were previously downloaded.
The TypeScript interface of Weather:
/*** Weather data*/
5. Manual access to the last data
If you have to do periodic calculations, you could request access to last weather out of the
To make it easier, this module exposes a property
last of type
undefined if none data are available.
Compatibility with weather-bit
/*** Weather samples from fitbit-weather*/
Unknown was defined at 9, to reduce messages size.
- clean (remove generated files from the
./distributiondirectory). Those jobs are made by Github Actions to publish the module to NPMJS.