Student Techlife
  • Categories
    • Student Life
    • Technology
    • Home Assistant
    • 3D Printing
    • DIY
  • My House
  • Projects
    • NIPKaart
    • Teddy Bear Hunting
    • NFC Scanner
  • Who am I?
  • Contact
Student Techlife Student Techlife
  • Categories
    • Student Life
    • Technology
    • Home Assistant
    • 3D Printing
    • DIY
  • My House
  • Projects
    • NIPKaart
    • Teddy Bear Hunting
    • NFC Scanner
  • Who am I?
  • Contact
365
139
61
  • Home Assistant
  • Student Life

Hey Google! Time to sleep πŸ’€

  • May 16, 2019
  • No comments
  • 2K views
  • 5 minute read
  • Klaas Schoute
Total
0
Shares
1
0
0

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.

Total
1
Shares
Share 1
Tweet 0
Share 0
Avatar
Klaas Schoute

Computer science student who loves home automation 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
Green light in the bathroom
View Post
  • Home Assistant
  • Student Life

How I save water while showering🚿

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

Is this going to be the future?

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

Back to school! πŸŽ“

  • September 18, 2020
  • Klaas Schoute
View Post
  • Home Assistant
  • Student Life
  • Technology

Hello? What is your emergency? πŸ†˜

  • February 12, 2020
  • Klaas Schoute
View Post
  • College
  • Home Assistant
  • Student Life
  • Technology

My cookingplate died 🍳

  • December 30, 2019
  • Klaas Schoute
View Post
  • Student Life

Shopping at Picnic πŸ›’

  • November 15, 2019
  • Klaas Schoute
View Post
  • Student Life
  • Technology

Welcome to Berlin! πŸ‡©πŸ‡ͺ

  • September 13, 2019
  • Klaas Schoute
View Post
  • Home Assistant
  • Student Life
  • Technology

Back to normal business πŸ‘¨β€πŸ’»

  • September 1, 2019
  • Klaas Schoute

Leave a Reply Cancel reply

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

Author
Klaas Schoute
Avatar
Computer science student who loves home automation and likes to take you on his adventure to…
Recent Posts
  • How I save water while showering🚿 December 25, 2020
  • Is this going to be the future? November 4, 2020
  • Back to school! πŸŽ“ September 18, 2020
  • Hello? What is your emergency? πŸ†˜ February 12, 2020
  • My cookingplate died 🍳 December 30, 2019
Instagram
klaasnicolaas
standing on the balcony for an hour, for that one perfect photo ⚑ #dslr #thunder #rain #lightroom #netherlands #weather
Wat ik gisteren toch heb gespot! 😲 #naturephotography #ooievaar #oranjewoud
It's time πŸ•› for some programming for the Galaxy watch active2⌚, Tizen OS here I come πŸ˜‹ #devops #tizenos @samsungnederland #wearable #smart #PAforyoungpeople
Maccie Christmas! πŸ˜… #mcdonalds #alkmaar
Follow
Archives
  • December 2020 (1)
  • November 2020 (1)
  • September 2020 (1)
  • February 2020 (1)
  • December 2019 (1)
  • November 2019 (1)
  • September 2019 (2)
  • August 2019 (1)
  • July 2019 (1)
  • June 2019 (3)
  • May 2019 (3)
  • April 2019 (3)
Student Techlife
  • Categories
  • My House
  • Projects
  • Who am I?
  • Contact

Input your search keywords and press Enter.