Automation Logic - action on timeout

I am trying to create an automation and struggling a bit with the logic and how best to implement. Essentially an elaborate way to turn my robot vacuum on. I have the individual parts working but just not as one workflow. Essentially what I want to achieve is outlined below:

1 - Start trigger at 10am
2 - Condition to check its either Monday/Wednesday/Friday
3 - Verify TV is switched off (wait up to 2 hours for it to be turned off)
4 - Send notification to phone asking to turn Vacuum on
5 - Response from user will either turn on Vacuum or cancel and do nothing
6 - Turn on vacuum

Issue is I only want 4 & 5 to run if it hits the two hour time out, as is then even if the TV is off then it sends me the notification to start. I want the vacuum to start automatically if the tv is off.

Is there a way to start an automation when the timeout is hit? That way I can just move item 6 up to item 4 and create a new automation with item 4 and item 5 driven by the timeout.

Any help would be much appreciated.

1 Like

Use a template condition between 3 and 4 that tests whether the appropriate wait variable is true or false…

Ok. I have this for part 3

wait_template: ' {{ is_state(''media_player.sony_bravia_tv'' , ''off'') }}'
timeout: '02:00:00'
continue_on_timeout: false

I will have a play with the wait variables and see if I can get it working. It looks like I should be able to based on the link. I will report back if I succeed. (or if I don’t!)

1 Like

Oh my actual days I thought I was going mad! I read through that page a number of times thought I fully understood what was going on but it still wasn’t working. A very long trial and error session behind me, it was the damned:

continue_on_timeout: false

that was still present from my previous attempt and I hadn’t spotted it! So it now works a treat!

Below is my complete automation if anyone else wants to use it as a base for something. I think I could optimise it by removing the first choose case, but now I have it working I am nervous to edit it!

- id: '1602426166791'
  alias: Turn on Mr Sweepy
  description: ''
  trigger:
  - platform: time
    at: '10:00'
  condition:
  - condition: time
    weekday:
    - tue
    - thu
    - sun
  action:
  - choose:
    - conditions:
      - condition: device
        domain: media_player
        entity_id: media_player.sony_bravia_tv
        type: is_off
      sequence:
      - service: vacuum.start
        data: {}
        entity_id: vacuum.mr_sweepy
    - conditions:
      - condition: device
        domain: media_player
        entity_id: media_player.sony_bravia_tv
        type: is_on
      sequence:
      - wait_template: ' {{ is_state(''media_player.sony_bravia_tv'' , ''off'') }}'
        timeout: 02:00:00
      - choose:
        - conditions:
          - condition: template
            value_template: '{{ wait.completed }}'
          sequence:
          - service: vacuum.start
            data: {}
            entity_id: vacuum.mr_sweepy
        - conditions:
          - condition: template
            value_template: '{{ not wait.completed }}'
          sequence:
          - service: notify.mobile_app_deadpool
            data:
              message: TV is still on... start Mr Sweepy?
              data:
                push:
                  category: mrsweepy_notify
        default: []
    default: []
  mode: single