Start vacuum when leaving home (tado)

Hello,

I am absolutely new t Home Assistant and have been messing around the last couple of days trying to integrate my Xiaomi Roborock S6 MaxV. I finally succeeded: the vacuum can be controlled via Home Assistant.

Now I want to go one step further and automate the cleaning process.
Therefore I want the vacuum to start whenever everybods in the household has left the house.
Since tado knows when all people have left the house I figured it would be best to use tado as trigger.
Unfortunately this is where all my attempts fail. The system won’t even let me save my attempts.

This is the best I came up with.

platform: state
entity_id: sensor.arbeitszimmer_tado_mode
from: HOME
to: AWAY

action:
  - service: vacuum.start
    entity_id: vacuum.xiaomi_vacuum_cleaner

Can anyone give me a hint o how to proceed?
Would be very thankful.

Regards
Bacardi Man

Your automation is missing several important things, the values for from and to should be in lowercase, and the indentation isn’t quite correct.

Try this:

alias: Start Vacuum
trigger:
- platform: state
  entity_id: sensor.arbeitszimmer_tado_mode
  from: home
  to: away
action:
- service: vacuum.start
  entity_id: vacuum.xiaomi_vacuum_cleaner

If you ever want to know an entity’s actual state values, inspect the entity in Developer Tools > States.

1 Like

Thank you very much!

Is there a way to prevent the vacuum from starting twice a day?
Should be a condition, right?

Here’s what I suggest, create a History Stats sensor to record the amount of time your vacuum operates during the day (it automatically resets itself at midnight):

sensor:
  - platform: history_stats
    name: Vacuuming Time Today
    entity_id: vacuum.xiaomi_vacuum_cleaner
    state: 'on'
    type: time
    start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'

Now add a condition to your automation that checks if the History Stats sensor reports zero (in other words, the vacuum has not yet logged any operating time today).

alias: Start Vacuum
trigger:
- platform: state
  entity_id: sensor.arbeitszimmer_tado_mode
  from: home
  to: away
condition: "{{ states('sensor.vacuuming_time_today') | int == 0 }}"
action:
- service: vacuum.start
  entity_id: vacuum.xiaomi_vacuum_cleaner
2 Likes

Wow, lightning fast support, thank you!

I insertet the first code into the configuration.yaml
Then I tried to insert the condition into the existing automation.

Unfortunately I then am presented the following message:
Message malformed: Unexpected value for condition: ‘{{ states(‘sensor.vacuuming_time_today’) | int == 0 }}’. Expected numeric_state, state, sun, template, time, zone, and, or, not, device @ data[‘condition’][0]

By the way: would that also be possible:

condition: "{{ states('sensor.vacuuming_time_today') | int >= 60 }}"

Try this version:

alias: Start Vacuum
trigger:
- platform: state
  entity_id: sensor.arbeitszimmer_tado_mode
  from: home
  to: away
condition: 
- condition: template
  value_template: "{{ states('sensor.vacuuming_time_today') | int == 0 }}"
action:
- service: vacuum.start
  entity_id: vacuum.xiaomi_vacuum_cleaner

That condition requires the vacuum to have already operated for a certain amount of time ( > 60) before it will execute the action. You want to execute the action only if the vacuum has not operated yet (i.e. allow it to run only once a day).

Thank you very much again.
Now everything seems to work just fine.

I tried to edit your code to int <= 60.
Therefore the vacuum should only start if it hasn’t been running for one hour or longer, since cleaning the whole appartement takes it around 1,5 hours.

I appreciate your help.
Thank you very much!

1 Like

You’re welcome!

Please consider marking either my first or second post with the Solution tag (you can only mark one of them). It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has an accepted solution. Effectively, it indicates your issue is resolved and helps users find answers to similar questions.

Dear Taras,

can you please help me out again?
I had to set up Home Assistant from scratch again an can’t get that condition to work.

My configurations.yaml looks like this

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

sensor:
  - platform: history_stats
    name: Vacuuming Time Today
    entity_id: vacuum.roborock_s6_maxv
    state: 'on'
    type: time
    start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'

My automation looks like this

platform: state
entity_id: sensor.arbeitszimmer_tado_mode
from: home
to: away
for:
  hours: 0
  minutes: 15
  seconds: 0

condition: 
- condition: template
  value_template: "{{ states('sensor.vacuuming_time_today') | int <= 0 }}"

device_id: 5ddc124576c87c575f00f42027a0dd66
domain: vacuum
entity_id: vacuum.roborock_s6_maxv
type: clean

But whenever I try to hit that save button I am presented the following message:

Message malformed: Unexpected value for condition: ‘[{‘condition’: ‘template’, ‘value_template’: “{{ states(‘sensor.vacuuming_time_today’) | int <= 0 }}”}]’. Expected and, device, not, numeric_state, or, state, sun, template, time, trigger, zone @ data[‘condition’][0]

What am I doing wrong?

best regards
Bacardi Man

If it looks like that then it’s completely invalid. It has no alias or action and its indentation is wrong in many places.

If you tried to create the automation manually (with a text editor), I suggest you delete it and use the Automation Editor to create it.

Dear Tas,

this the full code from the automation.yaml.
Ist was created by using the Atuomation Editor.

- id: '1648758836666'
  alias: Starte Saugroboter
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.arbeitszimmer_tado_mode
    from: home
    to: away
    for:
      hours: 0
      minutes: 15
      seconds: 0
  condition: []
  action:
  - device_id: 5ddc124576c87c575f00f42027a0dd66
    domain: vacuum
    entity_id: vacuum.roborock_s6_maxv
    type: clean
  mode: single

best regards
Bacardi Man

I think editing the code in the automation.yaml instead of trying to input the code in the Automation Editor in yaml-view solved the problem.

Thank you very much!