Part 5: Roborock S7: Sequentially Vacuuming Rooms in Home Assistant

by Danny
4 comments

READING TIME: 6 MINUTES

In this guide, I’m going to show you how to create an automation that will sequentially (asynchronously) vacuum rooms in Home Assistant.

If you’ve been following along with my Roborock S7 Series, then you’ll know I created individual scripts that correspond to each room of my house.

  • script.vacuum_office
  • script.vacuum_kitchen
  • script.vacuum_living_room
  • etc

Roborock S7 Vacuum in Home Assistant Series

In case you are finding this guide from a Google search, you may want to revisit the previous guides I’ve created.

roborock S7 Robot Vacuum and Mop, 2500PA Suction & Sonic Mopping, Robotic Vacuum Cleaner with Multi-Level Mapping, Works with Alexa, Mop Floors and Vacuum Carpets in One Clean, Perfect for Pet Hair
  • Roborock S7 robot vacuum is the Winner of 17 Best of CES 2021 Awards, from Business Insider, Digital Trends, Newsweek, How To Geek, and many more. Please be aware products purchased from non-authorized channels are not covered by the official warranty.
  • Sonic Mopping Technology. Roborock S7 robot vacuum mops with the power of sound, scrubbing up to 3,000 times per minute. Fed by a 300 ml electronic water tank, stains from coffee to mud and more can be cleaned deeply and effectively.

Why create scripts for each room?

I did this for a number of reasons.

  1. It allows me to create an input_select in Lovelace that lets me choose a specific room to vacuum.
  2. I can expose these scripts to Google Assistant so I can trigger room vacuuming using my voice.
  3. Duplicated this setup to control Roborock S7 mopping in Home Assistant.
  4. It allows for greater flexibility in automations. (i.e. – schedule vacuuming of the Office, Kitchen, Living Room on Tuesdays, and the 3 bedrooms on Thursdays.)

I have 11 rooms in my house, so I have 11 scripts that look like this, each with different coordinates.

alias: 'Vacuum: Kitchen'
sequence:
  - service: xiaomi_miio.vacuum_clean_zone
    target:
      entity_id: vacuum.roborock_vacuum_a15
    data:
      zone:
        - - 29609
          - 17748
          - 34877
          - 24460
      repeats: 1
mode: single
icon: mdi:countertop-outline

You may or may not be aware of this, but you can actually schedule up to 5 rooms to be vacuumed in a single script. The 5-room maximum is a Roborock limitation, so if you have a different robot vacuum that may not apply to you.

That script would look like this. Each double-dash indicates a new room.

alias: 'Rosie: Vacuum 3 Zones'
sequence:
  - service: xiaomi_miio.vacuum_clean_zone
    target:
      entity_id: vacuum.roborock_vacuum_a15
    data:
      repeats: 1
      zone:
        - - 22474
          - 25558
          - 23025
          - 26115
        - - 23877
          - 25073
          - 24428
          - 25630
        - - 22474
          - 25558
          - 23025
          - 26115
mode: single

However, like I said, I have 11 rooms, so that solution won’t work for me. Ideally I would like to vacuum 7 “main rooms” on a schedule. (I don’t schedule vacuuming in the kids bedrooms, because, well, there’s always stuff on the floor.)

The solution? Create an automation that sequentially calls each room script.

This allows you to choose the order in which rooms are vacuumed, and allows you to schedule as many room cleanings as you want!


Automation #1: Vacuum Multiple Rooms by calling multiple scripts

Note: I recommend using Automation #2 instead of this one.

Originally, I had used the script below which DOES work perfectly. Basically, in the rooms: variable, you add the ending names of your scripts. In the service call, it loops through to the next one.

The automation will start running at 2:00pm, and vacuum the office first, then the dining room, kitchen, and finally the living room. It works by looking for the state of my vacuuming – which changes from “Cleaning” to “Returning” after a zone cleanup is complete.

Create Input Boolean

First, go to Configuration > Automations & Scenes > Helpers. Click Add Helper > Toggle. Name it “Home“.

This creates an input_boolean.home entity.

Then, we add this as a condition to the automation. The reason we are doing this is so we can quickly toggle the automation on or off if we are home. For example, if you go on vacation and don’t want it running like normal, just toggle this off.

alias: Vacuum Multiple Rooms
description: ''
trigger:
  - platform: time
    at: '14:00:00'
condition:
  - condition: state
    entity_id: input_boolean.home
    state: 'on'
action:
action:
  - variables:
      rooms:
        - 'office'
        - 'dining_room'
        - 'kitchen'
        - 'living_room'
  - repeat:
      count: '{{ rooms | count }}'
      sequence:
        - service: 'script.vacuum_{{ rooms[repeat.index - 1] }}'
        - wait_for_trigger:
            - platform: state
              entity_id: vacuum.roborock_vacuum_a15
              to: 'returning'
mode: single

However, one problem I ran into with that script is in regards to the vacuum battery level. If the battery level reaches 20%, it returns to the dock automatically to recharge. However, because the code above is looking for the state of “returning”, it still processes the next script (even though it won’t actually vacuum it).

As an example, let’s say I had 7 rooms added to the automation above. If it’s vacuuming the office (4th room out of 7) and the battery level reaches 20%, it tries to return home but the automation tells it to go to room 5, 6 and then 7. This confuses the vacuum and sort of gets it caught in a weird loop.

So, you are welcome to use the automation above, but I wanted to make sure you were aware of that caveat.


Automation #2: Vacuum multiple rooms, but check for battery level

A better solution would be to check for the battery level before processing the next script, which is exactly what I have below. I added a condition: that checks if the battery level is above 20%. If it is, it runs the next-in-line script. If it’s less than 20, it doesn’t and the vacuum returns home successfully to recharge.

alias: Vacuum Multiple Rooms Based if battery is greater than 20%
trigger:
  - platform: time
    at: '14:00:00'
condition:
  - condition: state
    entity_id: input_boolean.home
    state: 'on'
action:
  - variables:
      rooms:
        - 'office'
        - 'kitchen'
        - 'dining_room'
        - 'living_room'
        - 'breakfast_room'
        - 'master_bedroom'
  - repeat:
      while:
        - condition: template
          value_template: >-
            {{ repeat.index <= rooms|count and
            state_attr('vacuum.roborock_vacuum_a15','battery_level')|int(0) >
            20 }}
      sequence:
        - service: script.vacuum_{{ rooms[repeat.index - 1] }}
        - wait_for_trigger:
            - platform: state
              entity_id: vacuum.roborock_vacuum_a15
              to: returning
mode: single

Wrapping Up

Hopefully you found this guide as useful as I did! This was the last piece of the puzzle for me. I can now schedule groups of rooms to be vacuumed on a specific days automatically.


My Favorite Home Assistant Devices

Below are some of the Home Assistant-compatible devices I personally use in my home. I highly recommend each of them.

The full list of all Home Assistant compatible & recommended devices I use can be found on my Equipment List page.

Smart Home Product Finder

What hub do you currently use?


SmartThings

Home Assistant

Hubitat

Step 1 of 3

What product are you looking to add?


Lights

Locks

Thermostats

Cameras

Garage Door Opener

Switches

Sensors

Motion, Door & Window, Leak

Smart Plugs

Buttons

Step 2 of 3

What protocol?


Z-Wave

Zigbee

Wifi

Step 3 of 3

Retake quiz? Click here!

4 comments

You may also like

4 comments

Søren May 4, 2022 - 6:24 am

Great guides. Thank you very much. I just recieved my S7, so I’m looking forward to having all this magic in HA.

In regards to this, post #5: What happens if the robot reaches 20% and returns before cleaning the remaing rooms? Does it resume the task when fully, charged or are the last room just skipped?

Reply
Billy July 8, 2022 - 8:36 am

Looking at the script, I’m also curious if it continues after the battery is charged.

Does the robot go back to the dock between each zone when sent sequentially in the script? Or will it go to the next zone immediately after ending the previous?

Reply
Danny July 8, 2022 - 1:22 pm

Hey Billy. Yes, the vacuum will attempt to “return to home” after each script zone. (That’s just the default behavior of the vacuum after a zone cleanup is complete.)

However, it won’t actually back to the base until after the last zone script runs in this sequential script.

I’m not 100% sure if it continues after the battery is charged. I think it does continue, because once the battery reaches 80% charge, it continues where it left off.

Reply
Char July 18, 2022 - 6:58 pm

How would you make this automation park at the trash can when finished instead of returning to the dock? I was trying to figure out a decent method of doing this but I am not sure how I could modify your automation. I have mine run overnight and in the morning I empty the bin and fill the water before returning it to the dock using the button on the vacuum.

Reply

Leave a Comment