Google Home/Google Assistant timer to turn off devices

Summary

  • Ask Google Home/Google Assistant to turn off devices in X minutes (e.g: OK Google, turn off bedroom light in 5 minutes)
  • Cancel current timer (e.g: OK Google, cancel bedroom light timer)
  • New timer will override existing one

How does it work?

  • Voice commands => Google Home/Google Assistant => IFTTT => Call Home Assistant scripts

Setup

HomeAssistant scripts:

  • Main timer script: script to turn devices in X minutes
  • Wrapper script: script to call to main script with logic of cancelling running script.

####### Main timer script
turn_off_bedroom_light_timer:
alias: ‘Timer to turn off bedroom light’
sequence:
- delay: ‘00:{{ time | int }}:00’
- service: light.turn_off
data:
entity_id: light.bedroom_light
####### Wrapper to start turn_off_bedroom_light_timer with logic of cancel existing timer
turn_off_bedroom_light_timer_wrapper:
alias: ‘Timer to turn off bedroom light - wrapper’
sequence:
- service: script.turn_off
data:
entity_id: script.turn_off_bedroom_light_timer
- delay: ‘00:00:01’
- service: script.turn_off_bedroom_light_timer
data_template:
time: ‘{{ time | int }}’

Add IFTTT applets

Start timer applet

Cancel timer applet

Cheers :slight_smile:

1 Like

This is great. I wonder how the new google assistant integration will affect this.

I am trying to do this for a fan.

Here is the Script, can you tell me what I am doing wrong?

####### Main timer script
turn_off_master_bedroom_fan_timer:
alias: 'Timer to turn off master bedroom fan’
sequence:

  • delay: ‘00:{{ time | int }}:00’
  • service: light.turn_off
    data:
    entity_id: light.master_bedroom_fan
    ####### Wrapper to start turn_off_master_bedroom_fan_timer with logic of cancel existing timer
    turn_off_master_bedroom_fan_timer_wrapper:
    alias: 'Timer to turn off master bedroom light - wrapper’
    sequence:
  • service: script.turn_off
    data:
    entity_id: script.turn_off_master_bedroom_fan_timer
  • delay: ‘00:00:01’
  • service: script.turn_off_master_bedroom_fan_timer
    data_template:
    time: ‘{{ time | int }}’