Skip to main content

How To Control Your Xiaomi Robot Vacuum With Google Home

xiaomi robot cleaner integration

Excited to turn your home into the Ultrahouse 3000?

Use Google Home and/or Google Home mini to control your Xiaomi Vacuum with your voice!

Here are the things you need:

This is a brief HOW-TO guide and some of the finer details may be omitted. If you hit any trouble just ask in the comments below. [2019-03-24: Updated walk-through to use the new access methods for Home Assistant]

How It Works

This is how I have mine configured at the moment. A quick overview on how how everything works:

  1. Create a WebApplet in IFTTT (Account required) with an activation phrase (e.g. Release The Hounds)
  2. Pair Google Home Assistant to IFTTT
  3. Now say 'Hey Google, release the hounds' within your Assistant's earshot
  4. Google assistant will forward it to IFTTT
  5. IFTTT will call a web hook (your Home Assistant server)
  6. The Home Assistant Webhook sends the command to your XiaoMi vacuum cleaner
  7. Your vacuum cleaner starts cleaning the house.

Down the road I'd try and see if it's possible to script everything from within Home Assistant.

Know Before You Start

This requires an Internet connection to work. Google Home needs to talk to the Internet to understand your voice commands, and the IFTTT service needs to get into your home network to activate the XiaoMi robot.

Configuring all this may be daunting to people who has never done this before. But by bouncing ideas off each other, you will get all this to work if you stay committed.

Extracting The Damn Token

Let's get the most difficult thing out of the way first - retrieving the XiaoMi token.

This token is an auto-generated password, a special code the XiaoMi robot Vacuum use to verify the person has the authority to control it. Supply the token to your vacuum the wrong token and it will not accept the commands.

New: miio (Added 21 Feb 2018)

This may be the easiest way to extract the token. You'd need a computer with Wifi (be it a computer laptop or a PC with a Wifi dongle).

  1. Find a computer or notebook with Wifi access
  2. Install nodejs (Download the LTS version): Link
  3. Start a new command window (or console or terminal)
  4. run the following command:

    npm install -g miio
  5. Reset the wifi on your robot vacuum (if you have previously registered your vacuum to MiHome you have to delete the device and re-register again)
  6. The XiaoMi wifi should be enabled. Connect your laptop/PC's wifi to this new Wifi LAN. No password is required.
  7. Once connected to the Vacuum Wifi, run the following command:

    miio discover
  8. You should see the token.
  9. Note that the token will no longer be visible once the Vacuum is registered. So if you forget the details you'd have to reset the wifi connection agian.

If you get the token now, skip to the next page. Otherwise continue below to find other ways to extract the token.

Apple iPhone

There are a lot of information out there on how to extract this token from your iPhone. I have spent a day trying and just failed to work it out.

Perhaps it's because my iPhone isn't jail broken. If you want a sure-proof way to get the token with an iPhone, don't!

Use an android phone or tablet instead! Hey you are using Google Home, there are bound to be a Windows computer and Android device lying around somewhere. Because MiHome is cloud based, all you need to do is to install MiHome to an Android device, log in to your XiaoMi account and everything you need will be transferred over. Here's how to do it:

  1. Find an android phone.
  2. Install MiHome from the Play Store.
  3. Sign in to MiHome with your XiaoMi account.
  4. Your robot vacuum will show up if you have already paired the Robot Vacuum earlier. If not just setup it up now.
  5. And that's it! The XiaoMi token is now stored on your Android phone and is now ready for extraction.

Android Phone

The quickest way to do perform the token extraction is from an Android device, and using a tool call the MiTookkit:

  1. Turn on USB debugging (If you havn't done this before you need to activate Developer Settings menu).
  2. Your Windows computer should already have Java installed. If not, download and install the Java Runtime Environment (JRE).
  3. Connect your Android device to your Windows computer.
  4. Your Android device will prompt you for authorisation. Click Allow or Accept.
  5. Download the latest version of MiToolkit in a Windows computer. Extract the archive and run the MiToolKit program.
  6. Click the button that says 'Extract Token'.
  7. Read the instructions, and click the 'Extract Token' again to begin extraction.
  8. A prompt will remind you not to set a password. Click the 'OK' button to continue.
  9. Now your Android Device will have a prompt about performing a full backup. Click the 'Back Up My Data' button (Note this prompt will be different across the Android platform).
  10. If you succeed, the token will be displayed in the text box like so:
  11. This token is re-generated every time you pair the XiaoMi robot vacuum to your MiHome. So if you delete this device from MiHome and repair, you have to do this token extraction all over again.

You are one step closer with this token. We now move on to Home Assistant. 

Home Assistant

Installation

There are several ways to run Home Assistant - e.g. on a Raspberry Pi, or on a normal computer. Since I already have a home lab running at home, I'm using the PC method (running in a virtual computer). Once you have a Linux machine setup, you can install Home Assistant easily by following these simple instructions: Installation in virtualenv.

A better solution for most people would be to run Home Assistant on a Raspberry Pi. I have created a HOWTO detailing the steps of installing Hassbian. If you don't have a Home Assistant setup, buy a Pi and install Hassbian now.

Basic HTTP Server configuration

This section already assumes you're using HTTPS to secure your web page. Newer versions of Home Assistant forces you to use an account now. If you're still using an older version that requires API_PASSWORD, update to the latest version now.

Login to your Home Assistant computer, and edit the configuration.yaml file (Usually located in /home/homeassistant/.homeassistant). If you are new to Linux, use the nano editor when editing files. 

In the file, go to the section that says http: and set it to the following

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
http:
#api_password: !secret http_password
base_url: https://<your_ip_or_domain_name_here

Save the file and restart HomeAssistant.

Home Assistant

Adding XiaoMi

Edit configuration.yaml again and now add in the XiaoMi robot Vacuum:

Replace ip_address_of_robot with the IP address of your XiaoMi robot. You can find this information from the MiHome app (Go to your Vacuum, the network information is under General Settings → Network Info). Because the Vacuum is never powered off, the IP address is unlikely to change. But if you want to be safe you can always configure your router or DHCP server to always allocate a specific IP address for your XiaoMi.

Replace super_secret_password_token with the token you have extracted earlier.

Replace name_of_robot with a unique name (this is used to identify different components in the Home Assistant Web App). Now Restart Home Assistant again, and you should see this appear in the dashboard. I'm calling my vac 'The Hounds':

Click the vacuum icon (picture to the left of the name) and you will see all the stats.  Flick the switch in the lower right hand corner, and hear your Vacuum roar (or in my case - bark).

If everything works, well done. You'll need to enable IFFFT In Home Assistant.

Integrate IFTTT Into your Home Assistant

In your Home Assistant portal. Click on Configurations, followed by Integrations:

Scroll down the list of items until you see the entry IFTTT. Click it's configure command.

Copy down the URL on this screen, you'll going to need this later when configuring your IFTTT Web Applets.

Over the next few steps we'll need to jump back and forth between the two IFTT and your Home Assistant Portals.

IFTTT

IFTTT stands for IF This Then That. Refer to this wikipedia article if you are unfamiliar with this protocol. Start your web browser and go to https://ifttt.com. Login to your IFTTT account (or sign up if you don't have one).

IFTTT - Integration with Google Assistant

Register your Google Home/Mini device to your Google Home app. You'll need to do this so your google voice searches will look into the IFTTT ecosystem.

Skip this if you already have already added the Google Assistant IFTTT service.

  1. From your IFTTT portal, click the My Applets (marked in illustration below):
  2. Now click 'Services':
  3. Select All Services:
  4. Enter Google Assistant in the search box, and click the Google Assistant tile:
  5. Click the Connect button:
  6. Follow the prompts and login with your Google Account (Remember to use the same account for Google Home).
  7. When prompted, allow ifttt.com to manage your Google voice commands:

IFTTT - Add Service Webhooks

Skip this if you are already connected to the WebHooks service:

  1. Select All Services:
  2. Find the WebHook service and click the Webhooks picture:
  3. Click the Connect button:

IFTTT - Find Your Secret code for Home Assistant

Home Assistant and IFTTT needs to share the same password. To get this password, follow these instructions:

  1. Login to your IFTTT web page
  2. Click on My Applets → Services.
  3. Find the WebHooks tile and click it.
  4. Click the Settings button located in the top right corner:
  5. You should see this settings page next, copy your special ifttt password (Copy only the password, not the entire URL):
  6. Return to your Home Assistant computer. Edit the configuration.yaml file.
  7. Add a new section for IFTTT like so, replace your_ifttt_special_password with your unique code:
  8. Setup a new Automation to handle IFTTT webhookes, edit your automations.yaml and add the following block:

    - trigger:
    platform: event
    event_type: ifttt_webhook_received
    event_data:
    action: call_service
    action:
    service_template: '{{ trigger.event.data.service }}'
    data_template:
    entity_id: '{{ trigger.event.data.entity_id }}'
  9. Restart Home Assistant. If you get no errors your Home Assistant setup should now be complete!

If you think that was hard, you may not like the next section :).

Linking Everything Together

IFTTT Needs To Find You From The Internet

IFTTT needs to know your IP address because it needs to talk back to your Home Assistant. Unfortunately for most people your Internet IP changes all the time.e.g. Here in Australia most people will get a different IP address when they re-connect to their ISP.

To work around this problem, you need to subscribe to a dynamic hostname service. With a dynamic host name setup, your hostname remains the same regardless what your Internet IP address is. 

DuckDNS is a service that came up while I was researching this subject.  Have not tried this service myself but will do so eventually. Setting up a dynamic hostname is beyond the scope of this article, there are already a lot of resources on the Internet on how to get this working. 

IFTTT Firewall Permissions

Your Internet router's firewall will typically stop IFTTT from talking to your IP directly. Therefore you need allow this permission on your router.

In computer speak - this means forwarding port 8123 into your home assistant computer's IP. Every router does this differently, look for anything that says NAT, Port Forwarding or Virtual Host. Here's an example of mine (called Port Forwarding):

Both these sections are beyond the scope of this article. However feel free to comment below if you want me to help you out on these.

Check your dynamic hostname and firewall rule is working by using an online port checker tool. Enter your personal hostname and port 8123 in the field and click the Check button. 

If all goes well you should see the text 'Port 8123 is open'. If you have gone this far, well done!

Now let's start creating some IFTTT statements!

IFTTT

Now start your Web browser and login to your IFTTT account again.

Go into My Applets → Services and double check you have the following three services installed.

You are ready to create your very first Web Applet!

IFTTT - This Component

Here's your first Web Applet. How to use voice command to start vacuuming.

  1. In My Applets → Services, click the New Applet button:
  2. This took me a long time to work it out. Maybe obvious to people who are used to tablet devices, but not to me. Begin by clicking the word text:
  3. Enter Google in the search file, and click the Google Assistant tile:
  4. Click the 'Say a simple phrase' tile:
  5. In the 'What Do You Want To Say' field, type in the voice command you want to use. e.g. I want to start vacuuming when I say these words - 'Release The Hounds'. You can leave the two optional say fields blank for now (more on this later in trouble shooting).
  6. The last response box is Google home's response to your voice command. In the following example, when I say 'Release the Hounds', Google home will respond with 'Releasing The Hounds'.
  7. Click the Create Trigger button to create the Trigger. You should see the this bit is now replaced with the Google Assistant tile:
  8. This completes the this part of the IFTTT.

In the next page, we will finish the that component.

IFTTT - That Component

In the previous page we have configured the this component of IFTTT. When that condition is true (i.e. when somebody says 'Hey Google, release the hounds!'), an action will be triggered. This action is defined in the that component of the IFTTT Web Applet. To define what happens, continue the configuration:

  1. Click on the text that:
  2. Enter Webhooks in the search field, and click the Webhooks tile:
  3. Click the tile that says 'Make a web request'
  4. Paste the URL given to you by Home Assistant during the IFTTT integration steps. Use this same URL when creating future Web Applets for your Home Assistant. The URL should look like so:

      https://<your_ip_or_domain>/api/webhook/<random_magic_sequence>
  5. The Method should be POST.
  6. The Content Type should be Application/JSON.
  7. The body is where all the magic is at. Enter the following (replacing name_of_robot with the actual name of your robot, specified in your configuration.yaml mentioned here):

      { "action": "call_service", "service": "vacuum.start", "entity_id":"vacuum.name_of_robot"}
  8. Your panel should look something like this (Make sure you fill in your own URL):

  9. Click Create Action to complete.
  10. Click Finish.

You are ready to Rock And/Or Roll. Say the voice command (e.g. Release The Hounds) and see what happens. If the XiaoMi Vacuum starts cleaning, that's it. You've done it!

If nothing happens, or if Google responded with a phrase that's different from what you specified in the this component, go to the next page for troubleshooting.

Trouble Shooting

You can refer to the Home Assistant log file and hopefully it will tell you what the problem is:

Here are some issues I have discovered along the way. If you have a different problem please comment below and I'd address them:

Google Home/Mini responded with the correct phrase, but nothing happens to the Xiaomi Vacuum

Most likely to be a network or communications issues. Follow the checklist and make sure everything is working:

  • IFTTT password is correct in Home Assistant configuration.yaml file
  • Home Assistant password is correct in IFTTT actions
  • Dynamic hostname has the correct Internet IP
  • Port 8123 is open on the Internet
  • Incoming port 8123 is forwarding to the correct IP of your Home Assistant computer

Google Mini/Home responded with an incorrect phrase.

This happens when Google 'speech to text' technology can't work out what you're saying. e.g. .When I say 'release the hounds', Google always return me a google search instead. This means your speech is interpreted incorrectly.

To diagnose this problem, go to MyActivity (either viaGoogle Home app or the https://myactivity.google.com website). Look through your search history until you find the card with your voice activity.

This is the card when I said the phrase 'release the hounds':

So Google thinks I'm saying 'house' instead of 'hounds'. You can click the play button to hear a recording of your voice. The easiest way to fix this problem is to add 'release the house' as the secondary phrase. 

To fix:

  1. Go to your IFTTT, click on My Applets, and find the IFTTT tile:
  2. Click the cog icon (marked with white arrow):
  3. Add the new phrase in the optional field
  4. Click Save
  5. Now say the voice command again. It should work now :)

Other Commands

In your JSON body, the entry

"service": "vacuum.start"

is the command to start the cleaning. You can change the service command to something else for other things. Here's the list (as of 0.90.1):

Command Description
vacuum.clean_spot Tell the vacuum cleaner to do a spot clean-up.
vacuum.locate Locate the vacuum cleaner robot.
vacuum.pause Pause the cleaning task.
vacuum.return_to_base Tell the vacuum cleaner to return to its dock.
vacuum.send_command Send a raw command to the vacuum cleaner.  Parameters for the command. { "key": "value" }
vacuum.set_fan_speed vacuum.set_fan_speed
vacuum.start Start or resume the cleaning task.
vacuum.start_pause Start, pause, or resume the cleaning task.
vacuum.stop Stop the current cleaning task.
vacuum.toggle No idea what this is doing
vacuum.turn_off Stop the current cleaning task and return to home.
vacuum.turn_on Start a new cleaning task.
vacuum.xiaomi_clean_zone Start the cleaning operation in the selected areas for the number of repeats indicated.
xiaomi_remote_control_move Remote control the vacuum cleaner, make sure you first set it in remote control mode with `remote_control_start`.
xiaomi_remote_control_move_step Remote control the vacuum cleaner, only makes one move and then stops.
xiaomi_remote_control_start Start remote control of the vacuum cleaner. You can then move it with `remote_control_move`, when done call `remote_control_stop`.
xiaomi_remote_control_stop Stop remote control mode of the vacuum cleaner.

Some of these services require additional key value/pairs in the JSON body. You can refer to the Home Assistant API for more information.

Questions?

Please comment below if you have any questions or suggestions. Check out the Home Automation section for more articles like these.

I'm trying new things on the social media. If you are an audiophile, or am interested in Home Automation/Systems Integration, please join the following community:

That's it for now. Still finding new ideas for home automation. Be on the lookout for more in the future.

Comments

Anonymous (not verified) Fri, 06/07/2018 - 16:15

In reply to by FilipeOS (not verified)

Thank you so much because I’ve setup the Roborock to Europe and now I can’t go back to China since it’s forcing me to change Region… I can’t do anything unless go to Europe again… I tried almost everything…

Join/Tasker allow you to do the same thing you did but without servers, I just don’t have that experience…

agent_kith Sun, 24/03/2019 - 09:59

api_password deprecated in 0.90. This tutorial updated with new information on how to integrate IFTTT with Home Assistant using the new access methods.

Gaetano (not verified) Tue, 24/12/2019 - 12:31

Finally this guide is updated! Everything works perfectly but I really don’t understand how to set the fan speed. Can someone help?

I tried in body section:

{ "action": "call_service", "service": "vacuum.set_fan_speed", "entity_id": "vacuum.xiaomi_vacuum_cleaner", "fan_speed": "quiet"}

It does not work.

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Contents