Google Assistant wake-up routine project

Hello guys!

I would like to share a little project I’ve created a couple of days ago. The idea is to use the Google Assistant sensor component to get the alarm time that is set with my good night routine (it asks for an alarm time directly using the Assistant) using a Google Home Mini that I had on my bedroom and use it to trigger an automation to wake me up slowly using sound and light.

Here is the final package:

sensor:

  - platform: template
    sensors:
      google_home_alarme_suite_time:
        friendly_name: "Time"
        value_template: "{% if not is_state('sensor.suite_alarm', 'unavailable') %}{{ as_timestamp(states.sensor.suite_alarm.state) | timestamp_custom('%H:%M') }}{% endif %}"
        entity_id: sensor.suite_alarm

      google_home_alarme_suite_day:
        friendly_name: "Day"
        value_template: "{% if not is_state('sensor.suite_alarm', 'unavailable') %}{{ as_timestamp(states.sensor.suite_alarm.state) | timestamp_custom('%d/%m/%Y') }}{% endif %}"
        entity_id: sensor.suite_alarm

      google_home_alarme_suite_time_left:
        friendly_name: "Time left"
        value_template: "{% if not is_state('sensor.suite_alarm', 'unavailable') %}{{ (((as_timestamp(states.sensor.suite_alarm.state) - as_timestamp(now())) /60) /60) | round(0)}}{% endif %}"
        entity_id: sensor.time
        unit_of_measurement: "hours"

homeassistant:
  customize:

    sensor.google_home_alarme_suite_time:
      icon: mdi:clock-outline

    sensor.google_home_alarme_suite_day:
      icon: mdi:calendar-clock

    sensor.google_home_alarme_suite_time_left:
      icon: mdi:timer

automation:

  - alias: Wake up routine 1 hour early
    initial_state: true
    trigger:
      - platform: template
        value_template: "{{ (not is_state('sensor.suite_alarm', 'unavailable')) and (states('sensor.time') == (as_timestamp(states.sensor.suite_alarm.state) - 3600) | timestamp_custom('%H:%M')) and (states('sensor.date') == as_timestamp(states.sensor.suite_alarm.state) | timestamp_custom('%Y-%m-%d')) }}"
    action:
      - service: switch.turn_on
        entity_id: switch.toalheiro
      - delay: '00:40:00'
      - service: media_player.volume_set
        data:
          entity_id: media_player.suite
          volume_level: 0
      - service: media_player.play_media
        data:
          entity_id: media_player.suite
          media_content_type: 'audio/mp3'
          media_content_id: 'http://192.168.1.12:8123/local/audio/despertador/passarinhos.m4a'
      - service: media_player.volume_set
        data:
          entity_id: media_player.suite
          volume_level: 0.6
      - delay: '00:05:00'
      - service: light.turn_on
        entity_id: light.ledsuitetv
        data:
          transition: 900
          brightness_pct: 50
          rgb_color: [255,60,0]
      - service_template: >-
          {% if is_state('input_boolean.cafe_manha', 'on') %}
            switch.turn_on
          {% else %}
            script.nada
          {% endif %}
        data_template:
          entity_id: >-
              {% if is_state('input_boolean.cafe_manha', 'on') %}
                switch.cafeteira_casa
              {% endif %}
      - service_template: >-
          {% if is_state('input_boolean.chaleira_manha', 'on') %}
            switch.turn_on
          {% else %}
            script.nada
          {% endif %}
        data_template:
          entity_id: >-
              {% if is_state('input_boolean.chaleira_manha', 'on') %}
                switch.chaleira_casa
              {% endif %}
      - delay: '00:05:00'
      - service: light.turn_on
        entity_id: light.ledsuitecama
        data:
          transition: 600
          brightness_pct: 50
          rgb_color: [255,60,0]
      - delay: '00:08:00'
      - service: cover.open_cover
        entity_id: cover.persiana_suite

The trigger checks if the alarm time is the same as now - 1 hour and if the current day is the same, in case you create an alarm for any other day than the next morning.

These template sensors are used to create a condition lovelace card that shows those information only if an alarm is set.

This routine starts 1 hour earlier than the current alarm time and does as follow:

  1. Turn on the bathroom heater at start
  2. Wait 40 minutes and start playing a media (birds singing) on the google home mini
  3. Wait 5 minutes and turn on the first led behind the TV at 50% with a transition of 10 minutes
  4. Turn on the coffee machine and the kettle (couple of sonoff basics)
  5. Wait 5 minutes and turn on the second led behind the bed at 50% with a transition of 5 minutes
  6. Wait 8 minutes and open the main bedroom window cover

By the end of this routine, the default google home alarm should trigger in case non of these actions wakes me up.

Maybe this code can help or inspire someone to do something better or different.

Have a great day!

4 Likes