bobobo1618 / ninesleep

MIT License
221 stars 26 forks source link

Overview

Warning: This code is very new and immature. It works for me but requires technical know-how to use.

This repository contains a program intended to replace the dac process on an Eight Sleep Pod 3, giving the user the ability to interact with the pod locally, without any interaction with Eight Sleep's servers.

Clearly, this project is not endorsed by Eight Sleep. You're responsible for anything you do with your pod.

Compatibility

This has currently only been tested on a Pod 3 based on the Variscite VAR-SOM-MX8M-MINI.

Example board:

picture of a Pod 3 circuit board

Example hardware info from Eight Sleep app:

screenshot of the hardware info section of the Eight Sleep app

Instructions

To use:

You can now compile this program for the Pod 3: cargo build --target aarch64-unknown-linux-musl (musl is used so that a static binary will work). Copy it to your Pod over ssh and you should be able to run it, although you'll need to run systemctl stop dac as root first to shut down the stock dac, which listens on the relevant unix socket.

You may want to disable Eight Sleep's updates and telemetry. You can do that with: systemctl disable --now swupdate-progress swupdate defibrillator eight-kernel telegraf vector. The frankenfirmware binary will still send data to raw-api-upload.8slp.net. If you want to deal with that, add raw-api-upload.8slp.net to your /etc/hosts file.

API

Home Assistant

The API can easily be integrated with Home Assistant using the rest_command integration:

rest_command:
  set_alarm:
    url: http://<pod_ip>:8000/alarm/right
    method: post
    payload: '{"pl":{{strength}},"du":{{duration}},"tt":{{timestamp}},"pi":"{{pattern}}"}'
  set_temp:
    url: http://<pod_ip>:8000/temperature/right
    method: post
    payload: '{{temperature}}'
  set_temp_duration:
    url: http://<pod_ip>:8000/temperature-duration/right
    method: post
    payload: '{{duration}}'

The relevant settings can be passed as data. Here's an example automation that sets the temperature based on a calendar where the event name is the desired temperature:

alias: Bed Calendar-driven Temperature
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "0:0:0"
    entity_id: calendar.sleep
condition:
  - condition: template
    value_template: "{{trigger.calendar_event.summary | is_number}}"
action:
  - repeat:
      sequence:
        - service: rest_command.set_temp
          data:
            temperature: "{{trigger.calendar_event.summary}}"
        - service: rest_command.set_temp_duration
          data:
            duration: 7200
        - delay:
            hours: 0
            minutes: 30
            seconds: 0
            milliseconds: 0
      while:
        - condition: template
          value_template: "{{as_timestamp(trigger.calendar_event.end) > as_timestamp(now())}}"
mode: single