Countdown Timer that announces every minute

Usually, the default timer of your smart speaker notifies you only once, when your time is up.
I always wanted something like this: “OK Google, start a 10 minute timer and let me know every minute”
Here is how I achieved this functionality using a script.

  1. Set an input_number that will work like a global variable.
    Go to configurations -> Helpers -> Click the add button on the right-lower corner
    Set the name to “Countdown minutes”, display mode to input field
    Now, you have a new entity: input_number.countdown_minutes

  2. Write a script that announces how much time you have left left every minute.

scripts.yaml

countdown_timer:
  alias: Countdown timer
  icon: mdi:alarm
  sequence:
  - repeat:
      while: '{{ states("input_number.countdown_minutes")|int > 0 }}'
      sequence:
      - service: media_player.play_media
        data_template:
          entity_id: media_player.kitchen_speaker
          media_content_id: http://192.168.xx.xx:8123/local/media/shine.mp3
          media_content_type: music
      - delay: 2
      - service: tts.google_translate_say
        data_template:
          entity_id: media_player.kitchen_speaker
          message: 'You have {{ states("input_number.countdown_minutes")|int }} minutes left'
          language: en-uk
      - service: input_number.set_value
        data_template:
          entity_id: input_number.countdown_minutes
          value: '{{  states("input_number.countdown_minutes")|int - 1 }}'
      - delay: 58
  - service: media_player.play_media
    data_template:
      entity_id: media_player.kitchen_speaker
      media_content_id: http://192.168.xx.xx:8123/local/media/shine.mp3
      media_content_type: music
  - delay: 2
  - service: tts.google_translate_say
    data_template:
      entity_id: media_player.kitchen_speaker
      message: "Time's up! Time's up! Time's up! Time's up! Time's up!"
      language: en-uk
  - service: input_number.set_value
    data:
      entity_id: input_number.countdown_minutes
      value: 5

The script repeats every 60 seconds. It announces how many minutes are left, and reduces countdown_minutes value by 1.
And when the countdown_minutes reaches 0, it announces that time’s up, and resets the value to the default value 5.

  1. Next, add a switch that controls this script.

switches.yaml

- platform: template
  switches:
    countdown_timer:
      friendly_name: Countdown timer
      icon_template: mdi:timer
      value_template: "{{ is_state('script.countdown_timer', 'on') }}"
      turn_on:
      - service: script.countdown_timer
      turn_off:
      - service: script.turn_off
        entity_id: script.countdown_timer

This template switch consists of 3 parts
(1) The state: Whether the script is running or not
(2) Turn on action: Run the script
(3) Turn off action: Abort the script

  1. Now add to the countdown timer to the frontend.
type: entities
entities:
- entity: input_number.countdown_minutes
- entity: switch.countdown_timer

image

The following steps are for google assistant users who want to use voice commands to run this countdown timer.
5. Make some additional scripts with the minutes you frequently use. (ex: 5, 10, 15 minutes)

five_minute_countdown_timer:
  alias: 5 minute countdown timer
  icon: mdi:timer-outline
  sequence:
  - service: input_number.set_value
    data:
      entity_id: input_number.countdown_minutes
      value: 5
  - service: script.turn_on
    entity_id: script.countdown_timer
ten_minute_countdown_timer:
  alias: 10 minute countdown timer
  icon: mdi:timer-outline
  sequence:
  - service: input_number.set_value
    data:
      entity_id: input_number.countdown_minutes
      value: 10
  - service: script.turn_on
    entity_id: script.countdown_timer
fifteen_minute_countdown_timer:
  alias: 15 minute countdown timer
  icon: mdi:timer-outline
  sequence:
  - service: input_number.set_value
    data:
      entity_id: input_number.countdown_minutes
      value: 15
  - service: script.turn_on
    entity_id: script.countdown_timer
  1. Expose the scripts to google assistant

configuration.yaml

google_assistant: !include google_assistant.yaml

google_assistant.yaml

project_id: home-assistant-xxxxx
service_account: !include SERVICE_ACCOUNT.JSON
report_state: true
expose_by_default: false
entity_config:
  script.five_minute_countdown_timer:
    name: "Five minute countdown"
  script.ten_minute_countdown_timer:
    name: "Ten minute countdown"
  script.fifteen_minute_countdown_timer:
    name: "Fifteen minute countdown"
  1. If you want to use shorter voice commands, add some routines like the following.
    This will make you able to just say “OK Google, 5 minute countdown.”
    instead of “OK Google, turn on 5 minute countdown”

I use this countdown timer daily, especially in cases like when you have to pack up and leave in 5 minutes. Instead of pulling out your phone to check the time, you are provided with a timed auditory cue which is more convenient that you’d expect.
Hope this helps some folks that want to make something similar.

4 Likes

I think this is terrific. However, as a total noob, I’m not sure where to put #s 4 & 5. I’m guessing #5 goes into the scripts.yaml. I tried adding #4 into the configuration.yaml but (with frontend: before it), but it didn’t seem to like that. Also, in the google-assistant.yaml, I assume the project id has to be unique, or is that number referring to something specific? Thanks for your help!

Regarding using Google home.
I use the IFTTT integration and that means I can speak out how many minutes and it will be transferred to HA.

#4 is in the frontend (lovelace).

Add a new card to your lovelace and choose manual, copy paste the yaml.

Thanks! I’m clearly over my head. I get the following error: Error loading /config/configuration.yaml: in /config/google_assistant.yaml", line 2, column 18: Unable to read file /config/SERVICE_ACCOUNT.JSON.

Have you connected Google Assistant to your HA?
If not, please follow this guide. Please note that you can either use a simple payed could method, or a rather complicated free manual method.

I have set it up with Home Assistant Cloud.

I am using the manual method, and you should change part 6 to match your settings. Have you connected any other entity with google assistant? I believe the changes you need will not be that big.