Automate Sleep with Tasker

What is Tasker?

Tasker is a total automatization tool for Android. You can catch events that happen on your phone (e.g. an alarm has been dismissed) and trigger actions (e.g. send sms that you’re awake to someone). You can choose from many events and actions, but to add them for 3rd party apps, there has to be a plugin that connects the app to Tasker.

In contrast to many other apps, Sleep as Android has a Tasker plugin integrated in itself, for free!

Events

You can use any of these events from Sleep as Android and link them to any actions on your phone:

  • Sleep tracking started
  • Sleep tracking stopped
  • Snooze (alarm)
    • the user has snoozed a ringing alarm
  • Bedtime
    • the bedtime has just occured
  • Alarm started
  • Dismiss (alarm)
    • the user has dismissed a ringing alarm AND solved the CAPTCHA if present
  • ~REM
    • the REM phase has been detected. More on REM phase detection here.
  • Anti-Snoring
    • Sleep as Android has detected snoring and executed an anti-snoring action (vibration or tongue click or both). Anti-snoring has to be active for this event to work.
  • Smart period
    • fires 45 minutes before smart period starts (to gather data for the smart period)

Actions

You can take any events given by your phone and trigger Sleep actions with them. Sleep provides these actions:

  • Start sleep tracking
  • Start sleep tracking: Save battery (no graph, just time)
  • Stop Sleep tracking
  • Snooze (alarm)
  • Dismiss (alarm)
  • Play lullaby
  • Stop lullaby
  • Sleep tracking: ideal sleep time
    • to create a new alarm for an ideal sleep time (with default settings) and start sleep tracking immediately

You can also add new alarm with System > Set Alarm action.

Walkthroughs

Create a widget with Tasker

Sleep as Android does not offer a widget to add an alarm directly.

How to create one in Tasker?

  1. Fire up Tasker, go to Tasks tab and add a new task (+) named Add alarm
  2. Tap + to add an action, select System > Send Intent
  3. In action, insert com.urbandroid.sleep.alarmclock.SetAlarm
  4. As target, select Activity
  5. Go back to confirm
  6. Add an icon in the lower right corner
  7. Long press on your desktop and add a Shortcut > Task shortcut and select Add alarm (your new task)
  8. Don’t forget to enable Tasker!

Integrate Sleep with hueManic

You can use any of the Sleep as Android’s events in Tasker to start a service com.urbandroid.hue/.ProgramService with following extras:
EXTRA_START
EXTRA_PROGRAM
to start a program
or
EXTRA_STOP
to stop a program.
EXTRA_PROGRAM needs to have one of the values:
DISCO, FIREPLACE, STORM, FIREWORKS, SEA, JUNGLE, TIBET, AURORA, SUNSET, RAINBOW
Example:

See video tutorial here.

Tasker > Task > Add task > Choose a name > Plus button > System > Send intent

Package: com.urbandroid.hue
Class: com.urbandroid.hue.ProgramService
Extra: EXTRA_START:start
Extra: EXTRA_PROGRAM:DISCO
Target: Service

then
Tasker > Profile > Plus button > Event > Plugin > Sleep > Configuration > Alarm started > Back > Back > Choose your task
Now make sure Tasker is enabled, hueManic installed and the Disco program will start on your alarm.
Adapt the specific conditions to your needs.

MiBand : Get notification when alarm starts

How to have your Mi Band notify you with LED / Vibrations when your alarm ( Sleep as Android ) goes off.. ( Using Mi Band Tools )

1. Create a tasker profile -> Event -> Sleep -> Configuration -> Alarm Started.
2. Create a task for this event.. Notify -> Select any title like ‘AlarmStarted’ which will send a notification in your status bar when alarm is triggered.
3. Open Mi Band tools and set an alert for Tasker application and filter with the title used earlier, ‘AlarmStarted’ .

Many thanks to Pratik Jain!

Share