A Node.js/TypeScript application for collecting and storing SleepNumber bed statistics in Victoria Metrics and sending data to Fitbit.
- Collects nightly sleep data from SleepNumber API
- Stores data in Victoria Metrics
- Optionally sends sleep sessions to Fitbit
docker run --rm --init \
-v $(pwd)/config:/app/config \
-p 3000:3000 \
-e TZ=America/New_York \
-e CONFIG_PATH=/app/config \
ghcr.io/claabs/sleepnumber-statsservices:
sleepnumber-stats:
image: ghcr.io/claabs/sleepnumber-stats
init: true
environment:
TZ: "America/New_York"
ports:
- 3000:3000 # optional, for Fitbit setup
volumes:
- ./config:/app/config
restart: unless-stoppedAll application configuration is provided via a config.json file. The optionaly environment variables are:
TZ: Set this to your desired timezone (e.g.,America/New_York,UTC,Europe/London). Default is UTC if not set.CONFIG_PATH: Path to the configuration directory containingconfig.json. Default is/app/config.
- The
/app/configvolume stores authentication tokens and should be mounted to retain login state between runs.
| Key | Description | Default | Example |
|---|---|---|---|
| sleepNumberEmail | SleepNumber account email | (required) | "your@email.com" |
| sleepNumberPassword | SleepNumber account password | (required) | "yourpassword" |
| victoriaMetricsUrl | Victoria Metrics server URL | (required) | "http://172.17.0.1:8428" |
| victoriaMetricsAuth.username | Victoria Metrics username | (optional) | "admin" |
| victoriaMetricsAuth.password | Victoria Metrics password | (optional) | "passwort" |
| deleteMetrics | If true, deletes all existing data previously stored before ingest | false | true |
| tz | Timezone for scheduling | "UTC" | "America/New_York" |
| logLevel | Pino logger level (trace, debug, info, etc.) | "info" | "debug" |
| fitbitRedirectUri | Public HTTPS callback URL for Fitbit OAuth2 | (optional) | "https://sleep.example.com/callback" |
| fitbitClientId | Fitbit developer app client ID | (optional) | "12ABCD" |
| fitbitClientSecret | Fitbit developer app client secret | (optional) | "abcdef1234567890abcdef1234567890" |
| port | Port for the web server (Fitbit setup) | 3000 | 3001 |
| runOnStartup | When true, the container runs immediately on startup | false | true |
| runOnce | When true, the container runs once and does not schedule | false | true |
| schedule | Cron syntax schedule for when the job should run | 15 10 * * * | 0 12 * * * |
{
"sleepNumberEmail": "your@email.com",
"sleepNumberPassword": "yourpassword",
"victoriaMetricsUrl": "http://victoriametrics:8086",
"victoriaMetricsAuth": {
"username": "admin",
"password": "passwort",
},
"deleteMetrics": false,
"tz": "America/New_York",
"logLevel": "info"
}To enable the Fitbit reporting of sleep data to your Fitbit account (for syncing to your phone):
-
Setup an HTTPS domain reverse proxied to your container
-
Create a Fitbit developer application:
- Create an app on the Fitbit dev portal
- Set OAuth 2.0 Application Type to
Personalif only you are using it, orServerif accounts other than the developer's account will connect - Set Redirect URL to your HTTPS URL set in the config
fitbitBaseUrl - Set Default Access Type to
Read & Write
-
Add the Fitbit options to your config:
{ ...existing config fields... "fitbitRedirectUri": "https://sleep.example.com/callback", "fitbitClientId": "12ABCD", "fitbitClientSecret": "abcdef1234567890abcdef1234567890" } -
Open a terminal inside your running container and run
./setup.sh:docker exec -it sleepnumber-stats sh ./setup.sh -
Navigate to
/register(e.g.https://sleep.example.com/register) -
Click the sleeper you'd like to associate with your Fitbit account and follow the Fitbit linking steps
-
CTRL-C in the terminal to exit the setup application
-
The Fitbit data will be uploaded on your next scheduled run. You should see your Fitbit refresh token in
/app/config/tokens.json.