lukas-clarke / eight_sleep

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

Bed State is always Unknown #50

Closed andrew-kennedy closed 1 month ago

andrew-kennedy commented 2 months ago

As of 1.0.15, I've noticed my Bed State, and all its attributes, are always unknown. This means I have no way to read the target heating level of the bed, though I'm still able to set it. Not seeing any error messages, but I haven't had time to go enable debug logging.

akaplan07 commented 2 months ago

Where are you looking at the data? You may need to switch the target entity.

One of the recent changes may have caused your home assistant to create a new entity. Looking at the old one will show unknown data. See if there is a different entity with valid data.

akaplan07 commented 2 months ago

I may have misunderstood your question to mean that you couldn't see any attributes. I'm seeing bed state as Unknown as well. All the other sensors like bed temperature and HRV are working for me.

lukas-clarke commented 1 month ago

Bed State is still updating for me. @andrew-kennedy, I'm curious if your account is being served a different version of the API

andrew-kennedy commented 1 month ago

Hmm, can you remind me which endpoints are in use for that state so I can audit them? I'll take another traffic capture.

lukas-clarke commented 1 month ago

@andrew-kennedy It's pulling from the heating_level: `@property def heating_level(self) -> int | None: """Return heating/cooling level.""" level = self.device.device_data.get(f"{self.side}HeatingLevel")

Update observed low

    if level is not None and level < self.observed_low:
        self.observed_low = level
    return level`

This boils down to being the first dictionary in the list returned from the url f"{CLIENT_API_URL}/devices/{self.device_id}" The key for this dictionary that is being used here is f"{self.side}HeatingLevel"

andrew-kennedy commented 1 month ago
{
  "result": {
    "deviceId": "redacted",
    "ownerId": "<redacted>",
    "leftUserId": "<redacted>",
    "leftHeatingLevel": -33,
    "leftTargetHeatingLevel": 0,
    "leftNowHeating": false,
    "leftHeatingDuration": 0,
    "leftSchedule": {
      "daysUTC": {
        "sunday": false,
        "monday": false,
        "tuesday": false,
        "wednesday": false,
        "thursday": false,
        "friday": false,
        "saturday": false
      },
      "enabled": false
    },
    "rightUserId": "redacted",
    "rightHeatingLevel": -33,
    "rightTargetHeatingLevel": 0,
    "rightNowHeating": false,
    "rightHeatingDuration": 0,
    "rightSchedule": {
      "daysUTC": {
        "sunday": false,
        "monday": false,
        "tuesday": false,
        "wednesday": false,
        "thursday": false,
        "friday": false,
        "saturday": false
      },
      "enabled": false
    },
    "priming": false,
    "lastLowWater": "2024-07-26T20:38:51.800Z",
    "needsPriming": false,
    "hasWater": true,
    "ledBrightnessLevel": 15,
    "sensorInfo": {
      "label": "20600-0003-F00-00012C1D",
      "partNumber": "20600",
      "sku": "0003",
      "hwRevision": "F00",
      "serialNumber": "redacted",
      "lastConnected": "2024-09-17T08:04:02.423Z",
      "skuName": "caking",
      "connected": true
    },
    "timezone": "America/Los_Angeles",
    "mattressInfo": {
      "firstUsedDate": null,
      "eightMattress": null,
      "brand": null
    },
    "firmwareCommit": "026334eb083095a6450edbf3d7c046b802b4280b",
    "firmwareVersion": "026334e",
    "firmwareUpdated": true,
    "firmwareUpdating": false,
    "lastFirmwareUpdateStart": "1970-01-01T00:00:00.000+00:00",
    "lastHeard": "2024-09-17T08:05:45.244Z",
    "online": true,
    "encasementType": null,
    "leftKelvin": {
      "targetLevels": [
        -21,
        -21,
        -21
      ],
      "alarms": [],
      "scheduleProfiles": [],
      "phases": [],
      "level": 0,
      "currentTargetLevel": 0,
      "active": false,
      "currentActivity": "off"
    },
    "rightKelvin": {
      "targetLevels": [
        -21,
        -21,
        -21
      ],
      "alarms": [],
      "scheduleProfiles": [],
      "phases": [],
      "level": 0,
      "currentTargetLevel": 0,
      "active": false,
      "currentActivity": "off"
    },
    "features": [
      "warming",
      "cooling",
      "vibration",
      "alarms"
    ],
    "leftUserInvitationPending": false,
    "rightUserInvitationPending": false,
    "modelString": "Pod 3",
    "lastPrime": "2024-04-24T21:03:33.000Z",
    "isTemperatureAvailable": true,
    "deactivated": {}
  }
}

This is what I see returned from that API when I do a traffic capture.

andrew-kennedy commented 1 month ago

I'm wondering if the side names are somehow wrong and being interpolated into incorrect keys or something...

lukas-clarke commented 1 month ago

So looking at the code, if you setup the integration while your bed was in away mode the self.side key wouldn't ever update when you assigned yourself to a bed side. This could cause the key for the json data to be misformatted. Creating a release to fix this, which I'm guessing may be your issue.

lukas-clarke commented 1 month ago

Closing this, since I believe the latest releases fixed the issue.