Integrate your Xiaomi or Roborock robot vacuum cleaner with Home Assistant

Previously, we integrated the Ecovacs robot vacuum cleaners, blink cameras as well as connected objects Smart Life/Tuya in Home Assistant. Today, we continue our momentum by integrating Xiaomi and Roborock vacuum cleaners into Home Assistant. Brands widely used by fans of home automation and whose reputation is second to none.

You can also find the Roborock S4 tests, S5 Max, S6 and S7+ in our lab'. Convincing robots acclaimed by their users that we particularly appreciate and that we rank among the best robot vacuum cleaners on the market!

« Alexa, ask Nestor to clean the kitchen. "

Currently the following services are supported:

  • start : Start the robot vacuum
  • pause : Pause the robot vacuum
  • stop : Stop the robot vacuum
  • return_to_base : The robot vacuum cleaner returns to its charging base
  • locate : Used to locate the vacuum cleaner
  • clean_spot : Send the vacuum robot to clean a specific corner of the housing
  • set_fan_speed : Allows you to control the suction speed (Silent, Standard, Medium, Turbo)
  • remote_control_ * : Control the vacuum cleaner with the virtual keys
  • xiaomi_clean_zone : Allows you to send the robot vacuum cleaner to a specific room

Set up a Xiaomi Roborock robot in Home Assistant

For the proper functioning of the integration it will be necessary get the token (token) which will allow your vacuum cleaner to interact with the API as well as set your IP address from your ISP box or router.

Static IP for Xiaomi robot vacuum cleaner

To set the IP of your device, you just have to go to the interface of your internet box or router. For my part, it will be since livebox / to access my Orange internet box.

Static DHCP Leases Roborock S6 Vacuum Cleaner
Static DHCP Leases Roborock S6 Vacuum Cleaner

There you have it, your vacuum cleaner has a fixed IP address. If you restart your internet box, Home Assistant will be able to find your robot vacuum easily.

Easily recover a Xiaomi Mi Home token

DifficultyEasy
Total time5 mins

1

Download the latest version of the application “Get Mi Home Devices Token App” on Github for Windows or macOS.

Recover Xiaomi Home token

2

Install the app : on Windows as on MacOS, an authorization is necessary. Don't worry, the code is public and available on Github, it has been validated by the community.

Get Token Xiaomi security issue

3

Enter your account credentials : username (login) and password (password).

Log in with your Xiaomi Home credentials

4

Select token that you want to recover.

5

You can now use your Xiaomi Home token in a third-party integration or application. Note, however, that your device remains tied to the cloud and will not work locally.

Xiaomi Home Token for Homey Pro

Ingredients

 1 Xiaomi Home device
 1 “Get Mi Home Devices Token App” app

Instructions

1

Download the latest version of the application “Get Mi Home Devices Token App” on Github for Windows or macOS.

Recover Xiaomi Home token

2

Install the app : on Windows as on MacOS, an authorization is necessary. Don't worry, the code is public and available on Github, it has been validated by the community.

Get Token Xiaomi security issue

3

Enter your account credentials : username (login) and password (password).

Log in with your Xiaomi Home credentials

4

Select token that you want to recover.

5

You can now use your Xiaomi Home token in a third-party integration or application. Note, however, that your device remains tied to the cloud and will not work locally.

Xiaomi Home Token for Homey Pro

Retrieve a Xiaomi Mi Home token

Old methods

If you prefer alternative methods, you can always retrieve the token of a Xiaomi or Roborock vacuum robot from the Xiaomi Home application. The procedure is different for an iOS device and an Android device.

Retrieve the token from an Android device:

  1. Add (if it is not already done) your vacuum cleaner on the application Xiaomi Home
  2. Uninstall the Xiaomi Home app (Yes Yes..)
  3. From your phone, download Aptoide
  4. From Aptoide, download the Mi Home app 5.4.54 (Secure, old official version of Xiaomi Home)
  5. Open the Mi Home app freshly installed then wait a few seconds for your devices to appear
  6. Once most of your devices have appeared you can close the application
  7. Open the application "File manager" and look for the file « SmartHome »
  8. This folder will contain log files, open the most recent file (opening it from a computer will be much easier to find your computer's token)
  9. Find the name of your vacuum cleaner, once found, there will be a little before a line that looks like: {token: XXXXXXXXXXXXXXX} 
  10. Copy this token, we need him for the rest of the tutorial 

This token changes when you disconnect or remove the vacuum cleaner from your Wi-Fi network.

Retrieve the token from an iOS device:

  1. Add (if it is not already done) your vacuum cleaner on the application Xiaomi Home
  2. On a PC or Mac with iTunes installed, you need to backup iPhone.
  3. install iBackupViewer, open it and open your backup
  4. Open the "raw data" module (tree-shaped logo)
  5. Access to com.xiaomi.mihome
  6. Look for a file that looks like XXXXXXX_mihome.sqlite in the file Documents
  7. Save this file to your computer
  8. install DB Browser for SQLite  (The portable version is sufficient)
  9. Open DB Browser for SQLite, click on "Open a database" then go to select the previously downloaded file (XXXXXXXX_mihome.sqlite)
  10. In the tab "Browse data" scroll through the columns to the last column (ZTOKEN)
  11. Click on it, you should see the token we want to use
  12. Your token is encrypted, we will decrypt it from a free site
  13. The right column should look like this:

Key (required): 00000000000000000000000000000000

This token changes when you disconnect or remove the vacuum cleaner from your Wi-Fi network!

Configuration in Home Assistant

The most complicated is over, you can now integrate your vacuum cleaner into Home Assistant.

For integrate your vacuum cleaner into Home Assistant, add this in your file configuration.yaml

vacuum:
- platform: xiaomi_miio
host: 192.168.XX
token: Your_token
name: Nestor

Once the file is saved, restart your Home Assistant server.

The variables of the xiaomi_miio integration

  • host : The IP address of your vacuum cleaner
  • token : The API token we retrieved earlier
  • name : The name you want to assign to your robot vacuum cleaner (Here, Nestor 🙂)

Congratulation! Your Xiaomi or Roborock robot vacuum cleaner is now integrated!

The attributes available for Xiaomi and Roborock robot vacuums

Your vacuum cleaner informs us on many points:

  • battery_icon : The battery% of your vacuum cleaner
  • cleaned_area : The number of m² cleaned 
  • fan_speed : The suction speed of the vacuum cleaner
  • fan_speed_list : The list of suction speeds available for your vacuum cleaner

But the integration xiaomi_miio de Home Assistant allows us to know more:

  • cleaning_time : The time taken by the vacuum cleaner to clean
  • main_brush_left : Hours remaining until a main brush change is required
  • side_brush_left : Hours remaining until a side brush change is required
  • filter_left : Hours remaining until a filter change is required
  • sensor_dirty_left : Hours remaining before cleaning the sensors
  • cleaning_count : Total number of cleaning cycles
  • total_cleaned_area : Total area cleaned in m² 
  • total_cleaning_time : Total cleaning time in minutes
  • do_not_disturb : Activation / Deactivation of do not disturb mode
  • clean_start : The last date / time the vacuum cleaner started cleaning
  • clean_end : The last date / time the vacuum cleaner finished cleaning

All attributes can be used in a scenario and you can simply display them in a map. 🙂

Possible script for the filters and brushes of your Xiaomi robot vacuum cleaner

The vacuum cleaner stores attributes like main_brush_left ou filter_left which allow to know the number of hours remaining before changing the component in question. However, once the change is made the attribute does not automatically reset. I therefore propose a scenario allowing you to reset the value once the change has been made:

reset_brosse_principal_nestor:
alias: "Reset the time of the main brush of Nestor"
sequence:
- service: vacuum.send_Command
date:
entity_id: vacuum.nestor
command: reset_consumable
params: ['main_brush_work_time']

Available settings:

  • ['main_brush_work_time']
  • ['side_brush_work_time']
  • ['filter_work_time']
  • ['sensor_dirty_time']

This is a script and not an automation.

home assistant script
home assistant script

You can call your script from a virtual button on the dashboard or add it to a self-regulating automation techniques.

Retrieval of cleaning details

In order to target a targeted room or area we need coordinates. 

Using the FLOLEVAC application

Available only for Android devices
  1. Download Flolevac
  2. Log in with your Xiaomi credentials (Tested by Google Play Protect)
  3. Open the map (Make sure you are on your home network)
  4. Select "Zone cleaning" et draw a square around the area that you want to clean
  5. Long press " Cleaning " and the coordinates of the area will be copied to your clipboard

Automation with coordinates 

I offer you an automation that allows you to launch a cleaning of a specific area 

  - alias: Kitchen cleaning
trigger:
- event:start
platform: homeassistant
condition: [] action:
- service: xiaomi_miio.vacuum_clean_zone
data_template:
entity_id: vacuum.nestor
repeats: 1
zone: [[XXXXX, XXXXX, XXXXX, XXXXX]
  • entity_id : replace it with the name of your vacuum cleaner
  • repeats : here it will clean this area once (you can put the number of repetitions you want)
  • areas : the area (s) to be cleaned 

Example with two zones:

zone: [[30914,26007,35514,28807], [20232,22496,26032,26496]]

Lovelace card for your Xiaomi or Roborock vacuum cleaner

I also share with you a additional integration interesting that allows you to start cleaning a specific part using a static map, as in the Mi Home app. In addition, vYou can define a list of zones and choose which ones to clean.

Roborock S6 Lovelace Card on Home Assistant

Do not hesitate to share in comments or via the facebook group your scenarios that help you on a daily basis. 🙂

Several feathers of enthusiastsAlexa to concoct articles with 4 or more hands ... Collaborative writing to address the most specialized or transversal subjects, the best home automation and connected home plans on the web, and much more ...