Xiaomi units we monitor and control with the Mqtt protocol.

Xiaomi Roborock Vacuum Cleaner

We now have a ready-made control program for this via mqtt. The program has the following features that are not found in the app:

1. zone based cleaning – eg clean kitchen.
2. Multi zone based eg clean living room and kitchen.
3. Waypoints eg goto livingroom

It is possible to define up to 10 zones and 10 waypoints in the cfg file.
Otherwise, the software has most of the commands that are also in the app (see below).
And best of all, the program allows Roborock to be controlled from whichever  automation system via the MQTT protocol.
To obtain the code (the token) for this we had to follow this recipe. And when we got connected  we received the status from it. 🙂
We also have another method to get the token, and this is described in the doc file including with the installation file.
Commands via mqtt. examples:
miio/set/vaccum/ = 1 – start cleaning of whole house
miio/set/vaccum/ = 1 –go to docking station
miio/set/vaccum/ = kitchen, livingroom, hall  – clean these zones
miio/set/vaccum/ = hallway  – goto hallway

.The following commands are available:
home = 1 – go to docking stationpause =
start = 1
clean = 1 (clean house-all zones)
speed = 1 -100 (%)
setvol = 1-100 (%)
stop = 1
spot = 1 – spot cleaning
soundtest = 1 – it says ‘Starting the cleanup!’ Resume_zoned_clean = 1
resume_or_start = 1
goto = x, y-coordinate
multi = section1, section3, section5 (defined in cfg file) – clean -clean multiple zones i
n one command
waypoint =xxx like ‘kitchen’ (x, y defined in cfg file) –
goto waypoint
find = 1 (say “Hi, I’m over here”)

Waypoint the command is based on the setup in the cfg file where you can define up to 10 waypoints.
It provides an opportunity to connect to a voice-controlled system such as Google Home or Alexa. one say e.g. ‘Hey Google, waypoint kitchen (or’ go to kitchen ‘if you want) and the robot goes to the point on the map you have predefined as kitchen in the cfg file.
The same applies to zone-based cleaning. All zones must be defined in the cfg file in advance .
After this is done, the voice command ‘Hey Google, clean the living room!’ cause the robot to do just that. 🙂
The zones defined are also used in Multisone cleaning where you can ask the robot to clean several zones in the order you choose.
Then the command ‘Hey Google, clean the living room and kitchen!’ cause it to be spotlessly clean there.
The Find command can be used either if one wants company or if one wants to drive away any unauthorized person with a female voice calling “Hey, I am over here!”

We hope to do manual control with voice control via Alexa or Google Home.
Then you will theoretically be able to have Roborock in your heels. 🙂

Xiaomi Air Purifier

We have come so far that we have ready a monitoring module for Xiaomi’s air purifier 2s.
This retrieves the status from the air purifier and publishes data to the mqtt broker.

We also have a control module that is waiting for a command to control the air purifier.
The following commands are possible, depending on the model:
Power (on, off) *
Operation modes (car, silent, favorite, idle) *
Buzzer (on, off)
Child lock (on, off)
LED (on, off)
Led_brightness (value)
Favorite Level (0… 16)
Reset filter ()
Autodetect (on, off)
Extra features (value)
Learn mode (on, off)
Volume (value) volume on buzzer

* tested and works on Air purifier 2s (zhimi.airpurifier.ma2)

The following data is published to the mqtt broker:
power = On, Off
aqi = 1->
average_aqi = 1->
temperature = degrees Celsius
humidity = 0-100%
mode = OperationMode (Silent, Auto, Idle, Favorite)
led = On, Off
led_brightness = Bright, Dim, Off
illuminance = 0-100 (lux)
buzzer = On, Off
child_lock = On, Off
favorite_level = 0-16
filter_life_remaining = days
filter_hours_used = hours
use_time = sec
purify_volume = m3
motor_speed = speed
motor2_speed = speed if exits
volume = 0-100
filter_rfid_product_id = id
filter_rfid_tag ​​= tag
filter_type = regular, anti-bacterial, anti-formaldehyde, unknown
learn_mode = On, Off
sleep_mode = Silent, Idle
sleep_time = sec
sleep_mode_learn_count = int
extra_features = int
turbo_mode_supported = True, False
auto_detect = None, On, Off
button_pressed = None or button (Power)


The project is based on the library python-miio which requires minimum python ver. 3.5 or higher
Many customers who have bought Xiaomi’s Airpurifier 2s have experienced that they do not get the air cleaner into Xiaomi’s app for Android or IOS. Using the mqtt protocol, it is still possible to control the air purifier via the phone or via an automation system. To connect the air cleaner on your private wifi network, do the following:
Download Xiaomi’s MI Home app for your phone.
Choose profile> settings> Region > Mainland ChinaSelect profile> settings> Language> Chinese
Now the app language is Chinese so best to keep your tongue straight in your mouth.
Go back to the main screen and press Add device (+). Select the type of device.
You will get questions about wifi Network.
Choose your network and password.
After a while you can see that an air cleaner appears on the screen.
And the process that is now going wrong, but don’t despair! Perhaps you have to take the power to the air cleaner to connect to your network first.
Now you can access your local firewall / router and see which ipaddress the air cleaner has got and possibly reserve this.
You need unit id and token also to get to communicate.This can be done by installing a command line tool called miio with following command:
npm install -g mii
Then run the Miio discover command from a command window. All your Miio devices will then print in this format on the screen as they are found on your network:

Device ID: 48765421
Model info: zhimi.airpurifier.m1
Token: token-as-hex-here via auto-token
Support: At least basic

More info about this tool here..
Take care of this data, you will need it the later …