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.
-
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 -
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.
- 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
- Now add to the countdown timer to the frontend.
type: entities
entities:
- entity: input_number.countdown_minutes
- entity: switch.countdown_timer
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
- 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"
- 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.