Eight Sleep component

Thank you!

Hi,

I like to automate a few things to the bed presence but it is really unreliable for me. Are you experiencing the same? Usually, the state of this sensor only updates 30-60 minutes (or even more) after I wake up or go to bed.

“binary_sensor.eight_left_bed_presence”

Thank you!

Bed presence detection is based on the state value obtained from the api. It’s fetched once per minute and should detect getting into bed within 5 minutes or so in my experience. Getting out of bed is trickier because of the sample rate and wanting to make sure the user is actually out of bed and not a sleep fluctuation.

In any case 30-60 minutes is much longer than you should be seeing. Do you see a good data stream for the bed state? Something like the screenshot below.

image

This is what I can see in the history for the right and left bed state sensor, My state is the brown line the green is my wife. I wake up at 7 AM and the sleep state score fall from 70 to 17 in like 2 hours… Seems to be your data almost immediately fall once you out of bed for me it is slowly falling under 1-2 hours.

I’m afraid that if that’s typical behavior for you there isn’t much I can do since the api only provides access to the temperature information. Does the eight app figure out you’re out of bed more quickly? I can probably add a condition into the bed state processing to base it off of the temperature information and whether or not eight is still processing the data. In my original testing the processing went on well beyond the temperature data providing an indication so I never bothered with it.

Out of curiousity, can two sleep trackers (2 different beds) be used in HA? Or is this limited to 1 account?

Hi,

Is there any way to create a script which heat the bed to X if the bed temperature is below Y and heat it to Z if the bed temperature is below N, but above X? Do not heat if the bed temperature is above N.

I am thinking about something like this (do not laugh on it, I am just a enthusiastic beginner :slight_smile: ) probably this is far from a working solution… THANK YOU!

- service_template: >
    {% if sensor.eight_right_bed_temperature < 32 %}
    data:
      entity_id: "sensor.eight_left_bed_state"
      target: 100
      duration: 1800
    {% elif sensor.eight_right_bed_temperature < 34 %}
    data:
      entity_id: "sensor.eight_left_bed_state"
      target: 50
      duration: 1800          
    {% endif %}
  entity_id: eight_sleep.heat_set

The goal is to call the script with my good night routine and heat up the bed for 30 minutes if needed, but do not heat it if it is already too warm (because it is warm in the room).

it’s a good concept and something that I would use. I even thought of it, but couldn’t figure out an approach.
For now though, I’ll have to wait, I’ve been having an issue with my Eight Sleep for the past 3 months. Their team is looking into it, I’ve already replaced 3 hubs with no luck. My current Bed Temperature shows “- 558 F” … and that I’ve slept for over 22 hours.

Please keep us posted if you think that this works.
I’ve also thought of writing something for the summer time months calculating the difference in temperature between the room (from the hub readings) and the outside temp. And start a window fan if the outside could help cool my bedroom.

@tiszavolgyi This is interesting and certainly doable. Would you want it to only do it at a certain time each day or monitor throughout the night?

@Jer78 - I would implement this into multiple scripts I have which scripts I call with automations. E.g. when I say “good night” to Alexa all of the lights turn off, nest thermostat set to lower temp etc. + I would like to heat the bed if needed for 30 minutes. If the bed kind of warm (because of the room temp) then I want to heat only a little, if too warm than do not heat at all.

It is also a good idea to monitor it during the night. On colder winter nights I can see the comfort of it. But that part should be easier. I would write an automation with a condition. If the bed temp is too low then heat for 30 min. I will try this sometime soon and share if it works.

I’ll post something too when I get a chance. I’ll use some input_numbers so the temp can be configured.

I still could not solve my original question but for @Jer78 idea here is a working solution:

  1. Create the following script, which turns on the bed heating for 30 minutes:
heat_peter_bed_for_30_min:
  sequence:
    - service: eight_sleep.heat_set
      data:
        entity_id: "sensor.eight_left_bed_state"
        target: 100
        duration: 1800
  1. and an automation which checks if the bed is occupied and the temp is below X:
  - alias: "Peter Bed Heating at Night"
    trigger:
      - platform: numeric_state
        entity_id: sensor.eight_left_bed_temperature
        below: 30
    condition:
      - condition: state
        entity_id: binary_sensor.eight_left_bed_presence
        state: 'on'
    action:
      service: script.turn_on
      entity_id: script.heat_peter_bed_for_30_min

You can check out the entire code here:

1 Like

@tiszavolgyi Here’s my take at it. Haven’t tried it yet but this should allow you to customize the settings. It checks every hour if there’s a bed presence and warms if the bed is cooler than the threshold set in the input_boolean to a configurable time in mins and temperature.

Input Numbers:

  eight_left_bed_temperature_threshold:
    name: Eight Left Temp Threshold
    icon: mdi:hotel
    unit_of_measurement: '°C'
    min: 27
    max: 40
    step: 0.1
  eight_left_heat_run_temp:
    icon: mdi:thermometer
    unit_of_measurement: '%'
    min: 10
    max: 100
    step: 10
  eight_left_heat_run_minutes:
    icon: mdi:clock
    unit_of_measurement: 'mins'
    min: 5
    max: 55
    step: 5

Group:

  night_eight_settings:
    view: no
    name: "Eight Sleep Settings"
    entities:
      - binary_sensor.eight_left_bed_presence
      - sensor.eight_left_bed_temperature
      - input_number.eight_left_bed_temperature_threshold
      - input_number.eight_left_heat_run_temp
      - input_number.eight_left_heat_run_minutes

Automation:

  - alias: 'Check Bed Temp every hour and adjust'
    initial_state: on
    trigger:
      platform: time
      hours: '/1'
      minutes: '0'
      seconds: '0'
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: binary_sensor.eight_left_bed_presence
          state: 'on'
        - condition: template
          value_template: '{% if (states.sensor.eight_left_bed_temperature.state|float) < (states.input_number.eight_left_bed_temperature_threshold.state|float)%}true{%endif%}'
    action:
      - service: eight_sleep.heat_set
        data_template:
          entity_id: sensor.eight_left_bed_state
          target: '{{ states.input_number.eight_left_heat_run_temp.state | int }}'
          duration: '{{ states.input_number.eight_left_heat_run_minutes.state | int * 60}}'
1 Like

On the released 0.67.0 I have notices that some of the attributes names have blank spaces which are causing problems with the API. Probably would be good to replace the blank spaces " "with underscores "".
For example: Deep Sleep % should be Deep_Sleep
%.

@mezz64 I had to reload HA but can’t seem to get the Eight Component to load anymore. Any ideas?

2018-05-14 15:52:34 ERROR (MainThread) [pyeight.eight] Error posting Eight data. Cannot connect to host app-api.8slp.net:443 ssl:True [[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)]
2018-05-14 15:52:34 ERROR (MainThread) [pyeight.eight] Unable to authenticate and fetch eight token.
2018-05-14 15:52:34 ERROR (MainThread) [homeassistant.setup] Setup failed for eight_sleep: Component failed to initialize.

I’m seeing some issues as well on my end. I’ll try to make some time to work through it tonight to see what’s going on. I did a few tests against the api and all seems OK from a response standpoint so they may have changed some return points or something.

Ok good to know it’s not just me. Hopefully it won’t be too much work to fix though. Let me know if you need any help testing.

I tracked my problems down to some empty fields in the api response (a fluke in the data processing), I was not having connection issues like you posted.

There have been some api slowdowns over the past couple days. Are you still having authentication problems?

@mezz64

Yes still having problems, which version of Python are you using? When I was on 3.5 it was working fine and when I installed 3.6 I started having problems. It may just be an issue with Python. Is there any dependencies that I need to force an install?

I doubt it’s the python version, I use 3.6 without issues. The only dependency that is related is aiohttp, but since that package is also required by the hass core you should be using an appropriate version.

What base OS are you running home assistant on?