I have a slightly complicated construct for how I control my robot vacuums at home.

While I want to document things a bit for myself, this is also a show and tell of something fun to do with flexible smart home tooling.

Everyone Worked in Harmony

A while ago, I got myself one of those Roomba to keep dust under control. And while it keeps my floors nice and dust free, it is pretty loud when it does so. To avoid having to think about it, I set it up to run at 9am every morning. This also worked well, since I used to be in the office at that point.

But then the Virus Attacked

Then the pandemic hit, and suddenly I wasn’t away from home at 9am, but I was home. Understandably, I didn’t want to be interrupted by the little noise machine during focus time. Or just have a hard time hearing people on zoom or GVC.

So a plan was born. The robot needs to be smarter than just having a simple timer. And while there are various alternative firmware projects for popular vacuums out there, I have Home Assistant running. And it provides integrations for both iRobot and Roborock.

The plan is easy. Disable the schedule in the official app, and trigger a cleaning cycle when it’s convenient.

When is it Convenient?

Since the vacuums are autonomous once triggered, and I use them to force myself to keep my floors clean, there is really only 2 parameters to consider

  • Is it going to annoy me?
  • Is it going to annoy any neighbours?

and for good measure

  • It didn’t already run this day

Me!

The introduction already specified how I handle the noise.

I simply aim to not be home. And while I could send myself a notification that tells me to go away, it’s easer to detect whether I’m home.

With Home Assistant it should be easy to figure out whether I’m home. Luckily, there’s an integration that integrated with my wifi AP.

This allows me to track whether my phone is at home. Which is close enough to me being at home.

Neighbours?

Solving this perfect is probably impossible. So I simplified this to the point that I don’t feel guilty.

If it’s running in normal hours, it’s not loud enough that it’s an annoyance through walls. So this boils down to

  1. Is it between 9:00 and 20:00, Mo-Sa

Putting it All Together

Putting it all together is really just a couple of entities in HA.

The automation to kick of a cleaning cycle.

# The automations name
alias: Start roomba when reasonable
description: ""
# The automation should try to run, either
# * when I leave
# * when we enter the time gate
trigger:
  - platform: time
    at: "09:00:00"
  - platform: state
    entity_id:
      - input_select.homestate
    to: Away
# If any of these fail, don't run.
condition:
  # Check whether I'm away.
  # input_select.homestate changes to away based on the phone presence sensor.
  # I also use it to turn of my lights and some other things.
  - condition: state
    entity_id: input_select.homestate
    state: Away
  # Check whether it's in the correct time.
  - condition: time
    after: "09:00:00"
    before: "20:00:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
  # Ensure that this only runs once a day
  - condition: template
    value_template: >-
      {{ as_datetime(states.sensor.last_roomba_cleaning.state) <
      today_at('00:00') }}      
# Start both robot vacuums
action:
  - device_id: No IDs leaked
    domain: vacuum
    entity_id: No IDs leaked
    type: clean
  - device_id: No IDs leaked
    domain: vacuum
    entity_id: No IDs leaked
    type: clean
# Don't try to run this multiple times at once.
mode: single

And the template entity to track the last cleaning cycle

template:
- trigger:
    - platform: state
      entity_id:
        - No IDs leaked
      from: "cleaning"
  sensor:
    - name: "Last Roomba Cleaning"
      state: "{{ as_timestamp(now()) }}"

Further Ideas

While I’m pretty happy with the current setup, there’s minor things that could be better.

Integrate Holidays

Currently the time boxing does not respect holidays. While the presence detection is good enough for me, I’d like to add this for completeness sake.

Estimate Available Time

Sometimes I just go out to grab something for lunch and then come buck pretty soon. This often takes less time than the vacuum needs to clean. Most days I do this, I also leave for longer in the evening for practice.

It would be nice, if HA could use history of the presence detection, to

  • guess whether the current slot will suffice
  • guess whether there will be a second slot later that day

then adjust whether it triggers the vacuum now, or tries to wait.