vmiklos / plees-tracker

Plees Tracker is a simple sleep tracker for your Android phone.
https://vmiklos.hu/plees-tracker/
MIT License
151 stars 38 forks source link

[feature request] sleep cycle based alarm #351

Open J4gQBqqR opened 1 year ago

J4gQBqqR commented 1 year ago

Would you consider adding a sleep cycle based alarm clock?

Not sure if this repo accepts feature request or this feature is out of scope of the app. If this is the case, please close the issue.

vmiklos commented 1 year ago

Feature requests are fine, don't worry. :-)

Would this be about something like: my preferred sleep length is 8 hours, I'm awake for 16 hours, alarm to signal it's time to go to bed?

J4gQBqqR commented 1 year ago

This feature would be like, I would like to wake up at around 6 am, no later than 7 am, no earlier than 5:45 am.

Please detect my sleep cycle and wake me up (alarm clock actually) while I am in the shallowest sleep cycle, better to be around 6 am instead of the middle time point of 5:45 and 7 (which is 6:23 am). If I keep sleeping until 7 am, wake me up no matter what.

J4gQBqqR commented 1 year ago

This would definitely require some historical statics on sleep cycle to define what level of sensor response is "shallowest sleep cycle". Then I can imagine using a very basic hypothesis testing based on the mean and variance to predict/detect/verify sleep cycle and trigger the alarm clock based on the set time frame.

If the "around 6 am" requirement is too hard to configure, this feature request can also be relaxed to, "I would like to wake up between 5:45 and 7am. Please wake me up gentally while I am not in deep sleep."

vmiklos commented 1 year ago

Ah, I see. Fine. I have no plans to implement something like this myself, but let's keep it open, I'm not against a PR that does this. I'm more interested in the "timer that counts average" piece. :-)

Mrnofish commented 1 year ago

Pretty much you need some way to track the user's movements, either through a wearable device, or another sleep tracking device of some kind.

While a number of devices exist on the market for this very purpose, some of which are easier to interface with and others definitely less, the phone itself can be turned into a sleep tracking device using some cleverness:

  1. apps used to instruct the user to place their smartphone under the pillow or otherwise in their bed, and then use the accelerometers and/or other sensors to track the user movevments. I'm not sure how popular is this anymore, TBH, last time I tried it was definitely not very accurate, it had some significant potential drawbacks, and probably has fallen out of fashion, now that wearables are a dime a dozen.

  2. Urbandroid came up with a "sonar" function that uses the phone's microphones and speakers as a sonic radar.

Implementing an actigraph and interfacing with the devices is not exactly a walk in the park and definitely not a small amount of work.

RageGamerBoi commented 1 year ago

Would this be about something like: my preferred sleep length is 8 hours, I'm awake for 16 hours, alarm to signal it's time to go to bed?

Maybe this is a better idea, just to keep it simple.

If you integrate this with a built-in alarm with a slow volume increase + vibration, snooze button customization/limiter, and maybe that increasing screen brightness trick, it might be almost as good.

derkrasseleo commented 1 month ago

There is also the approach of SleepCycle, which essentially just listens for movement noise, which they replaced the accelerometer method with. The question is if this feature goes too far for this app when the goal (at least according to the website) is to not drain battery..

vmiklos commented 1 month ago

It does go too far if this happens by default. If somebody wants to add this in a way that you need to explicitly opt in, that may be OK.