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?
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.
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.
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)
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
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.
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?
@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
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.
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-{}'
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).
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.