Xiaomi mi wifi plug & air purifier

Hi, syssi. For IR code learn, there is another file called xiaomi_ir.py. Do you need it as well? And actually AC Controller is the same product as Xiaomi AC Partner. The difference are appearance and brand. Both products are made by Aqara but square one is branded Aqara and Round one is branded Xiaomi. Just like other Zigbee products such as temperature sensor and windows/door binary sensors. Furthermore, I notice that only Aqara one is official sold abroad, which means that overseas customers may only be familiar with this one.

@thundergreen We are working on AC Partner component. Right now, you can follow this repository and add it as custom_component. You can check markdown file, which is English Doc. Since PR at home-assistant official repository is quite a chaos now.

@cxlwill I alredy tried AC Partner but it won’t work for the Chuang Mi IR Remote Controller unfortunately.

so we will have to pick up the xiaomi_ir.py to build this AC component

@syssi here is the link to the braodlink:

Config would look something like:

climate:
  - platform: broadlink
    name: Toyotomi Akira
    host: 192.168.1.85
    mac: 'BB:BB:BB:BB:BB:BB'
    ircodes_ini: 'broadlink_climate_codes/toyotomi_akira.ini'
    min_temp: 16
    max_temp: 30
    target_temp: 20
    temp_sensor: sensor.living_room_temperature
    default_operation: idle
    default_fan_mode: mid
    customize:
      operations:
        - idle
        - cool
        - heat
      fan_modes:
        - low
        - mid
        - high
        - auto

Hi everyone, I have a Xiaomi Air Purifier Gen 1, and have tried to use the plugin. So far it doesn’t seem to detect it, although my Xiaomi Robot Vacuum detects fine and can be controlled. Would that be because the Xiaomi Air Purifier Gen 1 is not supported? So far, the discussions seem to be focused on the latter models of the Xiaomi Air Purifier.

If the Xiaomi Air Purifier Gen 1 isn’t supported in this plugin, is there anything that supports it?

Thank you everyone!

Please use this component: https://home-assistant.io/components/fan.xiaomi_miio/

Yes, that’s the component that I’m using, and the guide that I used as well. My configuration is below:

Xiaomi Air Purifier

fan:

  • platform: xiaomi_miio
    name: Xiaomi Air Purifier
    host: 10.168.48.243
    token: [my token removed]

I’ve added the Xiaomi Robot Vacuum successfully as well, so I’m fairly sure I used the right process to extract the tokens. However, the component isn’t turning up in my Home Assistant page.

My Air Purifier is a Gen 1 (not Xiaomi Air Purifier 2, Air Purifier 2S or Air Purifier Pro) so I’m wondering if that is the reason why the component isn’t turning in my Home Assistant page? If the Gen 1 is supported, then not sure what I’m doing incorrectly? Any advice appreciated! Thank you!

@syssi Any ideas with this one?

Thanks for all your work on the xiaomi purifier! Any future plans on supporting the humidifier through HA?

Not yet. Do you like to provide some testing?

hi raty,
just trying to achieve what you’ve done, however it doesnt seem to work. It doesnt change the fan speed, any idea what I am doing wrong?

I pretty much copied and pasted your settings and just changing the IP address to my purifier.

Thanks

image

Hi kwetiaw,
since 0.60 the AirPurifier component isn’t working anymore in Home-Assistant (at least for me it isn’t).
I’ve read on github, that syssi is working on the solution.

Also, since there is an official component, the miio command has been replaced by the mirobo command.
But luckily it isn’t necessary anymore to do it the way I described.

Now, with the official component you can just use input_number and an automation like this:

Automation:

- id: xiaomi_fav_speed
  alias: Xiaomi Favorite Speed
  trigger:
    platform: state
    entity_id: input_number.xiaomi_fav_speed
  action:
    - service: fan.xiaomi_miio_set_favorite_level
      data_template:
        entity_id: fan.xiaomi_air_purifier_2
        level: '{{ states.input_number.xiaomi_fav_speed.state | int }}'

input_number:

xiaomi_fav_speed:
  name: Xiaomi Air Purifier Favorite Level
  initial: 5
  min: 1
  max: 16
  step: 1

But, as I said earlier, at the moment, it doesn’t work at all.

I have the humidifier and would be more than happy to test for you

It’s fixed and will be part of the next homeassistant release: python-miio version bumped by syssi · Pull Request #11837 · home-assistant/core · GitHub

1 Like

I wrote a custom component as first step:

Please give it a try. If it works fine I will merge the code into fan/xiaomi_miio.

@af950833 Last request for today. :wink: I want to support your Air Purifier Pro properly. You already know the procedere. Could you post the output of:

# I want to know the model name
bin/mirobo --ip 192.168.1.xx --token 3d5fffffffffffffffffffffff37453b info
# First bunch of properties
bin/mirobo --ip 192.168.1.xx --token 3d5fffffffffffffffffffffff37453b get_prop '["power", "aqi", "average_aqi", "humidity", "temp_dec", "mode", "favorite_level", "filter1_life", "f1_hour_used", "use_time", "motor1_speed", "purify_volume", "f1_hour"]'
# Second bunch of properties
bin/mirobo --ip 192.168.1.xx --token 3d5fffffffffffffffffffffff37453b get_prop '["led", "led_b", "bright", "buzzer", "child_lock", "volume" ]'

Thanks! :slight_smile:

(homeassistant) homeassistant@Tommy:/home/pi $ mirobo --ip 192.168.0.15 --token 2a4d39a5721f983fdceae9193fc35596 -d info
INFO:miio.vacuum_cli:Debug mode active
DEBUG:miio.vacuum_cli:Read stored sequence ids: {‘manual_seq’: 0, ‘seq’: 12}
DEBUG:miio.vacuum_cli:Connecting to 192.168.0.15 with token 2a4d39a5721f983fdceae9193fc35596
DEBUG:miio.protocol:Unable to decrypt, returning raw bytes: b’’
DEBUG:miio.device:Got a response: Container:
data = Container:
data = (total 0)
offset2 = 32
offset1 = 32
length = 0
value = (total 0)
header = Container:
data = !1\x00 \x00\x00\x00\x00\x036}B\x00\x0b\xdbO (total 16)
offset2 = 16
offset1 = 0
length = 16
value = Container:
length = 32
unknown = 0
device_id = 03367d42 (total 8)
ts = 1970-01-09 23:50:39
checksum = *M9\xa5r\x1f\x98?\xdc\xea\xe9\x19?\xc3U\x96 (total 16)
DEBUG:miio.device:Discovered b’03367d42’ with ts: 1970-01-09 23:50:39, token: b’2a4d39a5721f983fdceae9193fc35596’
DEBUG:miio.device:192.168.0.15:54321 >>: {‘method’: ‘miIO.info’, ‘params’: [], ‘id’: 13}
DEBUG:miio.device:192.168.0.15:54321 (ts: 1970-01-09 23:50:39, id: 13) << {‘result’: {‘token’: ‘2a4d39a5721f983fdceae9193fc35596’, ‘mac’: ‘28:6C:07:B1:FE:B8’, ‘otu_stat’: [74, 74, 21452, 25, 21384, 404], ‘ot’: ‘otu’, ‘hw_ver’: ‘MW300’, ‘life’: 777039, ‘ap’: {‘ssid’: ‘Tommy’, ‘rssi’: -35, ‘bssid’: ‘AC:9E:17:A1:DF:F8’}, ‘model’: ‘zhimi.airpurifier.v6’, ‘wifi_fw_ver’: ‘SD878x-14.76.36.p84-702.1.0-WM’, ‘netif’: {‘localIp’: ‘192.168.0.15’, ‘mask’: ‘255.255.255.0’, ‘gw’: ‘192.168.0.1’}, ‘mmfree’: 185644, ‘ott_stat’: [0, 0, 0, 0], ‘cfg_time’: 0, ‘fw_ver’: ‘1.2.9_9049’}, ‘id’: 13}
zhimi.airpurifier.v6 v1.2.9_9049 (28:6C:07:B1:FE:B8) @ 192.168.0.15 - token: 2a4d39a5721f983fdceae9193fc35596
DEBUG:miio.vacuum_cli:Full response: {‘ap’: {‘bssid’: ‘AC:9E:17:A1:DF:F8’, ‘rssi’: -35, ‘ssid’: ‘Tommy’},
‘cfg_time’: 0,
‘fw_ver’: ‘1.2.9_9049’,
‘hw_ver’: ‘MW300’,
‘life’: 777039,
‘mac’: ‘28:6C:07:B1:FE:B8’,
‘mmfree’: 185644,
‘model’: ‘zhimi.airpurifier.v6’,
‘netif’: {‘gw’: ‘192.168.0.1’,
‘localIp’: ‘192.168.0.15’,
‘mask’: ‘255.255.255.0’},
‘ot’: ‘otu’,
‘ott_stat’: [0, 0, 0, 0],
‘otu_stat’: [74, 74, 21452, 25, 21384, 404],
‘token’: ‘2a4d39a5721f983fdceae9193fc35596’,
‘wifi_fw_ver’: ‘SD878x-14.76.36.p84-702.1.0-WM’}
DEBUG:miio.vacuum_cli:Writing {‘manual_seq’: 0, ‘seq’: 13} to /tmp/python-mirobo.seq
(homeassistant) homeassistant@Tommy:/home/pi $
(homeassistant) homeassistant@Tommy:/home/pi $ mirobo --ip 192.168.0.15 --token 2a4d39a5721f983fdceae9193fc35596 raw_command get_prop ‘[“power”, “aqi”, “average_aqi”, “humidity”, “temp_dec”, “mode”, “favorite_level”, “filter1_life”, “f1_hour_used”, “use_time”, “motor1_speed”, “purify_volume”, “f1_hour”]’
Sending cmd get_prop with params [‘power’, ‘aqi’, ‘average_aqi’, ‘humidity’, ‘temp_dec’, ‘mode’, ‘favorite_level’, ‘filter1_life’, ‘f1_hour_used’, ‘use_time’, ‘motor1_speed’, ‘purify_volume’, ‘f1_hour’]
[‘off’, 7, 18, 45, 234, ‘auto’, 17, 52, 1664, 2642700, 0, 62180, 3500]
(homeassistant) homeassistant@Tommy:/home/pi $
(homeassistant) homeassistant@Tommy:/home/pi $ mirobo --ip 192.168.0.15 --token 2a4d39a5721f983fdceae9193fc35596 raw_command get_prop ‘[“led”, “led_b”, “bright”, “buzzer”, “child_lock”, “volume” ]’
Sending cmd get_prop with params [‘led’, ‘led_b’, ‘bright’, ‘buzzer’, ‘child_lock’, ‘volume’]
[‘on’, None, 83, None, ‘off’, 50]
(homeassistant) homeassistant@Tommy:/home/pi $

It is my pleasure to help you :slight_smile:
As I mentioned, there is no “led_b” in the Air purifier(and Buzzer is not in it)

Perfect! I will prepare the next interation.

@af950833 Last wish for this device: Could you check/verify the supported operation modes of the Air Purifier Pro? (Command: set_mode, Possible values: auto, silent, favorite, idle)

Idle isn’t supported and returns an error, right?

@syssi Yes, you are right.

(homeassistant) homeassistant@Tommy:/home/pi $ mirobo --ip 192.168.0.15 --token 2a4d39a5721f983fdceae9193fc35596 raw_command set_mode ‘[“silent”]’
Sending cmd set_mode with params [‘silent’]
[‘ok’]
(homeassistant) homeassistant@Tommy:/home/pi $ mirobo --ip 192.168.0.15 --token 2a4d39a5721f983fdceae9193fc35596 raw_command set_mode ‘[“auto”]’
Sending cmd set_mode with params [‘auto’]
[‘ok’]
(homeassistant) homeassistant@Tommy:/home/pi $ mirobo --ip 192.168.0.15 --token 2a4d39a5721f983fdceae9193fc35596 raw_command set_mode ‘[“idle”]’
Sending cmd set_mode with params [‘idle’]
{‘id’: 6, ‘error’: {‘code’: -5001, ‘message’: ‘invaild_arg’}}
(homeassistant) homeassistant@Tommy:/home/pi $ mirobo --ip 192.168.0.15 --token 2a4d39a5721f983fdceae9193fc35596 raw_command set_mode ‘[“favorite”]’
Sending cmd set_mode with params [‘favorite’]
[‘ok’]

1 Like

@af950833 I prepared the next iteration of the air purifier component: https://github.com/syssi/xiaomi_airpurifier

Please copy the custom component into .homeassistant/custom_components/fan/xiaomi_miio.py

The custom component overrides the official fan.xiaomi_miio component and provides support for the Xiaomi Air Purifier and Xiaomi Air Humidifier:

fan:
  - platform: xiaomi_miio
    name: Xiaomi Air Purifier
    host: 192.168.130.71
    token: b7c4a758c251955d2c24b1d9e41ce47d

  - platform: xiaomi_miio
    name: Xiaomi Air Humidifier
    host: 192.168.130.72
    token: 2b00042f7481c7b056c4b410d28f33cf

I would be happy about a screenshot of both detail views if the component works out of the box. Because you own the Xiaomi Air Purifier Pro there should be some mor attributes available as in my screenshot:

Thanks in advance!

hi syssi,

The HA frontend is just loading and showed nothing.
1

pi@Tommy:~ $ cat /home/homeassistant/.homeassistant/home-assistant.log
2018-02-22 17:36:33 WARNING (Recorder) [homeassistant.components.recorder] Ended unfinished session (id=76 from 2018-02-22 08:29:04.944067)
2018-02-22 17:36:40 WARNING (Thread-14) [homeassistant.components.emulated_hue] When targeting Google Home, listening port has to be port 80
2018-02-22 17:36:57 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform yr is taking over 10 seconds.
2018-02-22 17:36:57 ERROR (Thread-14) [miio.device] Got error when receiving: timed out
2018-02-22 17:36:57 WARNING (Thread-14) [miio.device] Retrying with incremented id, retries left: 3
2018-02-22 17:36:59 ERROR (Thread-21) [miio.device] Got error when receiving: timed out
2018-02-22 17:36:59 WARNING (Thread-21) [miio.device] Retrying with incremented id, retries left: 3
2018-02-22 17:37:06 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting
2018-02-22 17:37:11 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting
2018-02-22 17:37:30 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/remote.py”, line 126, in default
return json.JSONEncoder.default(self, o)
File “/usr/lib/python3.5/json/encoder.py”, line 179, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <FilterType.Regular: ‘regular’> is not JSON serializable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/remote.py”, line 132, in default
for child_obj in o]
TypeError: ‘FilterType’ object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/aiohttp/web_protocol.py”, line 416, in start
resp = yield from self._request_handler(request)
File “/srv/homeassistant/lib/python3.5/site-packages/aiohttp/web.py”, line 325, in _handle
resp = yield from handler(request)
File “/srv/homeassistant/lib/python3.5/site-packages/aiohttp/web_middlewares.py”, line 93, in impl
return (yield from handler(request))
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/http/ban.py”, line 58, in ban_middleware
return (yield from handler(request))
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/http/auth.py”, line 49, in auth_middleware
return (yield from handler(request))
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/http/static.py”, line 70, in staticresource_middleware
return (yield from handler(request))
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/http/init.py”, line 430, in handle
result = yield from result
File “/usr/lib/python3.5/asyncio/coroutines.py”, line 213, in coro
res = yield from res
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/websocket_api.py”, line 397, in handle
yield from self._writer_task
File “/usr/lib/python3.5/asyncio/futures.py”, line 382, in iter
return self.result() # May raise too.
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/asyncio/tasks.py”, line 239, in _step
result = coro.send(None)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/websocket_api.py”, line 246, in _writer
yield from self.wsock.send_json(message, dumps=JSON_DUMP)
File “/srv/homeassistant/lib/python3.5/site-packages/aiohttp/web_ws.py”, line 197, in send_json
return self.send_str(dumps(data))
File “/usr/lib/python3.5/json/init.py”, line 237, in dumps
**kw).encode(obj)
File “/usr/lib/python3.5/json/encoder.py”, line 198, in encode
chunks = self.iterencode(o, _one_shot=True)
File “/usr/lib/python3.5/json/encoder.py”, line 256, in iterencode
return _iterencode(o, 0)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/remote.py”, line 135, in default
return json.JSONEncoder.default(self, o)
File “/usr/lib/python3.5/json/encoder.py”, line 179, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <FilterType.Regular: ‘regular’> is not JSON serializable
2018-02-22 17:37:44 ERROR (Recorder) [homeassistant.components.recorder.util] Error executing query: <FilterType.Regular: ‘regular’> is not JSON serializable