nitobuendia / oura-custom-component

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

[Feature Request] Your bedtime tonight #14

Closed marcoleder closed 1 year ago

marcoleder commented 2 years ago

Hey there :)

Great work, I think including the ideal bedtime start and end times would be a very welcomed enhancement. This would allow users who struggle to go to bed at the right time to for example dim the lights when their ideal bedtime starts so they are reminded to go to bed, etc...

I would absolutely LOVE to see this feature!

Best regards Marco Leder

nitobuendia commented 2 years ago

Hi @MarcoLeder - thanks a lot for the feedback and the request.

Is the ideal bed time currently available on Oura? In what section?

Thanks!

marcoleder commented 2 years ago

Dear @nitobuendia

I just spent the whole morning implementing this feature directly in home assistant and it works flawlessly. I created a sensor that does direct calls to the API, extracts the optimal bedtime start&end for the current day, and then fills a helper variable with the timestamps. These helper variables can then be used for automation.

The ideal bedtime is available on Oura https://cloud.ouraring.com/docs/bedtime and can be called (I found this the easiest way) by including the access token in the URL parameter according to this description https://cloud.ouraring.com/docs/authentication#oauth2-using-the-access-token

Example call: https://api.ouraring.com/v1/bedtime?access_token=ACCESSTOKEN

I really hope that this description helps - it should give you all the data you need for implementing this in your oura component.

All the best, Marco

nitobuendia commented 2 years ago

Thanks, @MarcoLeder, this is clear. Thanks for sharing the endpoint. I never paid that much attention to this before on the app, but it does look interesting for automation purposes.

Since it's a new endpoint, this would require the same level of refactoring that #10 needs (except it would be for bedtime instead of readiness and/or activity). You may want to read there the requirements and why it wouldn't be straightforward at the moment, but definitely a good addition to the project.

nitobuendia commented 1 year ago

I have started the work to bump the API version to v2 (#15) and also do the changes mentioned in comment 4 to support more sensors/endpoints. Once these are ready, I will probably be adding all the endpoints available on the API documentation.

@marcoleder Do you know if the bedtime endpoint or data point exists on v2? I was not able to find it doing a quick search. Based on this, it might still be coming.

nitobuendia commented 1 year ago

While this is not available on V2 of the API, it seems with the current code structure it is quite straightforward to add V1 endpoints too. I am looking into it.

nitobuendia commented 1 year ago

@marcoleder The bedtime sensor has been implemented on the oura-v2 branch. I am not very clear on for which days this generates data, but I can see some data if add multiple days (not yesterday).

If you could try testing the code and see if it does what you needed, check how easy it is to install, and report any issues - I would highly appreciate it.

As I said, I have tested it and it seems to work for me. However, do note that I am still adding commits to that branch, so it could be broken at times (if I push a wrong commit).

I am not marking this as fixed yet until I merge the code into the main branch.