nitobuendia / oura-custom-component

Oura Custom Component for Home-Assistant. Adds Oura Ring sleep information.
108 stars 25 forks source link

Unable to get the integration to work #28

Closed phillcoxon closed 1 year ago

phillcoxon commented 1 year ago

Hi there.

I've spent many hours trying to get this integration to work without success. I'm fully out of ideas as to what is going wrong and would be extremely grateful for any feedback and suggestions.

# Loads default set of integrations. Do not remove.
default_config:

################################################################################
# Oura Ring: Sleep data.
################################################################################

- platform: oura
  name: sleep_quality
  access_token: **TOKEN**
  scan_interval: 7200
  sensors:
    sleep:
      name: oura_sleep_metrics
      max_backfill: 0
      monitored_dates:
        - 0d_ago
        - 1d_ago
        - 7d_ago 
    sleep_periods:
      name: oura_sleep_periods
      max_backfill: 0
      monitored_dates:
        - 0d_ago
        - 1d_ago
        - 7d_ago       
    sleep_score:
      name: oura_sleep_score
      max_backfill: 0 
      monitored_dates:
        - 0d_ago
        - 1d_ago
        - 7d_ago
    activity: {}
    heart_rate: {}
    readiness: {}
    workouts: {}     
% curl --location --request GET 'https://api.ouraring.com/v2/usercollection/sleep?start_date=2023-01-01&end_date=2023-01-14' \
--header 'Authorization: Bearer **TOKEN**'
{"data":[{"average_breath":15.75,"average_heart_rate":60.125,"average_hrv":24,"awake_time":5430,"bedtime_end":"2023-01-02T07:32:02+13:00","bedtime_start":"2023-01-02T00:15:02+13:00","day":"2023-01-02","deep_sleep_duration":4950,"efficiency":79 [...]

Here's the list of files in config/custom_components/oura:

ls -l  config/custom_components/oura

total 84
-rw-r--r--    1 root     root            30 Jan 15 21:37 __init__.py
-rw-r--r--    1 root     root          3039 Jan 15 21:37 api.py
drwxr-xr-x    2 root     root          4096 Jan 15 21:37 helpers
-rw-r--r--    1 root     root           309 Jan 15 21:37 manifest.json
-rw-r--r--    1 root     root          2959 Jan 15 21:37 sensor.py
-rw-r--r--    1 root     root          3048 Jan 15 21:37 sensor_activity.py
-rw-r--r--    1 root     root         18688 Jan 15 21:37 sensor_base.py
-rw-r--r--    1 root     root          3201 Jan 15 21:37 sensor_bedtime.py
-rw-r--r--    1 root     root          3320 Jan 15 21:37 sensor_heart_rate.py
-rw-r--r--    1 root     root          2789 Jan 15 21:37 sensor_readiness.py
-rw-r--r--    1 root     root          2050 Jan 15 21:37 sensor_sessions.py
-rw-r--r--    1 root     root          5015 Jan 15 21:37 sensor_sleep.py
-rw-r--r--    1 root     root          4542 Jan 15 21:37 sensor_sleep_periods.py
-rw-r--r--    1 root     root          2483 Jan 15 21:37 sensor_sleep_score.py
-rw-r--r--    1 root     root          2011 Jan 15 21:37 sensor_workouts.py

Any suggestions on what I'm doing wrong here?

Thanks in advance!

nitobuendia commented 1 year ago

Hi @phillcoxon - without logs is very hard to know specially without being able to reproduce the issue. However, throwing a couple of ideas:

--

1) Checking your configuration, it seems to be missing the sensor: key before setting up the overall oura sensor. Not sure if it's missing because it's cut, but making sure.

default_config:

sensor:
  - platform: oura
    name: sleep_quality
    access_token: **TOKEN**
    scan_interval: 7200
    sensors:
      sleep:
        name: oura_sleep_metrics
        max_backfill: 0
        monitored_dates:
          - 0d_ago
          - 1d_ago
          - 7d_ago 
      sleep_periods:
        name: oura_sleep_periods
        max_backfill: 0
        monitored_dates:
          - 0d_ago
          - 1d_ago
          - 7d_ago       
      sleep_score:
        name: oura_sleep_score
        max_backfill: 0 
        monitored_dates:
          - 0d_ago
          - 1d_ago
          - 7d_ago
      activity: {}
      heart_rate: {}
      readiness: {}
      workouts: {}     

Can you kindly confirm that this is not the issue?


2) When you did the API call, did you find data for January 14th (2023-01-14) and/or January 15th (2023-01-15)? The example you gave it only has 2023-01-02 on it, but I see the [...] indicating that perhaps we have more recent data.


3) If none of the above is the issue, the only thing I can think of is to enable more logs by configuring the logger component on your configuration.yaml. I don't recall the exact syntax, but I think this would help:

logger:
  default: info
  logs:
    homeassistant.custom_components.oura: debug
    custom_components.oura: debug
phillcoxon commented 1 year ago

And there it is! Thank you!

I did wonder if it would be something really simple that I was missing - I didn't have the sensor: in front of the config.

As a new person to Home Assistant this wasn't obvious. I had wondered if something was supposed to be in front but none of the config examples in this GitHub repo or the HA community thread included it. I had tried using oura: in my various config attempts but hadn't thought to try sensor:.

Can I suggest the documentation be updated to include sensor: ahead of the configuration example, or have a note to say the Oura configuration goes in the sensor: section of the configuration file?

Thank you so much for your help.

phillcoxon commented 1 year ago

With regard to question 2: I used [...] to indicate there was a larger response but I had trimmed it for brevity.

nitobuendia commented 1 year ago

Thank you @phillcoxon - glad to know this solved your issue. I have improved the documentation as per your suggestion. I hope it's clearer now :)