[GUIDE][Difficulty: Advanced] Custom Sleep Timer for any Audio App

1,034 posts
Thanks Meter: 2,137
By MishaalRahman, Editor in Chief on 10th March 2016, 06:40 AM
Post Reply Email Thread
Sleep timers are a pretty crucial feature for anybody who likes to listen to music, podcasts, or other audio at night. Using Tasker, we can make our own custom sleep timer.

Disclaimer: this was created by Rachet_Guy over on /r/Tasker. Credits to him for putting this together!

  1. Create a new profile and name it "Sleep Timer".
  2. Add a Time context, and set it to every 2 minutes (or however long you want it to run before the volume decreases).
  3. Create a new task, and name it "Sleep Timer".
  4. Variables --> Variable Set. Name %media_start_vol and set it to a value you feel comfortable with.
  5. Variables --> Variable Set. Name is %vol_decr and set it to a decrement value. NOTE: you must pick a starting volume and/or a decrement volume such that when you subtract the two eventually the value should equal 0, otherwise Tasker will not be able to set the final volume level and will fail.
  6. Task --> If. If %SleepTimerRunning != 1 AND %PENABLED !~ *Sleep Timer. This is basically checking where I'm at. If I haven't started the sleep timer yet, then we'll start it from the beginning.
  7. Alert --> Flash. Text: SLEEP TIMER - CYCLE BEGIN.
  8. Audio --> Media Volume. Set Level to %media_start_vol.
  9. OPTIONAL: if your music player supports an intent broadcast or has a plugin to start audio playback, then you can create an action to start it here. Otherwise, start audio playback before running the task.
  10. Tasker --> Profile Status. Name: Sleep Timer. Set: On.
  11. Task --> Wait. Wait 1 second.
  12. Variables --> Variable Set. Name %SleepTimerRunning To 1.
  13. OPTIONAL: Plugin --> Zooper Widget Variable. Configuration: #TSLEEPTIMER# = 1. This is if you want a Zooper widget that shows when the sleep timer is on.
  14. Task --> Else If. If %SleepTimerRunning = 1 AND %PENABLED ~ *Sleep Timer* AND %VOLM > 0. This is checking to see if the sleep timer is still active and if the media volume is still active.
  15. Variables --> Variable Set. Name %curr_vol to %VOLM. Set the current volume variable to the media volume.
  16. Variables --> Variable Set. Name %next_media_vol to %curr_vol-%vol_decr. We're decrementing the current volume.
  17. Audio --> Media Volume. Level: %next_media_vol. Changing the media volume.
  18. Alert --> Flash. Text: VOLUME LOWERED TO - %next_media_vol
  19. Task --> Else.
  20. Tasker --> Profile Status. Name: Sleep Timer, Set Off.
  21. Task --> Wait. Wait 2 seconds.
  22. Media --> Media Control. Cmd: Toggle Pause. Simulate Media Button: On. For App: choose the music app you want it to broadcast to. Check If and set it to If %SleepTimerRunning eq 1.
  23. Variables --> Variable Set. Set %SleepTimerRunning to 0.
  24. OPTIONAL: Plugin --> Zooper Widget Pro Variable. Configuration: #TSLEEPTIMER# = 0. We're toggling the Zooper Widget to show us that it's off.
  25. Audio --> Media Volume. Level: %media_start_vol
  26. Alert --> Flash. Text: SLEEP TIMER - CYCLE END
  27. Task --> End If.
  28. Exit out, and the profile creation is done.

Now, TURN OFF THE PROFILE! You don't want it running unless you explicitly tell it to! You can run it in many different ways, me personally I use a Zooper Widget to make it run, but you can simply create a homescreen shortcut using Nova or Apex Launcher to launch the Sleep Timer task.

Here are screenshots of the task:

I'll attach the XML file below. Import it by moving it to /sdcard/Tasker/Profiles, then opening Tasker and long-pressing on the Profile tab up top then pressing Import.
Attached Files
File Type: xml Sleep_Timer.prf.xml - [Click for QR Code] (8.6 KB, 656 views)
The Following 3 Users Say Thank You to MishaalRahman For This Useful Post: [ View ]
11th March 2016, 02:54 AM |#2  
twosix's Avatar
Senior Member
Thanks Meter: 39
Thank you. Does this works on Youtube?
12th March 2016, 12:03 AM |#3  
Junior Member
Thanks Meter: 2
I'd change it so that it would PAUSE ( + Close + Disconnect any bluetooth speakers ) the media app
The Following 2 Users Say Thank You to gaara87 For This Useful Post: [ View ] Gift gaara87 Ad-Free
Post Reply Subscribe to Thread

alarm, music, sleep, tasker, timer

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes