This library (and its accompanying cli tool, miiocli
) can be used to control devices using Xiaomi's
miIO
and MIoT protocols.
This is a voluntary, community-driven effort and is not affiliated with any of the companies whose devices are supported by this library. Issue reports and pull requests are welcome, see contributing!
The full documentation is available at python-miio.readthedocs.io.
- Installation
- Getting started
- Controlling modern (MIoT) devices
- Controlling older (miIO) devices
- Troubleshooting
- API usage
- Contributing
- Simulators
- Supported devices
- Projects using this library
- Other related projects
The most recent release can be installed using pip
:
pip install python-miio
Alternatively, you can install the latest development version from GitHub:
pip install git+https://github.com/rytilahti/python-miio.git
This project is currently ongoing a major refactoring effort. If you are interested in controlling modern (MIoT) devices, you want to use the git version until version 0.6.0 is released.
The miiocli
command allows controlling supported devices from the
command line, given that you know their IP addresses and tokens.
The simplest way to acquire the tokens is by using the miiocli cloud
command,
which fetches them for you from your cloud account using micloud:
miiocli cloud
Username: example@example.com
Password:
== name of the device (Device offline ) ==
Model: example.device.v1
Token: b1946ac92492d2347c6235b4d2611184
IP: 192.168.xx.xx (mac: ab:cd:ef:12:34:56)
DID: 123456789
Locale: cn
Alternatively, see the docs for other ways to obtain them.
After you have your token, you can start controlling the device.
First, you can use info
to get some generic information from any (even yet unsupported) device:
miiocli device --ip <ip> --token <token> info
Model: rockrobo.vacuum.v1
Hardware version: MW300
Firmware version: 1.2.4_16
Supported using: RoborockVacuum
Command: miiocli roborockvacuum --ip 127.0.0.1 --token 00000000000000000000000000000000
Supported by genericmiot: True
Note that the command field which gives you the direct command to use for controlling the device.
If the device is supported by the genericmiot
integration as stated in the output,
you can also use miiocli genericmiot
for controlling it.
You can always use --help
to get more information about available
commands, subcommands, and their options.
Most modern (MIoT) devices are automatically supported by the genericmiot
integration.
Internally, it uses ("miot spec") files to find out about supported features,
such as sensors, settings and actions.
This device model specific file will be downloaded (and cached locally) when you use the genericmiot
integration for the first time.
All features of supported devices are available using the common commands status
(to show the device state), set
(to change the settings), actions
to list available actions and call
to execute actions.
Executing status
will show the current device state, and also the accepted values for settings (marked with access RW
):
miiocli genericmiot --ip 127.0.0.1 --token 00000000000000000000000000000000 status
Service Light (light)
Switch Status (light:on, access: RW): False (<class 'bool'>, )
Brightness (light:brightness, access: RW): 60 % (<class 'int'>, min: 1, max: 100, step: 1)
Power Off Delay Time (light:off-delay-time, access: RW): 1:47:00 (<class 'int'>, min: 0, max: 120, step: 1)
To change a setting, you need to provide the name of the setting (e.g., light:brightness
in the example above):
miiocli genericmiot --ip 127.0.0.1 --token 00000000000000000000000000000000 set light:brightness 0
[{'did': 'light:brightness', 'siid': 2, 'piid': 3, 'code': 0}]
Most devices will also offer actions:
miiocli genericmiot --ip 127.0.0.1 --token 00000000000000000000000000000000 actions
Light (light)
light:toggle Toggle
light:brightness-down Brightness Down
light:brightness-up Brightness Up
These can be executed using the call
command:
miiocli genericmiot --ip 127.0.0.1 --token 00000000000000000000000000000000 call light:toggle
{'code': 0, 'out': []}
Use miiocli genericmiot --help
for more available commands.
Note, using this integration requires you to use the git version until version 0.6.0 is released.
Older devices are mainly supported by their corresponding modules (e.g.,
roborockvacuum
or fan
).
The info
command will output the command to use, if the device is supported.
You can get the list of available commands for any given module by
passing --help
argument to it:
$ miiocli roborockvacuum --help
Usage: miiocli roborockvacuum [OPTIONS] COMMAND [ARGS]...
Options:
--ip TEXT [required]
--token TEXT [required]
--id-file FILE
--help Show this message and exit.
Commands:
add_timer Add a timer.
..
Each command invocation will automatically try to detect the device model. In some situations (e.g., if the device has no cloud connectivity) this information may not be available, causing an error. Defining the model manually allows to skip the model detection:
miiocli roborockvacuum --model roborock.vacuum.s5 --ip <ip> --token <token> start
The miiocli
tool has a --debug
(-d
) flag that can be used to enable debug logging.
You can repeat this multiple times (e.g., -dd
) to increase the verbosity of the output.
You can find some solutions for the most common problems can be found in Troubleshooting section.
If you have any questions, feel free to create an issue or start a discussion on GitHub. Alternatively, you can check our Matrix room.
All functionalities of this library are accessible through the miio
module. While you can initialize individual integration classes
manually, the simplest way to obtain a device instance is to use
DeviceFactory
:
from miio import DeviceFactory
dev = DeviceFactory.create("<ip address>", "<token>")
dev.status()
This will perform an info
query to the device to detect the model,
and construct the corresponding device class for you.
You can introspect device classes using the following methods:
-
sensors()
to obtain information about sensors. -
settings()
to obtain information about available settings that can be changed. -
actions()
to return information about available device actions.
Each of these return device descriptor objects, which contain the necessary metadata about the available features to allow constructing generic interfaces.
Note: some integrations may not have descriptors defined. Adding them is straightforward, so feel free to contribute!
We welcome all sorts of contributions: from improvements or fixing bugs to improving the documentation. We have prepared a short guide for getting you started.
If you are a developer working on a project that communicates using the miIO/MIoT protocol,
or want to contribute to this project but do not have a specific device,
you can use the simulators provided by this project.
The miiocli
tool ships with simple simulators for both miIO and MIoT that can be used to test your code.
While all MIoT devices are supported through the genericmiot
integration, this library supports also the following devices:
- Xiaomi Mi Robot Vacuum V1, S4, S4 MAX, S5, S5 MAX, S6 Pure, M1S, S7
- Xiaomi Mi Home Air Conditioner Companion
- Xiaomi Mi Smart Air Conditioner A (xiaomi.aircondition.mc1, mc2, mc4, mc5)
- Xiaomi Mi Air Purifier 2, 3H, 3C, 4, Pro, Pro H, 4 Pro (zhimi.airpurifier.m2, mb3, mb4, mb5, v7, vb2, va2), 4 Lite
- Xiaomi Mi Air (Purifier) Dog X3, X5, X7SM (airdog.airpurifier.x3, x5, x7sm)
- Xiaomi Mi Air Humidifier
- Smartmi Air Purifier
- Xiaomi Aqara Camera
- Xiaomi Aqara Gateway (basic implementation, alarm, lights)
- Xiaomi Mijia 360 1080p
- Xiaomi Mijia STYJ02YM (Viomi)
- Xiaomi Mijia 1C STYTJ01ZHM (Dreame)
- Dreame F9, D9, L10 Pro, Z10 Pro
- Dreame Trouver Finder
- Xiaomi Mi Home (Mijia) G1 Robot Vacuum Mop MJSTG1
- Xiaomi Roidmi Eve
- Xiaomi Mi Smart WiFi Socket
- Xiaomi Chuangmi camera (chuangmi.camera.ipc009, ipc013, ipc019, 038a2)
- Xiaomi Chuangmi Plug V1 (1 Socket, 1 USB Port)
- Xiaomi Chuangmi Plug V3 (1 Socket, 2 USB Ports)
- Xiaomi Smart Power Strip V1 and V2 (WiFi, 6 Ports)
- Xiaomi Philips Eyecare Smart Lamp 2
- Xiaomi Philips RW Read (philips.light.rwread)
- Xiaomi Philips LED Ceiling Lamp
- Xiaomi Philips LED Ball Lamp (philips.light.bulb)
- Xiaomi Philips LED Ball Lamp White (philips.light.hbulb)
- Xiaomi Philips Zhirui Smart LED Bulb E14 Candle Lamp
- Xiaomi Philips Zhirui Bedroom Smart Lamp
- Huayi Huizuo Lamps
- Xiaomi Universal IR Remote Controller (Chuangmi IR)
- Xiaomi Mi Smart Pedestal Fan V2, V3, SA1, ZA1, ZA3, ZA4, ZA5 1C, P5, P9, P10, P11, P15, P18, P33, P39, P45
- Xiaomi Rosou SS4 Ventilator (leshow.fan.ss4)
- Xiaomi Mi Air Humidifier V1, CA1, CA4, CB1, MJJSQ, JSQ, JSQ1, JSQ001
- Xiaomi Mi Water Purifier (Basic support: Turn on & off)
- Xiaomi Mi Water Purifier D1, C1 (Triple Setting)
- Xiaomi PM2.5 Air Quality Monitor V1, B1, S1
- Xiaomi Smart WiFi Speaker
- Xiaomi Mi WiFi Repeater 2
- Xiaomi Mi Smart Rice Cooker
- Xiaomi Smartmi Fresh Air System VA2 (zhimi.airfresh.va2), VA4 (va4), T2017 (t2017), A1 (dmaker.airfresh.a1)
- Yeelight lights (see also python-yeelight)
- Xiaomi Mi Air Dehumidifier
- Xiaomi Tinymu Smart Toilet Cover
- Xiaomi 16 Relays Module
- Xiaomi Xiao AI Smart Alarm Clock
- Smartmi Radiant Heater Smart Version (ZA1 version)
- Xiaomi Mi Smart Space Heater
- Xiaomiyoupin Curtain Controller (Wi-Fi) (lumi.curtain.hagl05)
- Xiaomi Dishwasher (viomi.dishwasher.m02)
- Xiaomi Xiaomi Mi Smart Space Heater S (zhimi.heater.mc2)
- Xiaomi Xiaomi Mi Smart Space Heater 1S (zhimi.heater.za2)
- Yeelight Dual Control Module (yeelink.switch.sw1)
- Scishare coffee maker (scishare.coffee.s1102)
- Qingping Air Monitor Lite (cgllc.airm.cgdn1)
- Xiaomi Walkingpad A1 (ksmb.walkingpad.v3)
- Xiaomi Smart Pet Water Dispenser (mmgg.pet_waterer.s1, s4, wi11)
- Xiaomi Mi Smart Humidifer S (jsqs, jsq5)
- Xiaomi Mi Robot Vacuum Mop 2 (Pro+, Ultra)
Feel free to create a pull request to add support for new devices as well as additional features for already supported ones.
If you are using this library for your project, feel free to open a PR to get it listed here!
Home Assistant uses this library to support several platforms out-of-the-box. This list is incomplete as the platforms (in parentheses) may also support other devices listed above.
- Xiaomi Mi Robot Vacuum (vacuum)
- Xiaomi Philips Light (light)
- Xiaomi Mi Air Purifier and Air Humidifier (fan)
- Xiaomi Smart WiFi Socket and Smart Power Strip (switch)
- Xiaomi Universal IR Remote Controller (remote)
- Xiaomi Mi Air Quality Monitor (PM2.5) (sensor)
- Xiaomi Aqara Gateway Alarm (alarm_control_panel)
- Xiaomi Mi WiFi Repeater 2 (device_tracker)
- Xiaomi Mi Home Air Conditioner Companion
- Xiaomi Mi Smart Pedestal Fan
- Xiaomi Mi Smart Rice Cooker
- Xiaomi Raw Sensor
- Xiaomi MIoT Devices
- Xiaomi Miot Auto
This is a list of other projects around the Xiaomi ecosystem that you can find interesting. Feel free to submit more related projects.
- dustcloud (reverse engineering and rooting xiaomi devices)
- Valetudo (cloud free vacuum firmware)
- micloud (library to access xiaomi cloud services, can be used to obtain device tokens)
- micloudfaker (dummy cloud server, can be used to fix powerstrip status requests when without internet access)
- Xiaomi Cloud Tokens Extractor (an alternative way to fetch tokens from the cloud)
- Your project here? Feel free to open a PR!