Custom Componenet: Oura Ring sleep data sensor

Support for HACS seems to be ready :slight_smile: @Jamie_Pryer @adrkable

I finally managed to install this component via HACS. However, HA log tells that “Oura API was unable to retrieve new API token.” and points to custom_components/oura/api.py:69. I can see data inside hass-config/oura-token-cache-sleep_quality file. Something like this.

{"code": "my_secret_token"}

I tried to HA restart couple of times and updated entity using HA services menu but did solve my problem. Something more I could try?

Hi @villevirtanen

Can you paste your configuration? Did you follow the steps on GitHub to configure and install it?

Well, one more time I deleted the token file, reinstalled custom component, deleted old app from Oura web page, re-created new app etc. And boom, it started to work. I have no idea what was wrong earlier.

Anyway, great that this works now. Thanks!

Happy to hear :slight_smile: Enjoy the data!

1 Like

Just a quick FYI, I am strongly considering removing HACS support for this custom_component as a protest to this. If it stops working, feel free to integrate manually.

HACS support now fully reverted in protest for the bad direction of the Home-Asisstant project. You can still install the code through manual install from GitHub.

1 Like

Thanks for this, got it working.
First I didn’t have base_url setting because documentation says its not used any more, but then realized it was just removed and I have older version.

Then I had problem that token file couldn’t be written to disk. I tried to debug that, but eventually hardcoded the file path to /home/pi/.homeassistant and it worked.

In Oura developer page you also have to give permission Allow server-side authentication (grant-type code)

1 Like

Hi @nitobuendia

Is it possible to get component working with Home Assistant v 0.114.0, where base_url is deprecated?

Got this error to log every time when trying to get retrieve data:

2020-08-25 19:25:45 WARNING (SyncWorker_2) [homeassistant.components.http] Detected use of deprecated `base_url` property, use `homeassistant.helpers.network.get_url` method instead. Please report issue to the custom component author for oura using this method at custom_components/oura/api.py, line 236: base_url = self._sensor._hass.config.api.base_url

2020-08-25 19:25:45 ERROR (SyncWorker_2) [root] Oura API was unable to retrieve new API token.

2020-08-25 19:25:45 ERROR (SyncWorker_2) [root] Couldn't fetch data for Oura ring sensor

Hi @MarkoMarjamaa @tonfa80

Thanks both for reporting issues.

For the base_url, for a while I stopped updating my system due to the deprecation of YAML and never got the change myself. However, now that I’ve solved that and updating, I am happy to check to solve it. The migration is pretty straightforward as it just requires changing the base_url for a helper function. However, I would love to try making it compatible to as many versions; so that’s a bit of extra overhead. Would you mind opening an issue and I can take a look?

For the “Oura API was unable to retrieve new API token.”; sometimes this happens on the first load and fixes it afterwards. I’ve never been able to determine when the bug happens, but it never affected me. However, @MarkoMarjamaa your issue seems a bit different, if you can replicate, I can try to see if I can solve that as I haven’t experienced that and it feels like not working as intended.

Thank you!

I also get following oura_token_cache file to home assistant directory but after that those errors appear
{"code": "ABC123DEF456GHI789ABC123DEF456GHI1"}
and after that those warning/error combination in log. I though this would be due to version 0.144.0 and not supporting base_url parameter anymore?

I’ll open new issue for this.

@tonfa80 @MarkoMarjamaa I have fixed the base_url issue (#2). Thanks for reporting. I’ve tested on 0.109.6 and last version (as of today) and it worked on both. Nonetheless, if you want to test it out, feel free to do so :slight_smile:

Also, it seems you both mentioned other issues. If you still find some, feel free to report to github and I am happy to have a look.

Cheers,
Nito

2 Likes

Hey there,

Thanks for the custom component.
I am unfortunately unable to get the token

I am pretty sure i got through your documentation numerous time, my home assistant is hosted on cloudflare so i dont have to put a port number.

Just wondering if i should be selecting the following when i create an app on oura

Allow server-side authentication (grant-type code)
Allow client-side authentication (grant-type token)

Thanks

At least I couldn’t store the retrieved token file info into the custom_components/oura directory with my current configuration. Therefore I did what was mentioned earlier (I believe) and added a full path to hass users’s home directory in the custom_components/oura/api.py:

_TOKEN_FILE = '<add here full path to hass users home>/oura-token-cache-{}'

Or whatever works for you.

2 Likes

Thanks it works, upon going through this thread i found that this was critical during the setup

In Oura developer page you also have to give permission Allow server-side authentication (grant-type code)

1 Like

I changed all of my token files to always be on the same data/ directory. Perhaps why I didn’t see any issues. If this is failing for everyone, if you could share steps to reproduce, I can try.

The .storage files remove the issue of having them around (although they still centralize the data in those files, though).

Is that step missing in the documentation? If yes, do you want to create an issue to add it on GitHub? Thanks!

1 Like

Ok, it looks like there should be a line or two in readme that mentions that you should modify the token_file directory path to some directory under home-assistant account, otherwise the initial oura app authorization will not work as the token cache cannot be written to a local file.

I can create the issue, just not right now (too tired at the moment).

However, I was also unable to get any sensors created using the “Xd_ago” style as those sensor lines all fail the Home Assistant syntax check for some reason. The “yesterday/monday/etc etc” is fine, but whenever I try to to use the “2d_ago” or “2days_ago” it will not pass the syntax check and whenever I can make it pass, the value will be “unknown” —> I haven’t yet figured out how this is supposed to work or is there a bug somewhere.

I’d like to get some statistics showing current day, yesterday and a few days backwards from the current moment in order to get some visual graphs about the current trend.

When I click on the link in notification and click on Accept I get.

500 Internal Server Error
Server got itself in trouble

Any ideas?

No ideas, really?