mezz64 / pyEight

Python library to interface with the Eight Sleep API
MIT License
59 stars 15 forks source link

Home Assistant #1

Closed jer78 closed 7 years ago

jer78 commented 7 years ago

Hi, I just came across this. Any chance you can integrate with Home Assistant? www.home-assistant.io

mezz64 commented 7 years ago

That's the end goal. It's being written with home assistant in mind.

Just started working on it so it'll be a couple weeks at least until it gets that far. The API is a little limited so i'd be interested in what types of use cases you were hoping to get out of it.

jer78 commented 7 years ago

That's awesome! Looking forward to it. My goal is to learn Python so I can do the same thing one day. ;)

What does the API now provide? I noticed there's a smartthings integration (unofficial of course) that has sleep score, warming etc.

My use cases would be the following:

  1. I have an alarm within Home Assistant that wakes me up with a tts of my daily activities. I would integrate the last nights sleep score (for both my wife and I) and/or hours of sleep.
  2. Delay the alarm by up to 15 minutes if it senses I'm in a deep sleep vs. light sleep. (this would be really cool if it was possible)
  3. If I'm home, turn on the bed warming. I'd rather not use the auto timer in the app, because if I'm not at home there's no sense turn it on.

Thanks again for working on this!!

mezz64 commented 7 years ago

1 and 3 are definitely possible, 2 is a maybe. Right now the api only reports certain things on an hourly basis once it determines someone is actually in the bed so it's easy to get the deep sleep data after the fact, but harder to get it in real-time.

The smartthings integration was what motivated me to get started on this without the official API being available. There are some neat things in there in terms of using the bed heating level (one of the few things that can be requested in real-time) to determine bed presence that I plan to work into the python library also.

jer78 commented 7 years ago

Awesome!! So for #2, would there be a way to pull data at a certain time? For instance, if my alarm is set to go off, could a script in Home Assistant request an update? Or do you mean, Eight Sleep doesn't actually even know until an hour after the fact because it pushes the data every hour? Somehow Eight Sleep uses it for their "Smart Alarm" in real-time. But maybe they don't expose it to their API?

mezz64 commented 7 years ago

The intervals api endpoint does report what it thinks the current sleep state is and how long you've been in that state. Problem is that data is very dynamic while you are sleeping because of the way it's processed, so you could query it and it might say light sleep one minute and then update that past state to deep sleep once it processes more data the next time you query it.

mezz64 commented 7 years ago

First implementation of this has been merged into home assistant. Closing this...