Zoned cleanup with Live-map

I recently tweeted my Home Assistant UI for zoned cleanup with my vacuum cleaner:

If you want to do something like that you need a Xiaomi Mi Robot Vacuum and a Home Assistant installation (preferably Hass.IO) . Here’s a quick howto.

Installing Valetudo on your vacuum

First step: I installed Valetudo on my Xiaomi Mi Robot Vacuum. For that you need to root your robot and re-flash it. A nice side effect is that your vacuum will no more communicate with the Xiaomi cloud servers thanks to some IP rerouting performed by Valetudo.

The downside is that you loose the live map that is drawn in the Xiaomi app. But there is a addon that will bring it back as a camera device

I won’t go in the details of installing Valetudo and the Hass.IO addon. The instructions on the linked websites are quite extensive

The UI

The UI YAML in Home Assistant is quite simple:

As you can see it’s based on a picture-elements card with the floor plan image floorplan.jpg (I created mine with

The first element on top of it is the camera image from the addon. You need to fit it onto your floor plan manually. Ideally you perform a complete cleanup which generates a new map. Then reduce the opacity and play around with the rotate and translate parameters until it fits:

Now you can add the picture elements for the respective zones e.g. vacuum_eg_kueche.png. These could be just rectangles with different colors or more complex masks matching your floorplan.
You can use the CSS style parameters to position them and to adjust opacity, saturation, etc.
As entity you use some input_boolean entities that you create in your config, e.g. input_boolean.kueche_vacuum_zone.

Script the cleanup

Now you need a script that starts a cleanup of the zones activated by the input_booleans:

Make sure to reference the exact zone names you have setup in the Valetudo Web interface for defining zones under zone_ids.

That’s it. Add the script as a button to your UI and you’re done except for one tiny issue:

Map rotation / Map displacement

By default the vacuum creates a new map when a new cleanup is started. This will usually mess up the exact positioning of the map on your floorplan. More than this the Gen1 robot seems to change the map orientation sometimes and the defined zones won’t match anymore.

One option would be to never start a new cleanup but that is quite inconvenient. Someone however found a way to restore a previously saved map and described it here:

I added a simple automation that restores the map whenever the vacuum’s state changes to “docked”, so I always have the perfectly matching map whenever the vacuum returns to the docking station.

But be careful! I just learned from the author of this that your robot may reboot or even reset if you start a cleanup within the next few seconds after restoring the map.

He recommends to build a custom Valetudo firmware with this soon to be merged PR:

It should allow you to trigger the map reset via mqtt. I’ll definitely try that one to be safe.

What’s next?

As you can see quite a few building blocks are required to get it right. I would hope that the map restoring will seen be integrated in Valetudo so we can at least skip this part.

Meanwhile Valetudu is really nice to use and I definately prefer it over Xiaomis app. Combined with Home Assistant it’s close to perfect.