Universal Xiaomi integration - works with almost all Xiaomi devices!

Recently, Xiaomi brought out a new specification named MIoT-Spec. Let’s call it MIoT for short. It is used to communicate with ALL Xiaomi IoT devices. Compared with the old miio, this new specification is clear, highly adaptive, and open to all. Thanks to MIoT, nearly all Xiaomi IoT devices can be integrated into HASS in a very easy way. So I worked out this integration.

A list of supported devices: [meta] list of miot-enabled devices · Issue #627 · rytilahti/python-miio · GitHub

(TL/NR: ALL XIAOMI DEVICES!)

Installation

Using HACS (recommended):

  • Search for the integration “Xiaomi MIoT” and add it

Manual installation:

Configuration

Configure In UI:

  • After installation, add Xiaomi MIoT in ‘Integrations’ page, just like any other integrations.

(If you can’t find ‘Xiaomi MIoT’ but you are sure you have installed and restarted, this may because of your browser cache. Please try with another web browser.)

If you want to add devices from your Xiaomi account:

  • Select “登录小米账号”. Enter your credientals. Click “submit”.

  • If your devices are not in China server, select corresponding server in “Options”.

  • Add the integration again. Now, all devices in your account should appear in the list. Select the one you want to add.

  • You will see a window with two textboxes and two checkboxes. The textbox describes how device is read and controlled. You don’t need to change them unless you have some special needs. The checkboxes are for “Cloud Access”. Try uncheck them at first and click submit, if fails, check both of them.

  • If “Success” is shown, your device is ready to use!

Or if you prefer to add them by IP and token:

  • Select “接入设备”. A form will be shown shown to input them.

Configure In YAML (Deprecated):

What is “Cloud Access”?

Although Xiaomi has switched to MIoT, device manufacturers seems unwilling to use it. They stick to the old, unopened miio protocol. The device that implements miio instead of MIoT cannot be accessed via LAN. But don’t worry. Xiaomi Cloud is able to convert MIoT commands to miio commands and send them to the device via Internet. With your Xiaomi account, the integration sends commands - instead of to devices - to Xiaomi Cloud, so that all devices can work properly.

You can specify each device whether use Cloud Access or not. Please not that these devives will not work without Internet. Take care when use them in some important automations. To help you tell out devices with Cloud Access, there will be cloud in their entity ids.

Tested devices

  • chuangmi.plug.212a01 (works perfectly)

  • cuco.plug.cp1 (works perfectly)

  • mrbond.airer.m1t (requires Cloud)

  • leshi.light.wyfan (works perfectly)

  • lumi.acpartner.mcn02 (requires Cloud)

  • dmaker.fan.* (some requires Cloud and some not)

  • zhimi.fan.* (some requires Cloud and some not)

  • zhimi.airpurifier.* (some requires Cloud and some not)

  • deerma.humidifier.mjjsq (requires Cloud)

… and so on

For more information, please refer to xiaomi_miot_raw/README_en.md at master · ha0y/xiaomi_miot_raw · GitHub

If you have any questions or suggestions, please create an issue. You may use both English and Chinese.

I am using this right now! it works with my new aqara d1 wall swtich 3 gang no neutral, model QBKG25LM(lumi.switch.l3acn3) and also lumi.acpartner.v2 . Solving a big problem. Thanks!
Good job!

Thanks so much - confirming that it is working perfectly for me for a chuangmi.plug.212a01

Thanks! Works better than the Xiaomi App. The first link under your Configuration section threw me off but (skipping that link) everything worked flawlessly after that.

Tested on another chuangmi.plug.212a01.

Thanks everybody!

@siaox OK. I will update this post. I’m trying to make this integration as easy-to-use as possible. Some of those links are not necessary now.

Hope that it can help someone.

hey there @hy99

I’m a new user with HASS , and ive been tinkering with adding integrations ( and HACS) in the last few days, i found your integration , however , i have an issue.

IF using account Credentials, trying to choose the country in question ( Taiwan ) is not available, Using China returns no results when attempting to batch add

IF using tokens, it recognizes the item in question (example bslamp1) but it states “unknown error occurred” , when trying to use cloud.

see image for example.

Log as follows

This error originated from a custom integration.

Logger: aiohttp.server
Source: custom_components/xiaomi_miot_raw/config_flow.py:435
Integration: Xiaomi MIoT (documentation, issues)
First occurred: May 21, 2021, 11:59:19 PM (3 occurrences)
Last logged: May 21, 2021, 11:59:25 PM

Error handling request
Traceback (most recent call last):
File “/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py”, line 422, in _handle_request
resp = await self._request_handler(request)
File “/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py”, line 499, in _handle
resp = await handler(request)
File “/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py”, line 119, in impl
return await handler(request)
File “/usr/src/homeassistant/homeassistant/components/http/security_filter.py”, line 56, in security_filter_middleware
return await handler(request)
File “/usr/src/homeassistant/homeassistant/components/http/request_context.py”, line 18, in request_context_middleware
return await handler(request)
File “/usr/src/homeassistant/homeassistant/components/http/ban.py”, line 74, in ban_middleware
return await handler(request)
File “/usr/src/homeassistant/homeassistant/components/http/auth.py”, line 135, in auth_middleware
return await handler(request)
File “/usr/src/homeassistant/homeassistant/components/http/view.py”, line 131, in handle
result = await result
File “/usr/src/homeassistant/homeassistant/components/config/config_entries.py”, line 155, in post
return await super().post(request, flow_id)
File “/usr/src/homeassistant/homeassistant/components/http/data_validator.py”, line 63, in wrapper
result = await method(view, request, *args, **kwargs)
File “/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py”, line 109, in post
result = await self._flow_mgr.async_configure(flow_id, data)
File “/usr/src/homeassistant/homeassistant/data_entry_flow.py”, line 199, in async_configure
result = await self._async_handle_step(flow, cur_step[“step_id”], user_input)
File “/usr/src/homeassistant/homeassistant/data_entry_flow.py”, line 257, in _async_handle_step
result: FlowResult = await getattr(flow, method)(user_input)
File “/config/custom_components/xiaomi_miot_raw/config_flow.py”, line 435, in async_step_devinfo
‘model’: self._input2[CONF_MODEL],
KeyError: ‘model’

I am trying to use this integration but ran into issues.
vac_issues
It adds the device OK through the integration - finds it and all.
But it never creates any entities etc for it. Have this error after adding it through integration:

Logger: homeassistant.components.vacuum
Source: custom_components/xiaomi_miot_raw/__init__.py:1070
Integration: Vacuum (documentation, issues)
First occurred: 1:43:21 PM (2 occurrences)
Last logged: 1:54:03 PM

Error while setting up xiaomi_miot_raw platform for vacuum
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 250, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/xiaomi_miot_raw/vacuum.py", line 97, in async_setup_entry
    await async_setup_platform(hass, config, async_add_entities)
  File "/config/custom_components/xiaomi_miot_raw/vacuum.py", line 86, in async_setup_platform
    await async_generic_setup_platform(
  File "/config/custom_components/xiaomi_miot_raw/__init__.py", line 1070, in async_generic_setup_platform
    device_info.hardware_version,
  File "/usr/local/lib/python3.8/site-packages/miio/device.py", line 88, in hardware_version
    if self.data["hw_ver"] is not None:
KeyError: 'hw_ver'

So I added the iteration and the vacuum and see its atributes in the development tab

who can i manage the vacuum? lets say send it to vacuum all with double cleaning ?

Do you guys know how to make viomi vacuum work? I added the intergarion and see the data from it
but cannot call it to make it work…

here is what i see :grin:
msg_id: 1514786224358965200
is_new: 1
type: 6
title: Cleaning completed
content: Vacuum
user_id: xxx
timestamp: ‘2022-04-15T02:02:33’
model: viomi.vacuum.v18
event: ‘4.4’
home_name: xxx 's home
room_name: Tilley
entity_picture: ‘’
icon: mdi:message
friendly_name: Xiaomi xxx message
prev_message: ‘Vacuum: Cleaning completed’

here is what i try to send

service: xiaomi_miot.call_action
data:
entity_id: vacuum.dreame_p2259_entity_id
siid: 4 # vacuum-extend
aiid: 1 # start-clean
params:

  • 18 # piid: 1 - work-mode
  • ‘{“selects”:[[7,1,0,2,1]]}’ # piid: 10 - clean-extend-data
    throw: true # throw result to HA notifications

so far no luck

I have the same question. I have successfully added my S20+ to Home Assistant via this integration. Everything is showing up correctly, but how can I send the robot to a specific room with a specific cleaning program? e.g. “Vacuum the kitchen and mop with water level 3 afterwards”.

1 Like

For S20+

*** Start cleaning with the active room parameters in square brackets ***
action: xiaomi_miot.call_action
data:
entity_id: vacuum.xiaomi_b108gl_ca95_robot_cleaner
siid: 2
aiid: 13
params:
- “{"room":[9,12]}”

*** Set up rooms cleaning ***
action: xiaomi_miot.call_action
data:
entity_id: vacuum.xiaomi_b108gl_ca95_robot_cleaner
siid: 2
aiid: 10
params:
- “{"room_attrs":[{"id":8,"room_name":"Alex","fan_level":2,"water_level":1,"clean_mode":1,"clean_times":1,"mop_mode":0,"on":true}]}”

*** Start custom cleaning***
action: xiaomi_miot.call_action
data:
entity_id: vacuum.xiaomi_b108gl_ca95_robot_cleaner
siid: 6
aiid: 7
params: