Lovelace: Xiaomi - Mi air purifier 3H card

Ok, understand now.
This is not how it design to work at the moment. It just modified favorite level, you can check when expanding the purifer properties, but does not change the mode. You can see in the picture favorite level changing from 0 to 6 but not the mode. Probably it is a good idea to change also the mode. Let me think about it.

So now you first have to select the mode on Favorite then to change the level or coverage as you wish.

To be more precise it should work like in Mi Home app: when selecting Favorite/Manual Coverage to be visible, otherwise hidden, also for Fan to have the 3 levels available only when this mode is selected, otherwise hidden.

Unfortunately at this moment don’t know how to hide fields in HA based on other fields status.

But it is a good idea also to change the mode when changing fan, favorite or coverage. So let me think about it.

Hi all,

I have thought on what @emmpii said so I came with a new simplified release of this card.

  1. Fan level, favorite level/coverage will be available only if fun, respectively favorite are selected (conditional cards).
  2. Most of the attributes are unessential for day to day utilization so I have added a button to toggle them on/off the card.

So card is looking like this for different speeds:

Also if you toggle new attributes ON/OFF:
attributes off

UPDATE in configuration.yaml under fun.mi_air_purifier_3h:

input_boolean:
    mi_air_purifier_attributes:
      name: Attributes
      icon: mdi:pencil

NEW card configuration in lovelace.yaml:

cards:
  - cards:
      - entity: sensor.mi_air_purifier_air_quality_pm25
        max: 200
        min: 0
        name: AQI PM2.5
        severity:
          green: 0
          red: 150
          yellow: 75
        type: gauge
    type: horizontal-stack
  - entities:
      - entity: fan.mi_air_purifier_3h
      - entity: input_select.mi_air_purifier_mode
    show_header_toggle: false
    type: entities
  - card:
      entities:
        - entity: input_number.mi_air_purifier_favorite_level
        - entity: input_select.mi_air_purifier_coverage
      type: entities
    conditions:
      - entity: input_select.mi_air_purifier_mode
        state: Favorite
    type: conditional
  - card:
      entities:
        - entity: input_number.mi_air_purifier_fan_level
      type: entities
    conditions:
      - entity: input_select.mi_air_purifier_mode
        state: Fan
    type: conditional
  - entities:
      - entity: input_boolean.mi_air_purifier_attributes
    type: entities
    show_header_toggle: false
  - card:
      entities:
        - entity: sensor.mi_air_purifier_temp
        - entity: sensor.mi_air_purifier_humidity
        - entity: sensor.mi_air_purifier_air_quality_pm25
        - entity: sensor.mi_air_purifier_avg_air_quality_pm25
        - type: divider
        - entity: sensor.mi_air_purifier_use_time
        - entity: sensor.mi_air_purifier_filter_used
        - entity: sensor.mi_air_purifier_filter_remaining
        - entity: sensor.mi_air_purifier_purify_volume
        - type: divider
        - entity: sensor.mi_air_purifier_speed
        - entity: sensor.mi_air_purifier_led_brightness
        - type: divider
        - entity: switch.mi_air_purifier_led
        - entity: switch.mi_air_purifier_child_lock
        - entity: switch.mi_air_purifier_buzzer
      show_header_toggle: false
      type: entities
    conditions:
      - entity: input_boolean.mi_air_purifier_attributes
        state: 'on'
    type: conditional
type: vertical-stack
2 Likes

Looks much cleaner!

Will be testing out the automations again to see if they’re working as they’re supposed to

Further to your automations, I’ve disabled the following automations:

Air Purifier turn on/off
Air Purifier set favourite level based on PM2.5

I think that will decrease load on my Pi having to constantly check and also the 3H on auto automatically adjusts level anyway

Hi @emmpii the first automation is in case you don’t use continuously the purifier. Related to the second one, I have read an article recommending to use the purifier on manual, setting the coverage, not on auto: https://smartairfilters.com/en/blog/data-explains-never-use-purifiers-auto-mode/

Okay I’m not totally sure how that would work because it’s still pulling data from the Purifier Sensor?

I’ve just enabled the automation and the fan has set itself to level 2 while the PM2.5 level was just 001?

I’ve adjusted the auto mode automation to run every 5 minutes rather than every hour

- id: '1585984405489'
  alias: Air Purifier set favorite level based on PM2.5
  description: ''
  trigger:
  - minutes: "/5" # run when minute of the hour is dividable by 5
    platform: time_pattern
  condition:
  - condition: state
    entity_id: fan.mi_air_purifier_3h
    state: 'on'
  action:
  - data_template:
      speed: Favorite
    entity_id: fan.mi_air_purifier_3h
    service: fan.set_speed
  - data_template:
      level: '{% if states("sensor.mi_air_purifier_air_quality_pm25") | int > 50 -%}
        14 {%- elif states("sensor.mi_air_purifier_air_quality_pm25") | int > 40 -%}
        12  {%- elif states("sensor.mi_air_purifier_air_quality_pm25") | int > 30
        -%} 9 {%- elif states("sensor.mi_air_purifier_air_quality_pm25") | int > 20
        -%} 6 {%- else -%} 4 {%- endif %}

        '
    entity_id: fan.mi_air_purifier_3h
    service: xiaomi_miio.fan_set_favorite_level

I’m not sure if the data template for the set level is working correctly as at night it was increasing the favourite level quite a bit and then 5 minutes later dropping it…
As for the pm 2.5 history it looks below 5 all night which seems odd

I am just looking at this after getting a Air Purifier 3 and there is one function that doesn’t work properly here.
The Air Purifier 3/3H models have an OLED Display. That means they do not use the xiaomi_miio.fan_set_led_off or xiaomi_miio.fan_set_led_on commands as the LED display has Off, Dim and Bright as three options.
It might need that toggle to be replaced with a slider that can do 0, 1, 2 for command xiaomi_miio.fan_set_led_brightness

Hi Brendan. Just check and you are right, but instead of xiaomi_miio.fan_set_led_off or xiaomi_miio.fan_set_led_on that are not working, you can use xiaomi_miio.remote_set_led_off or xiaomi_miio.remote_set_led_on. It will just switch off, switch on the screen and I’ve changed this into configuration files above.

What you propose is a little bit more complicated and requires (like for defining slider for fan level) an input number entity, plus 2 automation, one to update the purifier brightness value to input number value and the second one to update the slider value on purifier brightness. It is not rocket science, just copy and modify the existing automation, but don’t know if worth the effort as I, for example, set the brightness to 1 and leave it like that.

Thank you. On and Off would be fine :slight_smile:.

I noticed also the Air Purifier does not sync to home assistant if the settings are changed in the Xiaomi App or on the front of the purifier. Is this correct or did I do something wrong?

It should as there are some automations just for this. But sometimes it take some time for HA to get the feedback from the purifier. You could always check the values received by HA by just checking the purifier.

1 Like

You are right. There is a delay when Home Assistant receives the updates.

Also changed above the attribute name from Led to Display in order not to be confused. It is now Display on/off

I had a play with the automations in this thread. It pretty well behaves identically to having the Air Purifier 3H in Auto mode, so they are kind of superfluous. I do appreciate the lovelace card setup however and find that quite useful. The only thing I found is I had to get rid of the “Fan” mode and use just Favorite, Auto and Silent as when the Air Purifier is set to Auto mode (not using HA automations for quailty control) the Auto speed would ramp up and the Fan mode would cut in and set the Purifier to a fixed level. Once I deleted the relevant Fan mode automations, this ceased to happen. Might be a thing with the latest firmware, not sure, but that was my experience.
I read the article on Air Purifiers in Auto mode. That article is not really current but basically it says don’t trust the auto sensors in the Air Purifiers. That means not trusting the readings of the sensors on the device.
The Xiaomi Air Purifier 3 actually has a reasonable sensor (in my one at least) and it’s auto mode is quite adequate for general use. One caveat here. Having the Air Purifier in “OFF” makes it’s internal sensor highly inaccurate as it needs the fan to be moving air over the sensor in order for it to work correctly.
The only way the automations in this thread will work correctly is by using an external air quality sensor and not using the one built in to the machine, as it introduces the same inaccuracies as using auto mode on the machine itself.
I appreciate the effort put into them, but for people looking at automations here, use an external Air Quality sensor, otherwise it really wont be different to using Auto Mode on the Xiaomi device.
The automations are still useful when used with an external sensor. Don’t rely on the internal sensor on the Xiaomi device to be accurate on every device.

Hi Brendan, can you post the final versions of your automation and config files?

Hi @brendan, appreciate your feedback. What I have thought and created this card my intention was to replicate functionalities from Mi Home app. I have also noticed issues with Fan, when sometime you set a different mode, like Favorite, but it switch to Fan. Please be careful when removing Fun, if you also use the Xioami app, there will be no mode displayed on the card. Basically, 2 of the automation, continuously check the operation mode with the purifier and update the card and vice versa when you change something on the card updates the purifier.
Also, regarding the auto mode, I totally agree with you for an external sensor, but the overcame if you don’t have one is the automation that first starts the purifier if a certain level is detected in auto, then, after a while, it change it according to your predefined Favourite levels depending on accurate PM2.5 reading in Auto mode ON.
Regarding the sensor accuracy, I have also bought a Smart Mi PM2.5 sensor, and it indicates the same value as Xiaomi sensor when ON. Haven’t tested on OFF.

1 Like

Mine is pretty accurate when it is on also, but when it is off, the little fan on the sensor is not running, so it doesn’t detect the particles in the air well. Not sure if this is a firmware update thing or whether they all do it. I am running latest firmware.
You are right about needing to be careful removing the fan automations. In my case, I don’t use the Mi Home app or the button on the front of the device, so it works out for me.
Anyone that uses the Mi Home app or the button on front of the device for control will need to keep the Fan automations as you posted them and just put up with the setting changing during auto operation.
With latest version of Home Assistant we need to change the remote_set_led command back to fan_set_led

First of all, thank you for your effort. Followed the instructions and got everything to work more or less.

I’m using Air Purifier 3H and the xiaomi_miio.remote_set_let_on/off did not work, it complained about a missing command. I used xiaomi_miio.set_led_brightness instead, 0 for on and 2 for off.

Also, LED brightness information seems to be missing on mine, showing 0 all the time.

@brendan the firmware has nothing to do with the accuracy. Just there are no air currents so the estimation is based just on the air around the purifier.

@bjorn.sivertsen the pm2.5 automation is only changing the favorite level, not the fan level.
I am having on my purifier a much more aggressive strategy:

> data_template:
>   level: >
>     {% if states("sensor.mi_air_purifier_air_quality_pm25") | int > 50 -%} 14
>     {%- elif states("sensor.mi_air_purifier_air_quality_pm25") | int > 40 -%} 12
>     {%- elif states("sensor.mi_air_purifier_air_quality_pm25") | int > 30 -%} 9
>     {%- elif states("sensor.mi_air_purifier_air_quality_pm25") | int > 20 -%} 6
>     {%- else -%} 4 {%- endif %}
> entity_id: fan.mi_air_purifier_3h
> service: xiaomi_miio.fan_set_favorite_level

Don’t know why it doesn’t start in your case. Maybe the air quality is good. Try to fry something in the kitchen and it should automatically start. Tested myself.

@Avise as @brendan said above:

With latest version of Home Assistant we need to change the remote_set_led command back to fan_set_led

so you should use xiaomi_miio.fan_set_led_on/xiaomi_miio.fan_set_led_off.

Changed also the yaml above.

1 Like

Sadly i got lot of errors everytime!