Geoff Ruddock

Turn on your thermostat before an alarm with Tasker (Android)

My main Black Friday purchase this year was a Tado° system (thermostat + smart radiator valves), which I acquired with the goal in mind of regulating the temperature in my bedroom by:

  1. Turning the heat down early enough to be consistently cold at night.
  2. Turning the heat up in the morning to make it easier to wake up. Ideally 1h before.

The first part is easy, but the second part can’t quite be achieved, at least out-of-the-box. If your daily sleep schedule is consistent, you can just set a corresponding heating schedule in the Tado app. But my own wake-up time varies between 7a-9a, and I found it cumbersome to change the “Smart Schedule” every evening in anticipation of when I would wake up the following morning.

Why IFTTT isn’t enough

Tado’s IFTTT integration is a good start, but it isn’t perfect. It is relatively straight-forward to create a recipe that turns on our heating when our Android alarm goes off. But ideally it would trigger some amount of time ahead of the alarm, so that the room has time to actually rise to temperature.

IFTTT doesn’t have any capability for this sort of pre-trigger logic. I toyed with triggering based on a “dummy” alarm set 1h ahead, but ultimately realized that actions trigger on the alarm being dismissed rather than going off.

How-to

There are two things we need to do, which we can achieve using a combination of IFTTT and Tasker:

  1. Calculate when to trigger the heat, based on the next alarm set.
  2. Actually trigger the Tado° thermostat to turn on at that time.

Calculate when to trigger

We’ll use the AutoAlarm plugin (Google Play) to enable tasker to see the time of the next alarm we have set. These instructions are heavily based on this forum post, which includes a video walk-through that is useful if you’re not familiar with the Tasker interface.

Set the to/from window based on when you normally wake up.

Set the to/from window based on when you normally wake up.

  1. Create a new time-based profile (Tasker → Profiles → (+) → Time)
    • From/to → if you use other android alarms throughout the day (besides for waking up) you’ll want to set a window here to only run around when your wake-up alarm should be. I used 5a-10a.
    • Every → I set it to run every 5 minutes, but I suppose you could run it less frequently to minimize effect on battery. This is less of a concern for me personally, because my phone is always plugged in overnight.
  2. Add the following actions to your profile
    • Plugins → AutoAlarm → this will run the plugin, exposing a %seconds variable which contains the number of seconds until our next alarm.
    • Set a variable %minsBefore to the number of minutes ahead of your alarm that you want your heat to turn on. I used 60 here, but adjust accordingly.
    • Set a variable %TriggerHeatAtSec that calculates the formula round(%TIMES + %seconds - (%minsBefore * 60)). Make sure the variable name starts with an uppercase character, so that it is available in “global scope” for later use by a different profile. If you’re trying to understand this formula: %TIMES is a built-in Tasker variable that returns the current time in UNIX format (number of seconds since January 1970, don’t ask).
    • If you use other alarms throughout the day, also set the variable %NextAlarmHour so it can be used as a condition later.

☠️ There are some reports of this method sometimes not working, possibly due to other apps using alarms silently in the background. If it’s acting funky, double-check that you have the Reliable Alarms option disabled in Tasker. This option sets background alarms in the built-in Android clock app to ensure that the Tasker app does not get killed due to battery-saving settings. But it interferes with what we’re trying to do here. If this doesn’t help, you may have a different app that is causing the interference. You can try debugging with the ClockTask plugin, which has a variable that tells you which app the next alarm is set.

This profile calculates the trigger time for the thermostat.

This profile calculates the trigger time for the thermostat.

Actually trigger the thermostat

Now we need to trigger our thermostat to kick in at the previously calculated time. We could probably do this entirely via Tasker using the tado API, but using IFTTT relieves us of the burden of dealing with OAuth tokens, etc.

  1. Connect your Tado account to IFTTT
  2. Enable the IFTTT Webhooks channel.
  3. Create an applet that triggers your thermostat based on a webhook event. Here is mine.
  4. Go back to the webhooks channel page and click Documentation in the top-right to get to a page where you can test out your configuration. Fill in the name of your event and click Test It. After a few seconds, check your Tado app (or listen to your radiator valve) and you should notice that it was triggered successfully.
    Screenshot of IFTTT webhook configuration
  5. Go back to Tasker and create a second profile that runs from/until %TriggerHeatAtSec (once).
  6. To prevent the logic from triggering for random alarms later in the day, you can set an additional constraint to the trigger logic: %NextAlarmHour < 13 (to only turn on heating for alarms before 1p).
    This profile actually does the triggering.

    This profile actually does the triggering.

  7. Add a single task that uses HTTP Request to make a GET request to the webhooks URL we tested earlier, which will look something like https://maker.ifttt.com/trigger/<event_name>/with/key/<your_key>.

comments powered by Disqus