Skip to content

ParkerRex/8sleep-bed-controller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Eight Sleep Smart Bed Controller

A comprehensive solution for controlling Eight Sleep smart beds via physical hardware buttons, bypassing the need for phone app interaction. This project provides multiple approaches for API access, traffic interception, and hardware integration.

๐ŸŽฏ Project Overview

This project enables you to control your Eight Sleep smart bed temperature using physical hardware buttons instead of relying on the mobile app. It includes:

  • API Client: Direct integration with Eight Sleep's REST API
  • Traffic Interception: Multiple methods to capture and analyze Eight Sleep app traffic
  • Hardware Integration: Physical button controller with customizable temperature presets
  • Bypass Solutions: Tools to handle certificate pinning and authentication challenges

โœจ Features

  • Direct API Control: Authenticate and control bed temperature programmatically
  • Multiple Proxy Methods: mitmproxy, custom TypeScript proxy, and capture scripts
  • Certificate Pinning Bypass: Python scripts and alternative approaches
  • Hardware Button Simulation: Keyboard-based testing with real hardware integration framework
  • Temperature Presets: Configurable cool, neutral, and warm temperature settings
  • Dual-Zone Support: Independent control for left and right bed sides
  • Environment Configuration: Easy setup with .env file support
  • Comprehensive Logging: Detailed capture and analysis of API traffic

๐Ÿ“‹ Prerequisites

  • Node.js/Bun: For running TypeScript components
  • mitmproxy: For traffic interception (brew install mitmproxy)
  • Eight Sleep Account: Valid email and password
  • iOS/Android Device: For initial traffic capture (if needed)
  • Hardware Button (optional): GPIO, USB HID, or similar interface

๐Ÿš€ Quick Start

1. Installation

# Clone and install dependencies
cd mitmproxy
bun install

# Install mitmproxy (macOS)
brew install mitmproxy

2. Configuration

Create a .env file with your Eight Sleep credentials:

# Copy the template
cp .env.template .env

# Edit with your credentials
vim .env

Required environment variables:

EIGHT_SLEEP_EMAIL=[email protected]
EIGHT_SLEEP_PASSWORD=your-password
EIGHT_SLEEP_CLIENT_ID=0894c7f33bb94800a03f1f4df13a4f38
EIGHT_SLEEP_CLIENT_SECRET=f0954a3e0e9b47348e98fc5f0b2d45c3b4ba1790e65973febc690037bdadceba

# Temperature presets (-100 to 100 scale)
COOL_TEMP_LEFT=-50
COOL_TEMP_RIGHT=-50
NEUTRAL_TEMP_LEFT=0
NEUTRAL_TEMP_RIGHT=0
WARM_TEMP_LEFT=50
WARM_TEMP_RIGHT=50

3. Test API Connection

# Test authentication and API access
bun run src/test-eight-sleep-api.ts

4. Start Hardware Controller

# Run the main controller with keyboard simulation
bun run index.ts

Use keyboard controls:

  • 1 - Set to COOL temperature
  • 2 - Set to NEUTRAL temperature
  • 3 - Set to WARM temperature
  • q - Quit

๐Ÿ“š API Documentation

SmartBedAPI Class

The core API client for Eight Sleep integration:

import { SmartBedAPI } from './src/smartbed-api';

const api = new SmartBedAPI({
  email: '[email protected]',
  password: 'your-password',
  clientId: 'optional-client-id',
  clientSecret: 'optional-client-secret'
});

// Authenticate
await api.authenticate();

// Get devices
const devices = await api.getDevices();

// Set temperature
await api.setTemperature({
  left: -50,  // Cool left side
  right: 25,  // Warm right side
  duration: 3600 // 1 hour (0 for continuous)
});

// Get current status
const status = await api.getStatus();

Temperature Scale

Eight Sleep uses a -100 to 100 temperature scale:

  • -100 to -1: Cooling (negative values)
  • 0: Neutral/Off
  • 1 to 100: Heating (positive values)

API Endpoints

The client automatically handles multiple API endpoints:

  • https://auth-api.8slp.net - Authentication
  • https://client-api.8slp.net - Device control
  • https://app-api.8slp.net - Application API

๐Ÿ”ง Traffic Interception Setup

If you need to capture your own API credentials or analyze traffic:

Method 1: mitmproxy with Capture Script (Recommended)

# Start interactive proxy selection
./start-proxy.sh

# Or run directly
mitmproxy -s scripts/bypass-cert-pinning.py --ssl-insecure

Method 2: TypeScript Proxy Server

# Run custom proxy server
bun run src/proxy-server.ts

Method 3: Manual Traffic Analysis

# Capture to file for later analysis
mitmdump -w captures/smartbed_traffic.flow --ssl-insecure

# Analyze captured traffic
bun run src/find-eight-sleep-traffic.ts

iPhone Proxy Configuration

  1. Install mitmproxy Certificate:

    • Start mitmproxy to generate certificates
    • Navigate to mitm.it on your iPhone
    • Install the certificate profile
    • Settings > General > About > Certificate Trust Settings
    • Enable trust for mitmproxy certificate
  2. Configure HTTP Proxy:

    • Settings > Wi-Fi > (i) on your network
    • HTTP Proxy > Manual
    • Server: Your Mac's IP address
    • Port: 8080

๐Ÿ” Certificate Pinning Solutions

Eight Sleep uses certificate pinning, which blocks standard proxy interception. Here are several solutions:

Option 1: Use Rooted Android Device

# Use SSL Kill Switch or TrustMeAlready apps
# These bypass certificate pinning automatically

Option 2: Frida SSL Bypass (Advanced)

# For jailbroken iOS or rooted Android
frida -U -f com.eightsleep.eight -l bypass-ssl-pinning.js --no-pause

Option 3: Web Portal Capture

# Try logging into web interface
bun run src/capture-web-login.ts

Option 4: Use Known OAuth Credentials

The project includes known OAuth client credentials that may work with your account:

EIGHT_SLEEP_CLIENT_ID=0894c7f33bb94800a03f1f4df13a4f38
EIGHT_SLEEP_CLIENT_SECRET=f0954a3e0e9b47348e98fc5f0b2d45c3b4ba1790e65973febc690037bdadceba

๐ŸŽฎ Hardware Integration

Button Controller Architecture

The ButtonController class provides the framework for physical button integration:

import { ButtonController } from './src/button-controller';

const controller = new ButtonController(api, {
  coolTemp: { left: -50, right: -50 },
  neutralTemp: { left: 0, right: 0 },
  warmTemp: { left: 50, right: 50 }
});

await controller.initialize();

Hardware Options

  1. GPIO Buttons (Raspberry Pi):

    // Extend ButtonController for GPIO
    setupGPIOListener(pin: number) {
      // Implement GPIO interrupt handling
    }
  2. USB HID Device:

    setupUSBListener(deviceId: string) {
      // Implement USB HID event handling  
    }
  3. Serial Communication:

    setupSerialListener(port: string) {
      // Implement serial port communication
    }
  4. Wireless Button (ESP32/Arduino):

    setupWirelessListener(endpoint: string) {
      // Implement HTTP/WebSocket listener
    }

๐Ÿ› ๏ธ Troubleshooting

Common Issues

Authentication Failures:

# Verify credentials
bun run src/extract-credentials.ts

# Test different API endpoints
bun run src/test-eight-sleep-api.ts

Certificate Pinning Errors:

# Use bypass script
mitmproxy -s scripts/bypass-cert-pinning.py --ssl-insecure

# Check certificate installation
# Settings > General > About > Certificate Trust Settings

No Traffic Captured:

# Verify proxy settings on device
# Check IP address is correct
# Ensure port 8080 is not blocked

API Rate Limiting:

# Add delays between requests
# Implement exponential backoff
# Use session token caching

Debug Mode

Enable verbose logging:

DEBUG=1 bun run index.ts

Network Diagnostics

# Test local network connectivity
./capture-with-ignore-hosts.sh

# Analyze captured traffic  
bun run src/find-eight-sleep-traffic.ts

๐Ÿ“ Project Structure

mitmproxy/
โ”œโ”€โ”€ README.md                    # This file
โ”œโ”€โ”€ CAPTURE_GUIDE.md            # Detailed capture instructions
โ”œโ”€โ”€ package.json                # Project dependencies
โ”œโ”€โ”€ tsconfig.json               # TypeScript configuration
โ”œโ”€โ”€ index.ts                    # Main application entry point
โ”œโ”€โ”€ .env.template               # Environment variable template
โ”œโ”€โ”€ start-proxy.sh              # Interactive proxy launcher
โ”œโ”€โ”€ capture-with-ignore-hosts.sh # Traffic capture with filtering
โ”‚
โ”œโ”€โ”€ src/                        # TypeScript source files
โ”‚   โ”œโ”€โ”€ smartbed-api.ts         # Eight Sleep API client
โ”‚   โ”œโ”€โ”€ button-controller.ts    # Hardware button controller
โ”‚   โ”œโ”€โ”€ proxy-server.ts         # Custom TypeScript proxy
โ”‚   โ”œโ”€โ”€ test-eight-sleep-api.ts # API testing utilities
โ”‚   โ”œโ”€โ”€ extract-credentials.ts  # Credential extraction guide
โ”‚   โ”œโ”€โ”€ find-eight-sleep-traffic.ts # Traffic analysis
โ”‚   โ””โ”€โ”€ capture-web-login.ts    # Web portal capture
โ”‚
โ”œโ”€โ”€ scripts/                    # Proxy and capture scripts
โ”‚   โ”œโ”€โ”€ bypass-cert-pinning.py  # mitmproxy certificate bypass
โ”‚   โ”œโ”€โ”€ capture-smartbed.ts     # TypeScript capture module
โ”‚   โ””โ”€โ”€ capture_smartbed.js     # JavaScript capture script
โ”‚
โ”œโ”€โ”€ captures/                   # Saved traffic captures
โ”‚   โ””โ”€โ”€ smartbed_traffic.flow   # mitmproxy flow file
โ”‚
โ”œโ”€โ”€ config/                     # Configuration files
โ””โ”€โ”€ hardware/                   # Hardware integration examples

๐Ÿ—๏ธ Architecture Overview

System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Physical       โ”‚    โ”‚   Controller     โ”‚    โ”‚  Eight Sleep    โ”‚
โ”‚  Button         โ”‚โ”€โ”€โ”€โ–ถโ”‚   Application    โ”‚โ”€โ”€โ”€โ–ถโ”‚  API Service    โ”‚
โ”‚  (GPIO/USB/etc) โ”‚    โ”‚   (TypeScript)   โ”‚    โ”‚  (REST API)     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚
                              โ–ผ
                       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                       โ”‚   Smart Bed      โ”‚
                       โ”‚   Hardware       โ”‚
                       โ”‚   (Eight Sleep)  โ”‚
                       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Data Flow

  1. Button Press โ†’ Hardware interrupt/event
  2. Event Handler โ†’ ButtonController.onButtonPress()
  3. API Call โ†’ SmartBedAPI.setTemperature()
  4. Authentication โ†’ Eight Sleep OAuth/Session
  5. Temperature Control โ†’ Bed hardware adjustment

Security Model

  • OAuth 2.0: Client credentials flow
  • Session Tokens: Temporary authentication
  • HTTPS: All API communication encrypted
  • Certificate Pinning: Handled by bypass scripts

๐Ÿค Development & Contributing

Development Setup

# Install development dependencies
bun install

# Run type checking
bun run tsc --noEmit

# Run linting (if configured)
bun run lint

# Run tests
bun test

Adding New Hardware Interfaces

  1. Extend the ButtonController class
  2. Implement hardware-specific event handling
  3. Add configuration options to ButtonConfig
  4. Update documentation with setup instructions

Example GPIO implementation:

class GPIOButtonController extends ButtonController {
  private gpio: any;
  
  setupGPIOListener(pin: number) {
    this.gpio = require('gpio');
    this.gpio.setup(pin, this.gpio.DIR_IN, this.gpio.EDGE_FALLING);
    this.gpio.on('change', (channel: number, value: boolean) => {
      if (!value) { // Button pressed (falling edge)
        this.onButtonPress(channel);
      }
    });
  }
}

API Extensions

To add new Eight Sleep API endpoints:

  1. Add method to SmartBedAPI class
  2. Update TypeScript interfaces
  3. Add usage examples to README
  4. Test with actual API

Testing

# Test API connectivity
bun run src/test-eight-sleep-api.ts

# Test traffic capture
./start-proxy.sh

# Test hardware simulation
bun run index.ts

๐Ÿ“„ License

This project is for educational and personal use. Respect Eight Sleep's terms of service and API usage policies.

๐Ÿ™‹โ€โ™‚๏ธ Support

Getting Help

  1. Check the troubleshooting section above
  2. Review capture guides in CAPTURE_GUIDE.md
  3. Test API connectivity with provided utilities
  4. Verify network configuration and certificates

Common Solutions

  • Can't authenticate: Try password reset and use known OAuth credentials
  • No traffic captured: Verify proxy settings and certificate trust
  • API rate limiting: Implement request delays and session caching
  • Hardware not responding: Check GPIO/USB permissions and drivers

Alternative Approaches

If direct API access fails:

  • Use smart plugs to control bed power
  • Implement IR blaster control (if bed has remote)
  • Reverse engineer Bluetooth protocol
  • Contact Eight Sleep support for official API access

Note: This project is not affiliated with Eight Sleep. Use responsibly and in accordance with their terms of service.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published