Sleep as Android trigger "Good Night!" phrase?


#1

I’m enjoying my time with ST… and having all of my connected lights turn off when I go to bed is great! What I would like to do, however, is tie in my Sleep as Android sleep tracking with the “Good Night” trigger, so as when I actually go to sleep, the rest of the lights will shut off, and the thermostat will be set to an appropriate night time temperature.

Ideally, it could also identify when ST is in Away mode, and not change to night mode in those cases when we may be staying out of town, etc.

Does anybody have some clear insight to how I could get these put together with Tasker, or SharpTools?


(Brian) #2

First, how do you want to indicate/detect sleep? The rest is easy.


#3

I have a widget from Sleep as Android on my homescreen, when I tap it, it starts sleep tracking mode. According to the documentation, there are intents that can be subscribed to:

In particular:

ACTION

Sleep tracking start intent
com.urbandroid.sleep.alarmclock.START_SLEEP_TRACK

Sleep tracking stop intent
com.urbandroid.sleep.alarmclock.STOP_SLEEP_TRACK


(Brian) #4

Aha, it’s an Android app.

Three ways:

  1. Ask them to integration with ST
  2. The way I recommend: They integrate with Tasker. There are threads/descriptions on how to integrate Tasker with ST (either IFTTT or Sharptools, can’t remember which, maybe even an easier way). I’d recommend this to start.
  3. I believe that you could make another Android app that watched for the intents, and then directly talked to ST. This could be a challenge unless you are an App developer.

Those are my thoughts.


(Joshua Lyon (SharpTools.io Dashboard)) #5

Tasker is set of automation tools for Android and you can use the intents from Sleep as Android to trigger events in Tasker. SharpTools is a set of SmartThings Tasker plugins I developed which allow you to control your Things, execute Phrases (Routines), and change Modes.

Use the notes below to setup the profile to react to your Sleep as Android events, then use the A Phrase plugin from Plugins > SharpTools to run your Routine.

React to Sleep as Android events in Tasker
Setup a Tasker profile using Event -> System -> Intent and add one of the Intents described below.

Events
Sleep tracking started
com.urbandroid.sleep.alarmclock.SLEEP_TRACKING_STARTED

Sleep tracking stopped
com.urbandroid.sleep.alarmclock.SLEEP_TRACKING_STOPPED

Snoozed by user
com.urbandroid.sleep.alarmclock.ALARM_SNOOZE_CLICKED_ACTION

Time to bed notification
com.urbandroid.sleep.alarmclock.TIME_TO_BED_ALARM_ALERT

Alarm triggered
com.urbandroid.sleep.alarmclock.ALARM_ALERT_START

Alarm dismissed
com.urbandroid.sleep.alarmclock.ALARM_ALERT_DISMISS

Lucid dreaming cue:
com.urbandroid.sleep.LUCID_CUE_ACTION
NOTE: enable settings-lucid dreaming

Antisnoring sound:
com.urbandroid.sleep.ANTISNORING_ACTION

45 minutes before smart period:
com.urbandroid.sleep.alarmclock.AUTO_START_SLEEP_TRACK

Reference: https://sites.google.com/site/sleepasandroid/doc/developer-api


(Tim Slagle) #6

There is also this. Future release date though.


#7

Hey, thanks for the info! I just got done setting Tasker up to respond to SLEEP_TRACKING_STARTED and SLEEP_TRACKING_STOPPED, to try getting the current mode into the %st_mode variable, and only send “Good Night!” phrase if the current mode is Home, or send “Good Morning!” if the current mode is Night.

I’ll see if it works tonight, or if I have more tweaking to do yet :wink:


(Joshua Lyon (SharpTools.io Dashboard)) #8

Two options come to mind – you can either request the current mode each time your event triggers or you can subscribe to mode changes and always have the latest up to date mode.


Option 1

The first option is a bit easier to understand, but it will result in a few second delay each time the sleep tracking is started or stopped as SharpTools has to go out and request the mode each time:

  1. Open your SLEEP_TRACKING_* event profile
  2. Add an action using Plugin > SharpTools > Mode: Get Current
    Note: This will set the variable %st_mode with the name of your current mode
  3. Add both of your actions to run your desired phrases and make them conditional
  4. Add the action using Plugin > SharpTools > A Phrase
  5. Select your desired phrase from the list and hit apply (eg. Good Night!)
  6. While you are still in the action, add an If conditional (eg. %st_mode ~ Home)

For more information on using conditional actions, see this article:


Option 2

The other approach requires you to setup a separate profile to listen for the mode changes and then save that variable to a global variable, but results in the mode variable already being set so it reacts quicker.

Saving the Mode

  1. Open the main SharpTools app, select Modes from the left navigation, long press on any mode and choose Subscribe to all mode changes
  2. Create a new Tasker profile using Event > Plugin > SharpTools > Mode Change
  3. In the Task, create an action using Variables > Variable Set
    Name: %STMODE
    To: %st_mode

Reacting to the Sleep as Android Event

  1. Open your SLEEP_TRACKING_* event profile
    Note: You don’t need the Get Mode action here since the global %STMODE will already be set
  2. Add both of your actions to run your desired phrases and make them conditional
  3. Add the action using Plugin > SharpTools > A Phrase
  4. Select your desired phrase from the list and hit apply (eg. Good Night!)
  5. While you are still in the action, add an If conditional (eg. %STMODE ~ Home)

For more information on saving status from events, see this article:


#9

Heyyyyy, looks just like what I did this morning to fix it… First time that I’ve used the If function in Tasker, so I unknowingly changed the ‘~’ to equals… Didn’t know that equals was for numbers and ‘match’ was for string. Once I fixed that, it worked like a charm!


(Kristopher Kubicki) #10

Just discovered this thread. Fantastic!


#11

Thanks for taking the time to simplify this.