20-11-2020 Warning! This blog has been outdated, much has changed in the past year. I no longer use IFTTT and Home Assistant has new features in the field of scripts and automations. Possibly links in this article no longer work.
Recently there were problems with the local API of the Google Home, with the result that I no longer received the alarm sensors in Home Assistant. That is why I started to further develop my usecase and added a manual option. (related to this commit on Github).
It’s time to take a dip in my Home Assistant config and tell you more about one of the projects I’ve been working on the last couple of weeks. Last week was also the first time I have slept in my own house 🙂 So this time a look at my going to bed and getting up ritual. For this project I use: IFTTT and Google Home beside Home Assistant.
For working with IFTTT with this case I refer you to the website of juanmtech where you can find all the info (under heading: “How to use IFTTT to trigger Scripts and automations“). Small note, occasional phrases in dutch will appear in screenshots or code in this blog.
Background info
To begin with, I have to admit that I am not a day person at all and prefer to work in the night. But because I study and now live on my own, I will sometimes have to be at school at half past eight and there is no mother who can wake me up now. There is home supervision, but as an IT person it is of course more fun if you could use Home Assistant as a real personal assistant 😀
Going to bed ritual
My goal was that I could use a voice command to the google home to start a sequence that dims lights, an input_boolean will set to true and it reminds me that I have to set an alarm clock for the next day (via the google home or manually in the lovelace UI).
1. Input boolean
So what does my bedtime ritual look like? First I created two input_boolean (input_boolean.yaml), “go_to_sleep” with which I can indicate whether I go to bed or not and “wakeup_wait” (important for later).

2. Script
After that I made a script (start_sleep.yaml) with the entire sequence that Home Assistant should follow. In my case: the action is being logged, the input_boolean is switched “on” and then lighting group for lighting group is dimmed in a time of max 40 seconds.
3. IFTTT / Google Assistant
Then I will use IFTTT to let Google Assistant start this script when I ask it. Create a new applet with IF (Google Assistant) and THEN (Webhook). Below 2 screenshots so that you can see exactly what you must enter.
I can now activate it by saying: “Hey Google! Start sleep mode”. Remember that you still need an automation (handle_ifttt.yaml) to handle all webhook request from IFTTT.
Wakeup ritual
In this section I have made the most changes. So there is now an input_datetime, extra sensors and additions to the script such as: adding the curtains, playing the radio and a morning briefing.
My goal was that I could use the google home alarm as a trigger for an automation that: put on my lights 10 minutes before the alarm goes off (like a kind of Philips wakeup light). At the same time, the curtains open up to 30% for some natural light. After the alarm there will be a morning briefing and finally the radio will play some morning music.
4. Input_number
One of the most important changes is that I have now added an input_datetime (alarm_wakeup.yaml), with which I can manually set a time in lovelace for when I want to be woken up. This is an additional added alternative for when the Google Home local API doesn’t work.
5. Binary Sensor
There are 2 binary template sensors. One for Google (google.yaml) that checks whether the current time matches, with the google alarm sensor of the google home integration. And the manual (manual.yaml) version that checks, whether the current time matches the time entered via the input_datetime. Both are programmed to assume the state “on”, when there is 10 minutes between the current time and the set alarm time.
6. Automation
The piece of automation (morning.yaml) is very simple. It’s triggered if a binary sensor has the state “on”. In the case of the manual alarm, the google home alarm sensor must also be have the state “none” / “unavailable” or “unknown”. This is to prevent a manual alarm from triggering the automation, when you had set an alarm via the google home.
Because the trigger could also go off by means of an alarm clock during cooking, I give it a condition that checks whether the input_boolean is “on”. If it is “off”, then the action will not be executed. If it’s “on”then the script below will be started. And finally in the action it will start the wakeup sequence script, new here is that I am going to give a trigger entity_id to the script, below you can read why.
action:
# Start wake up script ritual
- service: script.wake_up
data_template:
entity_id: "{{ trigger.entity_id }}"
7. Script
Same as with the bedtime script I made a new script (wake_up.yaml) sequence for getting up, in total this script takes 11 minutes to wake me up 🙂 New in the script is that I have now included: the curtains, there is a “wakeup_wait” boolean (verry important), a service that starts a daily briefing and at the end the radio is played for morning music.
An important challenge in the new script was to use 2 types of alarms, with the same script with as little code as possible and applying the DRY (Don’t repeat yourself) principle. For example, if I set the alarm manually, I would also have to program an alarm sound, but this is not necessary if I set an alarm via the Google home.
That is why I use a service_template and a wait_template. The service_template first checks whether the trigger entity of the automation comes from the Google Home or whether it was manual. Based on this, a separate script is started which is specifically intended for the type of alarm.
- service_template: >
{% if (entity_id == 'sensor.google_home_alarm') %}
script.alarm_google
{% else %}
script.alarm_manual
{% endif %}
Now the wait_template. To prevent the main script from continuing, while I first have to shout an alarm off and both types of alarms have a different duration, both scripts have a turn_on at the end for the input_boolean “wakeup_wait”. As long as the boolean does not have the state “on”, the main script keeps waiting to continue executing the sequence.
- wait_template: "{{ is_state('input_boolean.wakeup_wait', 'on') }}"
Are things not clear? Or if you have come to ideas by reading this blog, about how I can make it cooler and better? Share it with me! Via Twitter, mail or Github.