Xiaomi Air Purifier - Show all sensors and Switches in UI and HomeKit

I have tried the above models. First: get the components to work? How do i know if it works, other to check it in lovelace.?

Our 2H model is not officially supported by the Xiaomi integration.
I think that you should not specify the model in configuration.yaml…
Use # at the beginning of the line ‘model:’ …
I’ve not specified the model and the purifier works flawlessly…

Funny enough, mine is exactly the opposite… I can’t get it to work without a model type… :slight_smile: And mine is a 2H… That’s what I say, with chinese devices you never know what you get. And that is not disrespectful, I use a lot of Xiaomi devices, but even my cell is different from the description. I do have 128GB, but I only bought the 64GB version. Even my device specs on the carton say 64GB… :smiley:

But unfortunately KePeSWEs doesn’t work with our without model number. But…

OK, we start at the beginning: :slight_smile:
Developer tools you know? Doesn’t matter, here you go:

You select the tab for states. There you find “filter entities” (on the first line with a grey background). Type in fan. What do you see right under that filter line? Normally it should be something like fan.closet_mi_air_purifier_2h.

1 Like

Hi. I did the “filter entities” and typed fan and found fan.closet_mi_air_purifier_2h and the state is On, thats correct. Below that i’ve got a whole lot of info:

Here i could try out some other states right? For example.?

Did you fall asleep? @paddy0174

My log reports the “capitalize” issue:

Logger: homeassistant.components.input_select
Source: components/input_select/__init__.py:259 
Integration: Input selezione ([documentation](https://www.home-assistant.io/integrations/input_select), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+input_select%22)) 
First occurred: 4 giugno 2020, 23:56:04 (27 occurrences) 
Last logged: 0:16:41

Invalid option: None (possible options: Auto, Silent, Favorite)

I’ve read some messages about this in the upper section of this thread but I didn’t get how to resolve.
Any help?

Thank you in advance

I’m going to take care of the capitalization issue.

In the meanwhile, go back to my post on Feb 26 Xiaomi Air Purifier - Show all sensors and Switches in UI and HomeKit and try that solution. If you edit the fan.py to have the states in lowercase, it should work.

1 Like

I’m running hassio where do i fins that folder?

1 Like

I’m running hassio too but I’ve installed the official Xiaomi integrations.
This piece of software doesn’t install itself inside the ‘config’ dir.
So I don’t have access to the fan.py file…

I don’t know, but if you search Google for “edit file inside docker container” you can find multiple ways to edit the fan.py inside the homeassistant installation directory.
You can also copy the whole directory xiaomi_miio inside the “custom components” in the config directory and edit that one. This way you have a custom component which is identical to the standard one except for the strings you will edit.

Can you please help me I have now downloaded xioaomi_miio and placed the folder in custom components
\config\custom_components\xiaomi_miio and edited fan.py my copy I have edited
https://pastebin.com/Tm5GCGEj

but I get the same error still https://pastebin.com/bV0vuZM8

and it seems it has loaded

2020-06-06 14:08:34 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for xiaomi_miio which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.

https://github.com/home-assistant/core/issues/32419 is the relevant bug you are hitting, I also just wrote there how it should be properly solved (at least how I think it should be solved).

1 Like

I have put together stuff from multiple users in this thread, although it wouldn’t accept your modifications @sobczynski so logs are a bit overflown.

My question is, how would I go about it, of automating the fan based on the pm25 value?
Let’s say intervals, like if pm25 value is 0 - >10, set favorite level to 2, pm25 value is >10 - 20, set favorite level to 3, and so on?

Thanks in advance!

These are my configurations:

configuration.yaml

fan:
  - platform: xiaomi_miio
    name: "Xiaomi Miio Device"
    host: 192.168.179.192
    token: **removed**
    model: zhimi.airpurifier.mb3
switch:
  - platform: template
    switches:
      xiaomi_airpurifier_led:
        friendly_name: "LED"
        value_template: "{{ is_state_attr('fan.xiaomi_miio_device', 'led', true) }}"
        turn_on:
          service: xiaomi_miio.fan_set_led_on
          data:
            entity_id: fan.xiaomi_miio_device
        turn_off:
          service: xiaomi_miio.fan_set_led_off
          data:
            entity_id: fan.xiaomi_miio_device
        icon_template: "mdi:lightbulb-outline"
      xiaomi_airpurifier_child_lock:
        friendly_name: "Child lock"
        value_template: "{{ is_state_attr('fan.xiaomi_miio_device', 'child_lock', true) }}"
        turn_on:
          service: xiaomi_miio.fan_set_child_lock_on
          data:
            entity_id: fan.xiaomi_miio_device
        turn_off:
          service: xiaomi_miio.fan_set_child_lock_off
          data:
            entity_id: fan.xiaomi_miio_device
        icon_template: "mdi:lock-outline"
      xiaomi_airpurifier_buzzer:
        friendly_name: "Buzzer"
        value_template: "{{ is_state_attr('fan.xiaomi_miio_device', 'buzzer', true) }}"
        turn_on:
          service: xiaomi_miio.fan_set_buzzer_on
          data:
            entity_id: fan.xiaomi_miio_device
        turn_off:
          service: xiaomi_miio.fan_set_buzzer_off
          data:
            entity_id: fan.xiaomi_miio_device
        icon_template: "mdi:volume-high"
  
input_select:
  xiaomi_airpurifier_mode:
    name: Mode
    options:
      - Auto
      - Silent
      - Favorite
    icon: "mdi:animation-outline"

input_number:
  xiaomi_airpurifier_favorite_level:
    name: "Favorite level"
    initial: 0
    min: 0
    max: 14
    step: 1
    icon: "mdi:weather-windy"
    
sensor:
  - platform: template
    sensors:
      xiaomi_airpurifier_temp:
        friendly_name: "Temperature"
        value_template: "{{ state_attr('fan.xiaomi_miio_device', 'temperature') }}"
        unit_of_measurement: "°C"
        device_class: "temperature"
      xiaomi_airpurifier_humidity:
        friendly_name: "Humidity"
        value_template: "{{ state_attr('fan.xiaomi_miio_device', 'humidity') }}"
        unit_of_measurement: "%"
        device_class: "humidity"
      xiaomi_airpurifier_air_quality_pm25:
        friendly_name: "Air quality"
        value_template: "{{ state_attr('fan.xiaomi_miio_device', 'aqi') }}"
        unit_of_measurement: "μg/m³"
        icon_template: "mdi:weather-fog"
      xiaomi_airpurifier_speed:
        friendly_name: "Fan speed"
        value_template: "{{ state_attr('fan.xiaomi_miio_device', 'motor_speed') }}"
        unit_of_measurement: "rpm"
        icon_template: "mdi:speedometer"
      xiaomi_airpurifier_filter_remaining:
        friendly_name: "Filter remaining"
        value_template: "{{ state_attr('fan.xiaomi_miio_device', 'filter_life_remaining') }}"
        unit_of_measurement: "%"
        icon_template: "mdi:heart-outline"
automations.yaml

  - alias: Air Purifier mode change
    trigger:
      entity_id: input_select.xiaomi_airpurifier_mode
      platform: state
    action:
      service: fan.set_speed
      data_template:
        entity_id: fan.xiaomi_miio_device
        speed: '{{ states.input_select.xiaomi_airpurifier_mode.state }}'
  - alias: Air Purifier mode changed
    trigger:
      platform: state
      entity_id: fan.xiaomi_miio_device
    action:
      service: input_select.select_option
      entity_id: input_select.xiaomi_airpurifier_mode
      data_template:
        option: '{{ states.fan.xiaomi_miio_device.attributes.mode }}'
  - alias: Air Purifier favorite level change
    trigger:
      entity_id: input_number.xiaomi_airpurifier_favorite_level
      platform: state
    action:
      service: xiaomi_miio.fan_set_favorite_level
      data_template:
        entity_id: fan.xiaomi_miio_device
        level: '{{ states.input_number.xiaomi_airpurifier_favorite_level.state | int }}'
  - alias: Air Purifier favorite level changed
    trigger:
      platform: state
      entity_id: fan.xiaomi_miio_device
    action:
      service: input_number.set_value
      entity_id: input_number.xiaomi_airpurifier_favorite_level
      data_template:
        value: '{{ states.fan.xiaomi_miio_device.attributes.favorite_level }}'
  - alias: Air Purifier mode changed
    trigger:
      platform: state
      entity_id: fan.xiaomi_miio_device
    action:
      service: input_select.select_option
      entity_id: input_select.xiaomi_airpurifier_mode
      data_template:
        option: '{{ states.fan.xiaomi_miio_device.attributes.mode }}' #- speed for mode

Hi, in the instructions is stated

“Select your Gateway in Xiaomi Home app.”

but I do not have a gateway, I use the Xiaomi app only for the purifier… anyone knows how to retrieve the token?

This discussion is about automations and showing sensors. Connecting the device to home assistant should be asked in a different thread. You can start one if needed.

You don’t need Xiaomi Integration as addon there GW required
just put in your configuration.yaml


fan:
  - platform: xiaomi_miio
    host: ip of your air purifier
    token: 'your air purifier token'

Hello, I own 2 x Xiaomi Air Purifier 2H. I would REALLY like them integrated in HA, but I’m having a hard time understanding how I can add them… To me it look and sounds like they should be added throuhg the Xiamo miio integration, but that does not make a lot of sense to me, as they do not connect to a gateway, they connect directly to the Xiaomi Home app via wifi. And when I click the xiaomi miio integration in HA it is clearly wanting to add a gateway, not an air purifier (or other device).

I know how to retrieve the token etc, I have done that before when I integrated these devices to smartthings but that was a very very very unfinished terrible solution that only worked half and partly not at all. hence why I am here :slight_smile:

Hello everyone, I just copied the configuration from the first post, but I cannot see any sensor on my Air Purifier 2H in the entity card, but if I click the Air Purifier entity, it shows every single sensor. Also, the buttons for modifying the mode and the speed, and the LED, aren’t working… Can you tell me how to fix it?

Have you adapted the names of the entities in the automations?

1 Like

Updated the names? Could you please explain me what to do? Thanks!