Automation wait action using template

I am new to Home Assistant and trying to get around how the wait action works within Automations.
I have a robot vacuum that I don’t want turning on when the TV is on. I have this working by adding a condition that the TV is off which works fine, however I want the automation to run up to an hour later if I turn the TV off, else if I have my TV on at 10am each day then the vacuum will never turn on.
I have played around with the wait action by moving elements within the automation around but now it won’t run at all which makes me think I have the template wrong (even though nothing is erroring and the automation is being accepted). Setting a timeout means it just waits for the time out and then just turns the vacuum on after that time period. Clearly I have misunderstood something. I have created the automation in the UI.
What I hope its doing is wait for up to an hour for the TV state to switch to off, then turn on the vacuum.
Below is the extract from my automation.yaml file so hopefully you can spot my mistake

- id: '1602364625274'
  alias: Turn on Mr Sweepy
  description: ''
  trigger:
  - platform: time
    at: '10:00'
  condition:
  - condition: time
    weekday:
    - mon
    - wed
    - sat
  action:
  - wait_template: "{{ is_state('media_player.sony_bravia_tv', 'off') }}"
    timeout: 01:00:00    
    continue_on_timeout: false
  - service: vacuum.start
    data: {}
    entity_id: vacuum.mr_sweepy

At a first glance that looks absolutely fine to me, are you certain that the problem doesn’t lie elsewhere?

Hmmm… i was hoping there was something wrong with it. I will have debug session tomorrow, with simple Boolean toggles just to rule out the integrations. The below code works fine using the TV as a condition which makes me think that vacuum or TV plugin is fine.

- id: '1602364625274'
  alias: Turn on Mr Sweepy
  description: ''
  trigger:
  - platform: time
    at: '10:00'
  condition:
  - condition: time
    weekday:
    - mon
    - wed
    - sat
  - condition: device
    device_id: e02407540b3e11eb9a1b6de682fd153b
    domain: media_player
    entity_id: media_player.sony_bravia_tv
    type: is_off
  action:
  - service: vacuum.start
    data: {}
    entity_id: vacuum.mr_sweepy

Fresh eyes this morning and I sorted it. In honesty no idea what I changed to make it work, but I recreated the automation and it worked. I think the timeout setting was causing an issue… but either way now works.

1 Like