Automate your wakeups
Ever watched a movie set in the future, where the protagonist wakes up and the blinds in the room go up, the music starts gently and coffee is automatically served?
Well, the future is now!
This guide goes through how you can trigger this using any alarm application on Android via Tasker, so no additional app (except Tasker which runs in the background), or other hassle to deal with!
The movies set in the future always used HomeAssistant, didn’t you know? And for good reason! Because when you have your blinds, lights, coffeemaker, etc, the effort to implement them into HomeAssistant is extremely effortless. And when that’s done, there is no stopping you from automating it all to your hearts content.
This guide assumes that you already have stuff working in Homeassistant which you want to automate. If not, feel free to look at the following for inspiration:
To perform the automation on the Homeassistant side of things I’ve used Appdaemon. The advantage of Appdaemon is that it allows you to create more advanced automations using Python.
Installing Appdaemon itself is out of scope for this page, and is better explained by the author here: https://appdaemon.readthedocs.io/en/latest/INSTALL.html
In my case, the following script is used to wait for the alarm to be set for the next day, and add timers to trigger happenings based on it.
My ugly (but functional) script
If you read through the script, you’ll see that it’s very much custom tailored towards me, and you will need to make many changes to make it match your need. Currently my version performs the following:
- When the alarm is set, fade down the lights in the room until 10%
- After 25s (LIGHTS_OFF_AFTER_ALARM_SET), turn the lights off
- One hour (TIME_BEFORE_ALARM) before the alarm goes off, start turning the lights on gently
- 20 minutes (RADIOTIME_BEFORE_ALARM) before the alarm goes off, turn on the radio at a low volume
- Then, gently increase the volume in 3 steps (RADIOTIME_MID_BEFORE_ALARM, RADIOTIME_MORE_MID_BEFORE_ALARM, RADIOTIME_FULL_BEFORE_ALARM)
- 30 seconds after the alarm has gone off, start brewing coffee (COFFEETIME_AFTER_ALARM)
Take it more as a inspirational template, than a finished product. Look through it, and change the Id’s, services and timings as you need. The Appdaemon documentation will probably come in handy.
To install the script, simply copy it over to the apps directory of appdaemon. In my setup this is under
~/.appdaemon/apps. In addition to the script, you need a YAML configuration file in the same directory, something similar to this:
wakemeup: module: wakemeup class: WakeMeUp
The directory will then look similar to this:
~/.appdaemon/apps$ ls __pycache__ wakemeup.py wakemeup.yaml
Tasker for Android
On the Android side of things we use Tasker and the AutoAlarm plugin to monitor set alarms and ship them over to Homeassistant.
- You can find the Tasker app here: https://play.google.com/store/apps/details?id=net.dinglisch.android.taskerm
- And the AutoAlarm plugin here: https://play.google.com/store/apps/details?id=com.joaomgcd.autoalarm
First we need to configure a task to help Tasker with calling the HomeAssistant API. To make things easier, I’ve provided a XML dump of the task here: CallHASS.tsk.xml
Next up we need to set some variables for the task.
- %HA_ADDR should be set to the base URL of your HomeAssistant instance.
- %HA_AUTH should be a “Long Lived Access Token”, see https://www.home-assistant.io/docs/authentication/ for more details.
Set alarm task
Then, if we want to make a button/widget to transmit the currently set alarm to HomeAssistant we can do so as this:
(again, to make things easier, I have a XML you may import to Tasker here: Set_alarm.tsk.xml )
2. Perform task
If the XML import above failed you, this is how the “2. Perform task” in the previous screenshot was configured.
Running the task
If you imported the Task from the XML (or created it correctly manually), you should now be able to run it by pressing the play-button. This should then result in you now getting a “Sleep Alarm” sensor in Home Assistant which denotes when your next alarm is set for.
Sleep As Android
To automatically trigger tasker to send the alarm time to HomeAssistant I’ve coupled the task with a trigger from “Sleep As Android”. Note, this app is not necessary, you may also trigger Tasker in other means (eg. on a timer, or with other apps if they support it).
To configure this I made a Profile in Tasker where the “Set Alarm Task” is ran each time I start the sleep-tracking in “Sleep As Android”.
Congrats, you now live in the future too!
This post became somewhat messy and lacking in explanation in various parts, as due to all the different software components involved it’s hard to explain them all in the same detail.
If you got stuck then this post is also available on the Home Assistant forum here: automating-wakeups-with-tasker, feel free to poke me there to add some additional words where you feel it’s lacking.
Otherwise, La vita è bella, and thank you for being here :)