Skip to content

claabs/sleepnumber-stats

Repository files navigation

SleepNumber Stats

A Node.js/TypeScript application for collecting and storing SleepNumber bed statistics in Victoria Metrics and sending data to Google Health.

Features

  • Collects nightly sleep data from SleepNumber API
  • Stores data in Victoria Metrics
  • Optionally sends sleep sessions to Google Health

Quick Start (Docker)

Docker Run Example

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-stats

Docker Compose Example

services:
  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-stopped

Configuration

All 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 containing config.json. Default is /app/config.

Persistent Data

  • The /app/config volume stores authentication tokens and should be mounted to retain login state between runs.

Configuration Reference

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 ** *

Example config.json

{
  "sleepNumberEmail": "your@email.com",
  "sleepNumberPassword": "yourpassword",
  "victoriaMetricsUrl": "http://victoriametrics:8086",
  "victoriaMetricsAuth": {
    "username": "admin",
    "password": "passwort",
  },
  "deleteMetrics": false,
  "tz": "America/New_York",
  "logLevel": "info"
}

Optional: Google Health Integration

To enable the reporting of sleep data to your Google Health account (for syncing to your phone):

  1. Setup an HTTPS domain reverse proxied to your container

  2. Create a project in the Google Cloud Console:

  3. Create an app on the Google Cloud Console

  4. Go to the Google Health application and click Enable

  5. Click Credentials in the navigation menu

  6. Click Create credentials and then OAuth client ID

  7. Click Configure consent screen and complete the form

  8. 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)
  9. 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"
    }
  10. Go to the Audience page and click Publish app

  11. Open a terminal inside your running container and run ./setup.sh:

    docker exec -it sleepnumber-stats sh
    ./setup.sh
  12. Navigate to /register (e.g. https://sleep.example.com/register)

  13. Click the sleeper you'd like to associate with your Google Health account and follow the Google Health linking steps

  14. CTRL-C in the terminal to exit the setup application

  15. The Google Health data will be uploaded on your next scheduled run. You should see your Google refresh token in /app/config/tokens.json.

About

Scrapes sleep data from Sleep Number SleepIQ and writes it to Victoria Metrics and Fitbit

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors