A Node.js/TypeScript application for collecting and storing SleepNumber bed statistics in Victoria Metrics and sending data to Google Health.
- Collects nightly sleep data from SleepNumber API
- Stores data in Victoria Metrics
- Optionally sends sleep sessions to Google Health
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 Google Health 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 |
| overwriteGoogleHealthRecords | If true, overwrites existing Google Health sleep on conflict | false | true |
| tz | Timezone for scheduling | "UTC" | "America/New_York" |
| logLevel | Pino logger level (trace, debug, info, etc.) | "info" | "debug" |
| googleRedirectUri | Public HTTPS callback URL for Google OAuth2 | (optional) | "https://sleep.example.com/callback" |
| googleClientId | Google Cloud credential client ID | (optional) | "12ABCD" |
| googleClientSecret | Google Cloud credential client secret | (optional) | "abcdef1234567890abcdef1234567890" |
| port | Port for the web server (Google Health 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 reporting of sleep data to your Google Health account (for syncing to your phone):
-
Setup an HTTPS domain reverse proxied to your container
-
Create a project in the Google Cloud Console:
-
Create an app on the Google Cloud Console
-
Go to the Google Health application and click Enable
-
Click Credentials in the navigation menu
-
Click Create credentials and then OAuth client ID
-
Click Configure consent screen and complete the form
-
Click Create OAuth client
- Application type: Web application
- Name: sleepnumber-stats
- Authorized JavaScript origins: set to the origin of the HTTPS URL set in the config
googleRedirectUri(e.g.https://sleep.example.com) - Authorized redirect URIs: set to the value of the HTTPS URL set in the config
googleRedirectUri(e.g.https://sleep.example.com/callback)
-
Add the Google Health options to your config:
{ ...existing config fields... "googleRedirectUri": "https://sleep.example.com/callback", "googleClientId": "123456789012-abcdefghijklmnopqrstuvwcyz123456.apps.googleusercontent.com", "googleClientSecret": "ABCDEF-abcdefghijklmnopqrstuvwxyzab" } -
Go to the Audience page and click Publish app
-
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 Google Health account and follow the Google Health linking steps
-
CTRL-C in the terminal to exit the setup application
-
The Google Health data will be uploaded on your next scheduled run. You should see your Google refresh token in
/app/config/tokens.json.