My vacuum waits by the trashcan to be emptied

Nov 22, 2022

My robot vacuum positioned next to a trashcan.

I have a robot vacuum, but not one of the higher end models that empties itself. Instead, I've set up my vacuum to drive itself over to the trashcan when it needs emptying. Here's how it works.

Honestly, I think this is a feature that should be implemented by default on most robot vacuums. It would require no changes to the hardware, just a new software feature. Perhaps it would reduce sales of the higher priced self-emptying models though.

In my case, I have a Roborock S4 Max and I'm using Home Assistant to set up the automations.

To get started, I first needed to hook up the vacuum to Home Assistant. This was not that easy, but I found this guide on smarthomepursuits.com to get things rolling. The short version is that you set up the robot using the manufacturer's generic app, rather than the Roborock app. Then you use a script to extract the vacuum cloud tokens for sending commands. I also assigned the vacuum a fixed ip on my local network which IIRC made things a little easier. I won't repost those instructions, because they are great.

The next step is to understand out how the "go to" command works. Here is a screenshot from Home Assistant showing the service with params X and Y.

Home Assistant Services Page showing the xiaomi_miio.vacuum_goto service.

The X and Y aren't well documented, but my understanding is that they are approximately millimeters from the charging base at (0, 0). If you look at the floor map in your house, anything to the upper right from the charger will be positive X, positive Y.

I didn't pull out a tape measure. Instead, I just tried some numbers, saw where the vacuum ended up, and tried new numbers. After a few iterations of this, I was where I wanted the vacuum to stop for emptying.

The next thing to track is the state. "vacuum.roborock_vacuum_a19" has several statuses in my testing:

Unfortunately, my vacuum didn't seem to register a state for any dust-bin changes, such as the bin being taken out or put back in.

To make this all work, I create a new state variable that I track, initially set to "clean". When the status goes to "cleaning", I set my state to "dirty". Then, when the vacuum status goes to "docked" and my state is "dirty", I call the command to go to the trash can and set my state to "waiting". Finally, when the vacuum status goes to "docked" and my state is "waiting", I set my state to "clean".

I've actually punched this state machine up a little bit over time, so that it won't leave the charger if I'm not home or the battery is too low that it might run out while waiting for me to empty, but that's all unnecessary. You can see my appdaemon script here if it's useful.