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?
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:
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.
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.
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
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
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:
Open your SLEEP_TRACKING_* event profile
Add an action using Plugin > SharpTools > Mode: Get Current Note: This will set the variable %st_mode with the name of your current mode
Add both of your actions to run your desired phrases and make them conditional
Add the action using Plugin > SharpTools > A Phrase
Select your desired phrase from the list and hit apply (eg. Good Night!)
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
Open the main SharpTools app, select Modes from the left navigation, long press on any mode and choose Subscribe to all mode changes
Create a new Tasker profile using Event > Plugin > SharpTools > Mode Change
In the Task, create an action using Variables > Variable Set Name: %STMODE To: %st_mode
Reacting to the Sleep as Android Event
Open your SLEEP_TRACKING_* event profile Note: You don’t need the Get Mode action here since the global %STMODE will already be set
Add both of your actions to run your desired phrases and make them conditional
Add the action using Plugin > SharpTools > A Phrase
Select your desired phrase from the list and hit apply (eg. Good Night!)
While you are still in the action, add an If conditional (eg. %STMODE ~ Home)
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!