How I set up room-cleaning automation with Google Home, Home-Assistant and Xiaomi vacuum cleaner

89,684 reads

I use Home-Assistant running in a Raspberry Pi as the main hub to automate all my smart home devices. It is set up to connect to my Xiaomi Mi Roborock vacuum cleaner, with a basic interface to start, pause and dock the cleaner. The Mi Home app is more advance, able to map the plan of my home as it scans and cleans the place.

The vacuum cleaner works really well to clean the whole house automatically. But if I want to just clean a particular room at home, I have to use the Mi Home app to draw a rectangle (zone) around the room in the house plan to start the zone cleaning. The app does not save this, so each time I want to clean a different room, I have to repeat the same steps.

Wouldn’t it be great if I can automate this? This post made me realized it may not be difficult to achieve this.

Hey Google, clean the bedroom

The goal is to be able to issue a command to Google Home to tell the vacuum cleaner to clean just a small area at home. Here is step-by-step of what I did:

Find out the coordinate of a corner of a room to figure out the scale of the coordinates

Map out the coordinates of each room at home

Create an IFTTT recipe with Google Assistant as the trigger, and webhook as action to call my Home-Assistance server.

Testing app_goto_target command in service dev tool in Home-Assistant

Home-Assistant service dev tool can be used to call services for any devices connected to it. There is a command called app_goto_target that can be used to send the vacuum cleaner to any coordinates.

The docking point of the vacuum cleaner always have the coordinate [25500, 25500]. This is somewhere in my study room. Through trial-and-error, I figured out the coordinate of a corner of my study room. It can be any point in the house. It will provide a reference to draw a map later with scale later.

Screenshot of the Mi Home app that is used to control the Xiaomi vacuum cleaner

The Mi Home app has my entire home plan mapped out. I took a screenshot of that, opened it in Sketch and overlaid grids to draw out the x and y-axis. This provides a rough estimate for all the coordinates in the house.

Screenshot of my home plan created by the Mi Home app, with grids and coordinates overlaid in Sketch app. The green dot with coordinate [25500,25500] is the vacuum cleaner docking station.

The vacuum cleaner supports a command for zone cleaning called app_zoned_clean. It takes in a array 5-digit-numbers, each describes a rectangle called zone — the first two digits are the coordinates of the bottom left corner of the zone, the second two digits for the top right corner of the zone, and the last digit for number of times to clean a zone.

With all room coordinates mapped out, I tested them in Home-Assistant and made small tweaks if I have to. The zone can be slightly bigger than the room, but it should not overlap into another room.

Testing app_zoned_clean command in service dev tool in Home-Assistant

With all the rooms in my house mapped out, the next step was creating IFTTT recipes to allow Google Home to communicate with Home-Assistant to send these commands to my vacuum cleaner. Each recipe was created by choosing Google Assistant as the IFTTT trigger, and webhook as action.

Google Assistant as IFTTT Trigger, and Webhook as Action to call API in Home-Assistant

It is also possible to create a recipe to get the vacuum cleaner to clean the area a few times because the 5th digit sets the number of times to clean the area.

Hey Google, clean the kitchen 3 times

Google Assistant as IFTTT Trigger, with option to say a phrase with a number

The params field takes in an array of zones, so it is possible to create an automation that cleans an area with a customized shape. For example, when the vacuum cleaner is mopping the floor in my living room, I would like to exclude the area where the rug is.

Hey Google, mop my living room

Screenshot of the Mi Home app showing the 4 zones in my living room, excluding the area where the rug is

That’s it. Now I can ask Google Home to clean any rooms at home.

IFTTT recipes to clean rooms with Google Home and Xiaomi vacuum cleaner

Related posts:

How I got my vacuum cleaner to talk back to me via Telegram.

Tags