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

Enhancement request - Setting / updating alarm time #19

Open Dorusvandenoord opened 8 months ago

Dorusvandenoord commented 8 months ago

Since you recently added the 'Alarm Snooze' and 'Alarm Stop' and you can already read the 'Next Alarm', I'm wondering if it's possible to update existing alarm times from the API, or add new alarm times?

Context: I currently use Apple Health bedtime to set my alarm time, which syncs up to Home Assistant to trigger all morning automation at the right time. Would be awesome if I could automate my Eight Sleep alarm time to sync up. (and maybe even set the Eightsleep bedtime when it turns on, although I personally wouldn't use that).

Awesome work on this custom integration! Love the active development and frequent updates! 🙌🏼

lukas-clarke commented 8 months ago

Hey, I looked into this and it seems like it would be quite difficult to find an intuitive way to implement it without a UI. When a routine gets created, is has a UID, so if you want to update it you have to include the UID in the API call.

With a UI (such as in the app) it's easier because all your routines are shown, and it knows which UID to include in the API call depending on which routine you click on. But from a HA service setup, it's not feasible for someone to include a UID in one of the fields. It would be possible to pull all the routines and expose their data, along with their UIDs in HA. Then the service call could use this data. However, that would take a lot of time to develop and would have a lot of possible issues due to the number of fields now possible with routines.

Dorusvandenoord commented 8 months ago

Ah yes, that makes sense, unfortunately.

I also have a Philips Somneo smart wake-up light, that (unofficial) Home Assistant integration just shows you 15 alarm slots each with 4-5 settings. It works for me, I just have the first alarm always synced, but it's a mess in HA and clunky.

I'm not sure if the routine UID changes? I assume it doesn't. You could one time manually figure out the UID, (or show a dropdown of all available values), and then have just 1-2 routine fields which you can sync with Home assistant. It's not perfect. Deleting the routine in 8 Sleep would stop it work, you can't edit or turn off new routines created through the app. And if you want multiples routines in HA you need to change the existing routine rather than creating separate ones.

But if you stick with just 1-2 routines in the app and have Home Assistant (or use app to) change them it should keep working?

Another idea could even be to view each routine as a separate 'alarm clock' device in HA, just like each bedside is its own device. It could auto add / delete those devices based on the available routines in Eight Sleep. It would still be messy to find the right one in HA probably because they don't have names, but probably you only need to do that once in a while if you make a change to your routines.

Maybe if I have time in the future I'll try working on it myself if I can get the API call data from the app using Proxyman.

Dallas-J commented 7 months ago

I hacked in a way to do this to my personal fork a while ago if you want a starting point. I spent a few days thinking about how to create a proper interface that could get merged back in, but it didn't really seem feasible without some major custom GUI work.

Anyway, you can check it out here: https://github.com/Dallas-J/eight_sleep

marbemac commented 3 weeks ago

Any chance there is a way to trigger a one-off alarm as part of an automation? Say for example the dog is waiting by the front door in the middle of the night - a motion sensor picks that up and vibrates the bed to wake up one of the partners in the bed. No UI needed for this one I think? Since the use case is basically just wanting to trigger a wake up right now in response to another trigger.