Gentler wakeups with Home Assistant 🥱

wakemeup.py
HowTos homeassistant snapcast appdaemon homeautomation iot

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!

Home Assistant

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:

AppDaemon

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

Configuration

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:

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.

Installation

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.

Configure

CallHASS task

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

Variables

Next up we need to set some variables for the task.

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.

Press the following button to get redirected to your entities list. Open your Home Assistant instance and show your entities.

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”.

Conclusion

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 :)

Buy Me a Coffee at ko-fi.com