Giter VIP home page Giter VIP logo

pyeight's Introduction

PyPI

Introduction

Python library to interface with the Eight Sleep API

API is currently undocumented. Usage is derived by capturing api calls made by the Eight Sleep android app.

Code is licensed under the MIT license.

Thanks

Special thanks to github user @alyc100 for making his SmartThings Eight Sleep code available.

Requirements

  • python >= 3.9
  • aiohttp >= 2.0
  • asyncio

Installation

pip install pyeight

Usage

Full usage example can be found in the HomeAssistant implementation of this library.

Basic Usage

from pyeight.eight import EightSleep

eight = EightSleep(user, pass, timezone, None)

await eight.start()

# Update mattress data, 1min interval recommended
await eight.update_device_data()

# Update user data, 5min interval recommended
await eight.update_user_data()

Properties

Library properties are well defined in both eight.py and user.py.

TODO

  • Improve dynamic presence detection through statistical analysis

pyeight's People

Contributors

fabaff avatar jonathantsao avatar mezz64 avatar raman325 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pyeight's Issues

Set away mode

From the latest discovery I see set away mode is possible. It would be great if this could be implemented in the home assistant integration

Unable to authenticate and fetch eight token

Been seeing Unable to authenticate and fetch eight token for the last few days. Also seeign 404s in the Home assistant logs when posting eight data. Usernames and passwords have not changed.

Can't turn on the heat

I'm opening a local issue as instructed in the original Home Assistant issue here: home-assistant/core#62813
I've removed partner option from the configuration, and I'm still seeing the same errors whenever I try to turn on the heat in my eight mattress topper. I've verified that my login information is correct, and logged out and back in on my phone. Everything is working fine in the phone app, but not working through this integration. No changes has been made on my account in a very very long time. And this used to work just a few month ago.
Here are the error messages I get:

2021-12-26 15:13:49 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: None
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 381, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 584, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1495, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1530, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/components/eight_sleep/__init__.py", line 178, in async_service_handler
    usrobj = eight.users[userid]
KeyError: None
2021-12-26 15:13:49 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139940582132224] Error handling message: Unknown error
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 527, in handle_execute_script
    await script_obj.async_run(msg.get("variables"), context=context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1260, in async_run
    await asyncio.shield(run.async_run())
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 363, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 381, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 584, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1495, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1530, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/components/eight_sleep/__init__.py", line 178, in async_service_handler
    usrobj = eight.users[userid]
KeyError: None

Home Assistant Single Sleeper

Setting up Eight with home assistant first assumes a single sleeper is on the left, and to my knowledge is supposed switch to the right side of the left throws an error. Not working in my case, sensors showing for left even though no data is being provided and no data or sensors for right side, even though data is available.

Pod Support

I found a thread on the home assistant community page where someone was instructed to open a new issue for the Eight Pod.[https://community.home-assistant.io/t/eight-sleep-component/10472/138] When looking at the data in home assistant, none of it seems to match the data in the Eight app. I'm not the person from that thread, but I've had the Eight Pod for several months and would be willing to help however I can.

Support for local non-cloud connection

Is there any possibility of being able to bypass the eightsleep cloud entirely and instead interact directly with the sleep hub? Would be interested if anyone here has tried anything like this.

Did the new app update break things

Hey, there was an update to the app last week and I'm seeing a 404 when trying to set a temperature. I had not used the pyeight API before, so I'm not sure if it was working and doesn't work now because of the update

Error puting Eight data. 404, message='Not Found', url=URL(

Intermittent connection failures

I noticed that the eight component in homeassistant fails to connect most of the time.

After a bit of investigation, I changed the DEFAULT_TIMEOUT from 10 to 60 in constants.py and I haven't seen any issues since.

Parameters EightUser class

Hi,

I don't see which parameter this class needs. it is device = IP or device = "mattress" ? userid = email account ?
def init(self, device, userid, side):

Thanks for your help.
Laurent.

Bed Presence update

I am still seeing this intermittent problem on home assistant where all the data is updated except for the bed presence sensor turning off. It does not appear to be an API issue because as soon as I restart home assistant, the sensor turns off. Turning it on does not appear to be a problem either. It is very specific to getting the home assistant sensor to turn off when the API has it off.

'NoneType' object is not subscriptable

Got the following error when using this in HA. Not sure if you want this issue here or in the HA repo.

homeassistant    | 2021-09-20 11:57:43 ERROR (MainThread) [homeassistant.components.sensor] eight_sleep: Error on device update!
homeassistant    | Traceback (most recent call last):
homeassistant    |   File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
homeassistant    |     await entity.async_device_update(warning=False)
homeassistant    |   File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 633, in async_device_update
homeassistant    |     await task
homeassistant    |   File "/usr/src/homeassistant/homeassistant/components/eight_sleep/sensor.py", line 326, in async_update
homeassistant    |     temp = self._eight.room_temperature()
homeassistant    |   File "/usr/local/lib/python3.9/site-packages/pyeight/eight.py", line 195, in room_temperature
homeassistant    |     if obj.current_values['processing']:
homeassistant    |   File "/usr/local/lib/python3.9/site-packages/pyeight/user.py", line 407, in current_values
homeassistant    |     'date': self.current_session_date,
homeassistant    |   File "/usr/local/lib/python3.9/site-packages/pyeight/user.py", line 167, in current_session_date
homeassistant    |     date = self.intervals[0]['ts']
homeassistant    | TypeError: 'NoneType' object is not subscriptable

API and App data discrepancy

It looks like the sleep score value in the API response is different than what is in my app.

Example:
3/10/2023 | API: 73 | App: 92
3/9/2023 | API: 76 | App: 100
3/8/2023 | API: 73 | App: 88
3/7/2023 | API: 67 | App: 96
3/6/2023 | API: 73 | App: 93

Other data such as wake-up time is confirmed to be working, but be wary of sleep score and consider calculating your own.

API response example: example.txt

IMG_1641

Hope this helps,

Mckay

Feature Suggestion: Vibration Control for Pod Pro

So my Pod had a warranty issue, and they sent me the updated Pod Pro. The Pod Pro has the ability to wake you up by means of vibration. There is something that vibrates embedded into the mattress cover. This would be an amazing thing to be able to control with Home Assistant for important notifications when you're in bed.

Some API reversing discoveries:

I captured a bunch of traffic to the eight sleep api from the iOS app and figured I'd document it here, as there isn't a discussion area for this project.

Setting Temperature:

Temperature setting URL: https://client-api.8slp.net/v1/users/<user_id>/temperature
Guest temperature setting URL: https://client-api.8slp.net/v1/users/guest-<device_id>-<left|right>/temperature
Method: PUT
Request body to set smart schedule or weekly schedules, where heating level is an integer from -100 to 100:

{
  "settings": {
    "scheduleType": "smart",
    "timeBased": {
      "level": 0,
      "durationSeconds": 0
    },
    "smart": {
      "bedTimeLevel": <heating_level>,
      "initialSleepLevel": <heating_level>,
      "finalSleepLevel": <heating_level>
    },
    "schedules": []
  }
}

Request body to set heating/cooling level:

{
  "currentLevel": 91
}

Request body to turn power on or off, possible values are "off" or "smart". Potentially more values are supported as when the smart mode is started and in the bedtime state, the actual value returned for currentState is "smart:bedtime", so you can track which smart "phase" you are in that way.:

{
  "currentState": {
    "type": "<off|smart>"
  }
}

Changing sides/taking over bed

Change sides URL: https://client-api.8slp.net/v1/users/<user_id>
Method: PUT
Request body to change sides:

{
  "currentDevice": {
    "id": "<device_id>",
    "side": "<right | left | solo>"
  }
}

I don't have a linked partner account, as my partner doesn't like to use the app and just sets and forgets the guest account through my app. The way guests accounts work seems to be as follows:

Both sides of the bed always have a unique user ID, which follow the following template: guest-<device_id>-<left|right>. You can always use the same /temperature api for guests, but they are only enabled or have any effect when you user is set to the other side of the bed. So if you are set to the left side, all left guest settings will persist but have no effect, etc.

When the side is set to solo, neither guest temp setting endpoints have any effect.

Away mode

Away mode api url: https://app-api.8slp.net/v1/users/<user_id>/away-mode
Method: PUT
Request body to start away mode:

{
  "awayPeriod": {
    "start": "2023-06-14T03:01:00.000Z"
  }
}

Request body to end away mode:

{
  "awayPeriod": {
    "end": "2023-06-14T03:06:00.000Z"
  }
}

From my exploration I learned that the timestamps you send must be valid timestamps or else you get a validation error, but they are immediately ignored, sending any start timestamp seems to immediately start away mode and the returned awayPeriod start time is always just the time the request was received. Same goes for sending the request to end away mode, timestamp must be valid but is ignored and away mode is ended immediately with the end time set to the time the request was received.

initialization fails due to 403 when partner is not sharing data

I'm trying to set up my eight sleep pod with HA using the eight sleep integration.

my partner doesn't have the "share sleep data" toggle on so trying to access her user data fails with a 403. this appears to be unhandled which causes the initialization to fail.

homeassistant       | 2022-07-20 22:17:59 DEBUG (MainThread) [pyeight.eight] Initializing pyEight Version: 0.3.0
homeassistant       | 2022-07-20 22:17:59 DEBUG (MainThread) [pyeight.eight] UserID: d167cbc87fb54843b4edaaef219a4aec, Token: *****
homeassistant       | 2022-07-20 22:17:59 DEBUG (MainThread) [pyeight.eight] Devices: ['4000280018504e3157303520'], POD: True
homeassistant       | 2022-07-20 22:18:00 ERROR (MainThread) [pyeight.eight] Error geting Eight data. 403, message='Forbidden', url=URL('https://client-api.8slp.net/v1/users/e8b305971bb845af823cf94663bc42e3')

KeyError: 'rightUserId'

Hello,

I've had the following issue for about 2 months. I was hoping it would fix itself, but it hasn't. Any ideas?

Home Assistant(v0.90.2) Config:

eight_sleep:
    username: !secret eight_username
    password: !secret eight_password
    partner: false

Error:

Traceback (most recent call last):
  File "/usr/src/app/homeassistant/setup.py", line 151, in _async_setup_component
    hass, processed_config)
  File "/usr/src/app/homeassistant/components/eight_sleep/__init__.py", line 103, in async_setup
    success = await eight.start()
  File "/usr/local/lib/python3.7/site-packages/pyeight/eight.py", line 102, in start
    await self.assign_users()
  File "/usr/local/lib/python3.7/site-packages/pyeight/eight.py", line 149, in assign_users
    if data['result']['rightUserId'] == self._userid:
KeyError: 'rightUserId'

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.