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

Hi, I’m new here, so I apologize for maybe the usual things and for my English.
I integrate my Xiaomi air purifier, I have two, older 2S and newer 3H.

Home Assistant version 2021.3.4 (runs as a virtual machine on Synology NAS DS716 + II)

First I integrated 3H (name Air Purifier Office, entity fan.air_purifier_office).
I think it’s pretty cool, except for a little bugs, but I’ll leave them out now.

Now I need to add the second one, model “2S” (Air Purifier Bedroom, entity fan.air_purifier_office_2). But I don’t know exactly how to rename everything correctly.

In the basic definition of fan: (configuration.yaml) I already have both purifiers (see picture), the second purifier is now also visible, I can turn it on and off. But I need to add more sections to the sensor, switch and input sections (configuration.yaml).
And of course to the automations.yaml file

Thank you very much, I am a complete beginner in H.A.

Below are fragments from my YAML files.

Fan config in configuration.yaml
HA - Config yaml - Xiaomi Fans

Fan Sensors config in configuration.yaml
HA - Config yaml - Xiaomi Fans Sensors

Fan Switch config in configuration.yaml
HA - Config yaml - Xiaomi Fans Switch fragment

Fan Sensors config in automations.yaml
HA - Automation yaml

I have already managed 2 air purifiers for Home Assistant, see above.

Power switching works, sensors and switches are functional too.

But the Input section doesn’t work for me, I have it set up like this. Input works only for 3H (Office), but does not work for 2S (Bedroom).

Can’t someone advise?

input_select:
# Xiaomi Air Purifier 3H
  xiaomi_airpurifier_mode:
    name: Air Pur. Office Mode
    options:
      - Auto
      - Silent
      - Favorite
    icon: "mdi:animation-outline"
    
# Xiaomi Air Purifier 2S
  xiaomi_airpurifier2_mode:
    name: Air Pur. Bedroom Mode
    options:
      - Auto
      - Silent
      - Favorite
    icon: "mdi:animation-outline"    

My Air Purifier 2H was working fine until the 2021.4 update… now it does not. What am I supposed to do?

Screenshot_5

Thanks @MickL for sharing this guide. It saved me hours and works like a charm with a “2H” purifier after adapting the entity ID to my situation.

I got my 2H today and got it working with this configuration:

fan:
  # Xiaomi Air Purifier 2H
  - platform: xiaomi_miio
    host: 192.168.NNN.NNN
    token: !secret mitoken
    name: "Xiaomi Air Purifier 2H"
    model: 'zhimi.airpurifier.mc1'

Not sure if that helps…

Thank you. Helped me.

Same here with the air purifier 3H. After updating to 2021.4.6, can’t control it from Home Assistant.
image

Hi,

I recently updated my newly installed Ha to version Home Assistant 2021.5.4. Same for me. I am not able to setup configuration using this article:

Firstly I would like to thanks to all the contributor in this threads, got me going for years until recently…
The latest update a few things changed. 3 main things look out for
1 . It no longer accepts the fan: - platform: xiaomi_miio in configuration.yaml. Remove that. Its now in the Intergration UI.
2. Look in the Developer Tools make sure the name of the device still that same, It might now be fan.airpurifierxx_2 remove the old one and rename it back to fan.airpurifierxx.
3. Some of the service name also change eg fan.set_speed is replace by fan.set_preset_mode, it still might work but throw a lot of errors in the logs, so if things dont work as expected look through the service call see if need change there.

I am using this custom_components which setup similar to previous, and dont throw errors in the logs. Even if you dont use the components scroll through the example scripts which is much the same as this thread which might get you back on tracks.

3 Likes

you can also add filter life remaining in days - you have to devide hours used by 24 to get days. What I’ve noticed new filters have 145 days total, so that should give the same information as Xiaomi Home App:

xiaomi_airpurifier_filter_remaining_days:
        friendly_name: "Filter remaining"
        value_template: "{{ (145 - state_attr('fan.xiaomi_miio_device', 'filter_hours_used') | float / 24) round(0) }}"
        unit_of_measurement: "days"
        icon_template: "mdi:heart-outline"

Hi there,
pay attention to the many breaking changes for Xiaomi Miio fan platform with the upcoming 2021.9 release!!!
check this out:
https://rc.home-assistant.io/blog/2021/08/25/release-20219/#breaking-changes

3 Likes

That is quite a mouthful!

One one hand, it is nice I can remove a lot of the template and binary sensors from my configuration.yaml as they are now separate entities.
But I am a bit worried how I need to update my automations that rely on Favorite Level.

Yes! I’m happy to see the team is finally adding all the sensors and switches that were missing. My configuration file will be slimmed down significantly. :partying_face:

Will have to do some updating my lovelace and automations.

Quick question, is anyone else hit by the warning that fan.set_speed is deprecated in their logs, while not using it?
It only happens once shortly after server startup.

[homeassistant.components.fan] The fan.set_speed service is deprecated, use fan.set_percentage or fan.set_preset_mode instead

When it was first announced a while ago, I made sure to modify all configuration to align with this. And I have gone through all my files (multiple times) with Search to see if it’s there somewhere.

That’s coming from the Xiaomi integration. Should be resolved with the next release of HA (2021.9.x). At least the changelog for this intergation shows a lot of changes… :wink: See link above to check it out. :slight_smile:

Is anyone else having problems setting the speed in automations?

Can you set the fan to ‘Auto’ with the latest updates? I have been testing it today, a switch for auto doesn’t seem to be exposed.

Also, it seems the new entities use the ‘Area’ name when creating the new entities instead of the device name. Is this on purpose? So instead of switch.master_bedroom_air_purifier_child_lock I have switch.master_bedroom_child_lock. IMO using the device name would be better.

No idea how to contact the devs for this feedback so I am posting here.

You are able to set it in auto mode like this:

  - service: fan.set_preset_mode
    data:
      preset_mode: Auto

The other thing I don’t know.

1 Like

Hi everyone, the latest breaking update have simplify things quite alot. They have done a fantastic job. We no longer need template sensors and switches. They are now all separates entities. And we no longer need to have all the complex automation as well because of the new template entities: Number and Select.

All you need is to add the following to your configuration.yaml for the select input modes:

template:
  - select:
      - name: "Air Purifier Mode"
        state: "{{ state_attr('fan.zhimi_airpurifier_mc1', 'preset_mode') }}"
        options: "{{ state_attr('fan.zhimi_airpurifier_mc1', 'preset_modes') }}"
        select_option:
          service: fan.set_preset_mode
          target:
            entity_id: fan.zhimi_airpurifier_mc1
          data:
            preset_mode: "{{ option }}"
  - select:            
      - name: "Humidifier Mode"
        state: "{{ state_attr('humidifier.zhimi_humidifier_v1', 'mode') }}"
        options: "{{ state_attr('humidifier.zhimi_humidifier_v1', 'available_modes') }}"
        select_option:
          service: humidifier.set_mode
          target:
            entity_id: humidifier.zhimi_humidifier_v1
          data:
            mode: "{{ option }}"

The lovelace humidifier card have slider for the target humidity, and the favorite levels is now a “number” entity called [ number.xxx_favorite_level ]

1 Like

Thank you for your trick.
I’ve tried your “Air Purifier Mode” template but, unfortunately, in my case it doesn’t seem to work.
This is what I can find in my logs:

Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:94 
Integration: Template (documentation, issues) 
First occurred: 23:06:41 (1 occurrences) 
Last logged: 23:06:41

Error validating template result 'None' from template 'Template("{{ state_attr('fan.zhimi_airpurifier_v2', 'preset_mode') }}")' for attribute '_attr_current_option' in entity select.air_purifier_mode validation message 'string value is None'