Tasker: Sleep mode with text message reply

Ever get tired of going to bed (early or not) and being woken up by a friend’s unimportant call or text message?  But you can’t just turn all sound off, what if someone needed to get ahold of you in an emergency?

Enter Tasker, a nifty little Android app that lets you take complete control of your device by making profiles and tasks.  With Tasker I built a series of profiles and tasks that creates a smart “Sleep mode”:

Description

Enter “Sleep mode”:

  • Between the hours of X & X
  • The phone is connected to power
  • Not docked in the car

During “Sleep mode”:

  • Mute all sounds (including phone ringer)
  • Turn off blinking LED
  • When someone calls:
    • The first time, text them back to inform them you are sleeping.  But tell them if it is an emergency, simply call right back.
    • If the same number calls back within 5 minutes, unmute all sounds (allowing the phone to ring)
    • After 5 minutes, return to normal sleep mode and re-mute all sounds if they were unmuted

Profiles

The following is a text description of the profiles contained in this project.  This is simply here to help explain what each of the profiles is for, what it does, and why.  The profiles themselves can be imported directly into Tasker at the bottom of this article.

  1. Sleep mode– main sleep mode on/off profile
    1. Contexts:
      1. Power AC
      2. From 21:00 Till 06:00
      3. Not Docked Car
    2. Tasks:
      1. |> Set Sleepmode
      2. <| End sleepmode
  2. Sleep Mode Off For Call– turns sleep mode off when someone calls a second time within 5 minutes
    1. Contexts:
      1. Phone Ringing *
      2. Variable Value %SLEEPMODE=1
    2. Tasks:
      1. |> Anonymous (#1 below)
  3. Sleep Mode Call Timeout– turns sleep mode back on after 5 minutes has passed and the caller hasn’t called back
    1. Contexts:
      1. Variable Set %SLEEP_CALL, *
    2. Tasks:
      1. |> Anonymous (#2 below)
  4. Fix Sleep Mode– turns sleep mode off if for some reason it didn’t turn off by the exit task (has only happened to me once, but this profile makes sure it can’t happen)
    1. Contexts:
      1. Not Power AC
      2. Variable Value %SLEEPMODE=1
    2. Tasks:
      1. |> Anonymous (#3 below)
  5. Sleep Notification LED– kills the LED on new notifications while in sleep mode
    1. Contexts:
      1. Notification *,*
      2. Variable Value %SLEEPMODE=1
    2. Tasks:
      1. |> Kill LED
  6. Sleep Display Off LED– kills the LED when the screen turns off in sleep mode
    1. Contexts:
      1. Display State Off
      2. Variable Value %SLEEPMODE=1
    2. Tasks:
      1. |> Kill LED

Tasks

The following are text descriptions of the different tasks associated with this project, again for explanations of what they do, not for creating them manually.  Import the project below and all of these tasks will be imported for you.

  1. Set Sleepmode – silences the phone and sets sleep mode
    1. Silent Mode: On
    2. Variable Set %SLEEPMODE=1
    3. Perform Task: Kill LED
  2. End Sleepmode – sets phone back to normal sound and unsets sleep mode
    1. Perform Task: Vibrate Off
    2. Varaible Clear %SLEEPMODE
    3. Notification Pulse: On   (allow the LED to blink)
  3. Kill LED – stops the LED pulse from blinking
    1. Wait: 10 seconds
    2. Notification Pulse: Off   (forbid the LED from blinking)
  4. Vibrate Off – unmutes phone, but sets default “silence toggle” to Vibrate instead of Silent
    1. Silent Mode: Vibrate
    2. Ringer Volume: 10
  5. Anonymous #1 – unnamed task for turning silent mode off for a repeat-caller
    1. IF: %SLEEPMODE = 1
      1. IF: %CNUM !~ %SLEEP_CALLER   (if the current caller’s phone number is different than the stored %SLEEP_CALLER number)
        1. Send SMS to %CNUM   (send an SMS message to the current caller’s number with whatever text you would like)
        2. Variable Set:  %SLEEP_CALLER = %CNUM   (store the current caller in our %SLEEP_CALLER variable to compare if they call back)
      2. ELSE   (the current caller’s number is the same as the %SLEEP_CALLER – they called back)
        1. Silent Mode: Off
      3. END IF
      4. Variable Add:  %SLEEP_CALL, 1    (increment our %SLEEP_CALL counter by 1)
    2. END IF
  6. Anonymous #2 – unnamed task for decrementing the %SLEEP_CALL counter ever 5 minutes until we resume sleep mode
    1. Wait:  5 minutes
    2. IF:  %SLEEP_CALL > 1   (we haven’t waited at least 5 minutes since our last sleep call)
      1. Perform Task:  Decrement Sleep Caller
    3. ELSE:   (we’ve waited at least 5 minutes since our last sleep call)
      1. Silent Mode: On
      2. Variable Clear:  %SLEEP_CALL
      3. Variable Clear:  %SLEEP_CALLER
    4. END IF
  7. Anonymous #3 – unnamed task for fixing sleep mode if it somehow gets left on in the morning
    1. Wait:  5 minutes
    2. STOP IF:  %PACTIVE ~ *,Sleep mode,*   (if the Sleep mode profile is active again, stop)
    3. IF: %SLEEPMODE == 1
      1. Perform Task:  End sleepmode
      2. Email Me Pro   (Tasker plugin to send me an email telling me it had to fix sleep mode)
    4. END IF
  8. Decrement Sleep Caller
    1. Wait:  30 seconds
    2. Variable Subtract:  %SLEEP_CALL, 1  (decrement our %SLEEP_CALL counter by 1)

XML to import

The following XML file can be imported directly into Tasker.  It will create a new tab (Project) where all of the profiles and tasks will be stored, and will import all of the necessary profiles, tasks and variables for it to work.  You may need to tweak a few settings, but it will handle the majority of the setup for you.

Note: you must disabled “Beginner mode” in order to be able to import this configuration.

Sleep.prj

  • Durlon Bryant

    Hi, I installed this project, and it works to a point, I had a friend call me to test it, and they got the text message…but when they called back the silent did not turn off. I’m on a Samsung Galaxy S4, if that makes a difference.

    • gjanes

      I’ve been using this profile for years, currently with Tasker 4.1u3 on Android 4.1.2, and everything works. I don’t have access to an S4, but I have to assume there is a different option on the S4 to mute (or unmute in this case) the ringer, or there’s something different in a newer version of Android that I don’t have.

      I’m sorry I can’t be of any additional help, I simply don’t have the means to test. But if you figure out the problem, please let me know and I can either update the project or at least make a mention in the post.

    • Durlon Bryant

      Well, did some more testing and it’s working now…The only thing i changed was I uninstalled Beautiful Widgets, I ahd read on an other forum that it sometimes interfered with Tasker controlling the settings….It’s seems to work now, so maybe that was the problem….only way to test is to reinstall BW and see if Tasker messes up again. Not worth the effort really, since it’s working now.

  • Helen

    Hi I’ve probably overlooked something really simple but when I try to import this to tTasker I get the message Tasker can’t handle this information…. I have beginner mode unchecked. Does anyone have any idea??