Help with vacuum automation

I have an automation set up (below) to run my Roomba vacuums which is mostly working. The condition template was just added from reading another thread so not sure if that part is functional yet. What I really want it to do is more complex then I can manage to come up with though and I’m looking for some assistance. I’ll try my best to explain what I’m trying to do.

Run once a day only
Only start between 09:00-18:00 mon-sat
Only start if the tv is off (harmony integration)
Force start at 17:00 if it hasn’t already run

alias: Vacuum house
description: ''
trigger:
  - platform: time
    at: '12:00:00'
    id: time
  - platform: state
    to: not_home
    from: home
    for:
      hours: 0
      minutes: 15
      seconds: 0
    entity_id: group.someones_home
condition:
  - condition: time
    weekday:
      - mon
      - tue
      - wed
      - fri
      - sat
    before: '18:00:00'
    after: '09:00:00'
  - condition: template
    value_template: >-
      -{{ state_attr('this.entity_id','last_triggered') | default(today_at(),
      true) < today_at('05:00') }}
  - condition: state
    entity_id: remote.living_room
    state: power_off
    attribute: current_activity
action:
  - scene: scene.vacuum
mode: single

Are your written requirements incomplete? Because your automation does two things that aren’t mentioned in the requirements:

  1. It’s scheduled to run at noon.
  2. It will attempt to run 15 minutes after the house is vacated.

Those are just the triggers I added when I created it to try and get it going.
Ideally the vacancy trigger would apply starting at 09:00 and then a trigger covering the 12-18:00 if the tv is off.

Not sure if that really clarifies it

Not really. If you remove those two triggers, your list of four requirements only contain a single Time Trigger (with a condition):

  • Force start at 17:00 if it hasn’t already run

The first three requirements are defined in a way that would be implemented as conditions (not triggers).

  1. Run once a day only (this is a condition, unless you specify a specific time when it should trigger).
  2. Only start between 09:00-18:00 mon-sat (this is a condition, unless you want it to trigger at 09:00).
  3. Only start if the tv is off (this is a condition, unless you want it to trigger the moment someone turns off the TV).

Okay let me try again.
Trigger if everyone leaves between 09:00-18:00
Trigger at 12:00 if the tv is off, if not continue to check every #mins until 17:00
Trigger at 17:00 regardless if it hasn’t run previously because of conditions

I’m still new and trying to learn what’s possible so I don’t even know if this is doable,

It’s all doable but we will be wasting out time if the requirements aren’t clearly defined. For example, the original list of requirements didn’t mention it should trigger the moment everyone leaves (yet the example you posted had it as a trigger). That’s why I asked for clarification.

Instead of “check every X minutes” why not just trigger the moment the TV gets turned off (between noon and 17:00)?

  • If a Time Trigger triggers at noon but the TV is not off (this is a condition), nothing happens; the automation doesn’t execute its action.
  • If a State Trigger monitoring the TV’s state, is triggered when the TV is turned off, and the Time Condition confirms it’s between noon and 17:00, the automation will execute its action (assuming all other conditions are also met).

Does that sound like the way you want it to work?


EDIT

What’s the TV’s entity_id? Is it remote.living_room?

Trigger between 9-12 if/when house is vacant
Trigger between 12-17 if/when TV has been off for 5mins
Trigger at 17 regardless of conditions above if it hasn’t run yet
Only run once a day

Yes - below variables “should” work

condition: state
entity_id: remote.living_room
state: PowerOff
attribute: current_activity

These two are problematic

Trigger between 9-12 if/when house is vacant
Trigger between 12-17 if/when TV has been off for 5mins

Is this behavior you want?

  • If the house becomes vacant between 9-12, it will trigger.

  • If the house becomes vacant between 12-17 it will not trigger.

  • If the TV turns off between 12-17, it will trigger.

  • If the TV turns off between 9-12, it will not trigger.

Basically, if the TV is turned off in the morning (or is never turned on) and the house becomes vacant shortly after 12:00, nothing will happen until the Time Trigger at 17:00. Seems like a waste of several hours when the vacuum could be operating.

Crap I suck at this. Okay
If the house becomes vacant between 9-17, trigger
At 12, if tv is off, trigger
If tv turns off between 12-17, trigger
At 1700, trigger

Start with this and we can adjust it if needed:

alias: Vacuum house
description: ''
trigger:
  - platform: time
    at:
      - '09:00:00'
      - '12:00:00'
      - '17:00:00'
  - platform: state
    entity_id: group.someones_home
    to: not_home
    from: home
    for:
      minutes: 15
  - platform: state
    entity_id: remote.living_room
    attribute: current_activity
    to: power_off
condition:
  - condition: time
    after: '09:00:00'
    before: '17:01:00'
    weekday:
      - mon
      - tue
      - wed
      - fri
      - sat
  - condition: state
    entity_id: group.someones_home
    state: not_home
    for:
      minutes: 15
  - condition: state
    entity_id: remote.living_room
    attribute: current_activity
    state: power_off
  - "{{ state_attr('this.entity_id', 'last_triggered') | default(today_at(), true) < today_at('09:00') }}"
action:
  - scene: scene.vacuum
mode: single

EDIT

Correction. Remove leading word condition: from Template Condition.

Trigger is 15 minutes after the Harmony is turned off or 5:00 PM. Create a toggle helper. Call it Vacuum has run, or whatever. Youll need another automation that turns that toggle back off every night at midnight.

alias: Run Vacuum
description: ''
mode: single
trigger:
  - platform: device
    type: turned_off
    device_id: 065681e3bdecd9525368eb4113591cce
    entity_id: remote.harmony_hub
    domain: remote
    for:
      hours: 0
      minutes: 15
      seconds: 0
    id: Harmony Off
  - platform: time
    at: '17:00:00'
    id: Failsafe
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: Harmony Off
          - condition: time
            before: '18:00:00'
            after: '09:00:00'
            weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
              - sat
        sequence:
          - service: vacuum.start
            data: {}
            target:
              device_id: c639fa4c6d03aa3a1dd55f150479895c
          - service: input_boolean.turn_on
            data: {}
            target:
              entity_id: input_boolean.vacuum_notification_has_run
      - conditions:
          - condition: trigger
            id: Failsafe
          - condition: device
            type: is_off
            device_id: 065681e3bdecd9525368eb4113591cce
            entity_id: remote.harmony_hub
            domain: remote
          - condition: state
            entity_id: input_boolean.vacuum_notification_has_run
            state: 'off'
          - condition: time
            before: '00:00:00'
            weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
              - sat
        sequence:
          - service: vacuum.start
            data: {}
            target:
              device_id: c639fa4c6d03aa3a1dd55f150479895c
          - service: input_boolean.turn_on
            data: {}
            target:
              entity_id: input_boolean.vacuum_notification_has_run
    default: []

I don’t understand how this would work. The way I read this it will only start between 9-17 if no one is home and the tv is off. How do the conditions apply to the specific triggers.

Message malformed: Unexpected value for condition: '{{ state_attr('this.entity_id', 'last_triggered') | default(today_at(), true) < today_at('09:00') }}'. Expected and, device, not, numeric_state, or, state, sun, template, time, trigger, zone @ data['condition'][3]

Thanks for this but it leaves out several of the triggers I’m looking for or I just completely don’t understand it.

Okay so here are two separate automations that if both are enabled will trigger the action like I want. Only trouble is, since they are separate, the condition to only run once a day applies to each separately. How do I combine them so they only run once.

alias: Vacuum house (Duplicate1)
description: ''
trigger:
  - platform: state
    to: not_home
    from: home
    for:
      hours: 0
      minutes: 15
      seconds: 0
    entity_id: group.someones_home
  - platform: time
    at: '17:00:00'
condition:
  - condition: time
    weekday:
      - mon
      - tue
      - wed
      - fri
      - sat
    before: '18:00:00'
    after: '09:00:00'
  - condition: template
    value_template: >-
      -{{ state_attr('this.entity_id','last_triggered') | default(today_at(),
      true) < today_at('05:00') }}

alias: Vacuum house (Duplicate2)
description: ''
trigger:
  - platform: state
    to: PowerOff
    for:
      hours: 0
      minutes: 5
      seconds: 0
    entity_id: remote.living_room
    attribute: current_activity
  - platform: time
    at: '12:00:00'
condition:
  - condition: time
    weekday:
      - mon
      - tue
      - wed
      - fri
      - sat
    before: '18:00:00'
    after: '12:00:00'
  - condition: template
    value_template: >-
      -{{ state_attr('this.entity_id','last_triggered') | default(today_at(),
      true) < today_at('05:00') }}
  - condition: state
    entity_id: remote.living_room
    state: PowerOff
    attribute: current_activity
    for:
      hours: 0
      minutes: 5
      seconds: 0

Like I said, it’s a starting point and it can be adjusted.

That’s my mistake. I have corrected the example. All you need to do is remove the leading condition: from the Template Condition.

The first one’s Template Condition is invalid. Remove the leading hyphen. Also, why have you chosen 05:00 for the template’s time?

The automations allow for vacuuming when the TV is on in the morning (no one home but TV left on). Is that the behavior you wish to allow?

Similarly they allow vacuuming in the afternoon even if someone is home as long as the TV is off.

Made that adjustment

I copied this from another thread and just forgot to adjust the time.

I have another automation that shuts everything in the house off if everyone leaves. Besides, if no one is there watching, who cares if you can’t hear because the vacuum is running. :wink:

Yes. I just don’t want it to start if I’m home watching TV. At least not until 17:00

Probably from one of my posts because I recognize the template, right down to the time which met the needs of the person for whom I created the template.

Understood. It can run when no one is home (morning and afternoon) or when someone is home as long as the TV is off (but only in the afternoon). I can adapt the original example to meet these requirements.

That sounds right