lukas-clarke / eight_sleep

Home Assistant Eight Sleep integration that works with Eight Sleep's new API and OAUTH2
MIT License
62 stars 11 forks source link

add GET for /v1/users/{self.user_id}/temperature to pyEight #9

Closed keatontaylor closed 6 months ago

keatontaylor commented 7 months ago

When calling /v1/users/{self.user_id}/temperature via a GET call it returns the current smart state of the mattress.

{
  "currentLevel": 0,
  "currentDeviceLevel": -51,
  "currentState": {
    "type": "off",
    "instance": {
      "timestamp": "2023-11-27T13:37:55Z"
    }
  },
  "scheduleType": "smart",
  "smart": {
    "bedTimeLevel": 0,
    "initialSleepLevel": 0,
    "finalSleepLevel": 0
  },
  "timeBased": {
    "level": -10,
    "durationSeconds": 28800
  }
}

['currentState']['type'] represents the state of the mattress as seen in the 8-sleep app for the schedule. With the following options:

off = when the mattress side is completely off smart:bedtime = when the mattress is precooling or preheating for the selected bedtime (begins one hour before bedtime) smart:initial = when the mattress has detected the person on this bedside has fallen asleep (lasts for 4 hrs) smart:final = after the 4 hr window the mattress goes into the temperature set in the "final" stage in the app (stays in this stage until alarm or off) alarm = 1 hr prior to the alarm time the app to begin heating and cooling the bed to the alarm temp.

Integrating this into the attributes for the mattress side state would allow automations to key off of the 4 phases that can be set in the 8-sleep app. Such as setting the lights to a lower brightness when the smart:bedtime state is detected, or opening the blinds after 30 mins when the alarm state is detected.

lukas-clarke commented 7 months ago

Thanks for looking into the API. I'm traveling for a week, so likely won't be able to implement this until end of next week.

I'm guessing an option for currentState should also be "away"?

Also, have you found any way this updates based on bed presence?

keatontaylor commented 7 months ago

Not sure what you mean by your question currentState should ask be away?

However, for the second question as far as I can tell the bed presence is not reported directly in the API and I do not see any values that would help determine if the bed actually has someone in it besides getting sleep data (light, rem, deep) from the trends.

lukas-clarke commented 7 months ago

Edited my comment for clarity: * "also be away"

keatontaylor commented 7 months ago

Ah not 100% sure, I think when you put the mattress side into away mode if say you're on vacation it does not return any values for the user ID calls.

lukas-clarke commented 6 months ago

Addressed in latest release.