Student Techlife Student Techlife
  • Categories
    • Student Life
    • Technology
    • Home Assistant
    • 3D Printing
    • DIY
  • My House
  • My Projects
    • Home Assistant Glow
    • NIPKaart
    • Teddy Bear Hunting
    • NFC Scanner
  • Who am I?
  • Contact
0
817 Followers
168 Followers
Student Techlife Student Techlife Student Techlife
  • Categories
    • Student Life
    • Technology
    • Home Assistant
    • 3D Printing
    • DIY
  • My House
  • My Projects
    • Home Assistant Glow
    • NIPKaart
    • Teddy Bear Hunting
    • NFC Scanner
  • Who am I?
  • Contact
  • Home Assistant
  • Student Life

Hey Google! Time to sleep ๐Ÿ’ค

  • May 16, 2019
  • Klaas Schoute

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

OFF / ON

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.

  • Google Assistant
  • Webhook

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.

Share
Tweet
Share
Klaas Schoute

Interaction technology (UX/UI) student who loves home automation, drones, open source projects and likes to take you on his adventure to the perfect smart student house.

Related Topics
  • google home
  • ifttt
  • in depth
  • morning
  • sleeping
  • wakeup
Previous Article
  • Home Assistant

Home Assistant config on Github

  • May 11, 2019
  • Klaas Schoute
View Post
Next Article
  • Home Assistant
  • Student Life

My TV ๐Ÿ“บ is out of (own) control

  • June 2, 2019
  • Klaas Schoute
View Post
You May Also Like
View Post
  • Home Assistant
  • Integration

EnergyZero market prices with new integration in Home Assistant

  • Klaas Schoute
  • January 11, 2023
View Post
  • Projects
  • Student Life

๐Ÿ…ฟ๏ธ NIPKaart project update

  • Klaas Schoute
  • August 22, 2022
View Post
  • College
  • Home Assistant
  • Student Life

It’s a long time ago

  • Klaas Schoute
  • June 3, 2022
View Post
  • Home Assistant

First integration in Home Assistant!

  • Klaas Schoute
  • June 2, 2021
View Post
  • DIY
  • Home Assistant

Blitzwolf LT11 with ESPHome

  • Klaas Schoute
  • March 11, 2021
Green light in the bathroom
View Post
  • Home Assistant
  • Student Life

How I save water while showering๐Ÿšฟ

  • Klaas Schoute
  • December 25, 2020
View Post
  • Home Assistant
  • Student Life
  • Technology

Is this going to be the future?

  • Klaas Schoute
  • November 4, 2020
View Post
  • College
  • Student Life

Back to school! ๐ŸŽ“

  • Klaas Schoute
  • September 18, 2020

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Author
Klaas Schoute
Interaction technology (UX/UI) student who loves home automation, drones, open source projects and likes to take you on his adventure to the perfect smart student house.
Recent Posts
  • EnergyZero market prices with new integration in Home Assistant January 11, 2023
  • Let’s contribute! Hacktoberfest 2022 October 2, 2022
  • ๐Ÿ…ฟ๏ธ NIPKaart project update August 22, 2022
  • It’s a long time ago June 3, 2022
  • First integration in Home Assistant! June 2, 2021
Instagram
klaasnicolaas
Iedereen een gelukkig nieuwjaar! ๐Ÿฅ‚
Finally received my @chonkerkeys last week, now online meetings are even more fun! ๐Ÿ˜
Wauw wat een mooie show! Als je nog niet geweest moet je zeker gaan, kan nog t/m december 2022 (is alweer verlengd). #soldaatvanoranje #valkenburg #theaterhangaar
Die momenten tussen de sets dat je even met de ๐ŸฅŽ wil spelen ๐Ÿ˜… #tennis #rookie #new #sport #training
Follow


Student Techlife Student Techlife
  • Categories
  • My House
  • My Projects
  • Who am I?
  • Contact
Make a student life smarter

Input your search keywords and press Enter.