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

hmmm the script that you post purifier_mode_change & purifier_mode_changed seem to be same. Both call on to same service.

  action:
    service: input_select.select_option

there is no call to the airpurifier. When I get home i’ll look back at the old setting and see if I can edit it to your setting. From what I see the “set.speed” is change to “set.preset_mode” and the favorite level is totally changed.

tthank you @paddy0174 and @huu,
It’s very kind of you.
this night, when I’ll be back home, I will try the new code ……
I’ll let you know

Can try this one too, see which work for you.

- id: purifier_mode_change
  alias: 'Air Purifier (mode change)'
  trigger:
    entity_id: input_select.zhimi_airpurifier_mode
    platform: state
  action:
    service: fan.set_preset_mode
    data_template:
      preset_mode: "{{ states.input_select.zhimi_airpurifier_mode.state }}"
    entity_id: fan.zhimi_airpurifier_v2
    
- id: purifier_mode_changed
  alias: 'Air Purifier (mode changed)'
  trigger:
    entity_id: fan.zhimi_airpurifier_v2
    platform: state
  condition:
    condition: not
    conditions:
      - condition: state
        entity_id: fan.zhimi_airpurifier_v2
        attribute: preset_mode
        state: null
  action:
    service: input_select.select_option
    data_template:
      option: "{{ state_attr('fan.zhimi_airpurifier_v2', 'preset_mode') }}"
    entity_id: input_select.zhimi_airpurifier_mode

- id: purifier_fav_level_change
  alias: 'Air Purifier (favorite level change)'
  trigger:
    entity_id: input_number.zhimi_airpurifier_favorite_level
    platform: state
  action:
    service: number.set_value
    data_template:
      entity_id: number.zhimi_airpurifier_v2_favorite_level
      value: '{{ states.input_number.zhimi_airpurifier_favorite_level.state | int }}'
 
- id: purifier_fav_level_changed
  alias: 'Air Purifier (favorite level changed)'
  trigger:
    platform: state
    entity_id: number.zhimi_airpurifier_v2_favorite_level
  condition:
    condition: and
    conditions:
    - condition: template
      value_template: "{{ (state_attr('number.zhimi_airpurifier_v2_favorite_level', 'state') | int) != (states('input_number.zhimi_airpurifier_favorite_level') | int) }}"
  action:
    service: input_number.set_value
    entity_id: input_number.zhimi_airpurifier_favorite_level
    data_template:
      value: '{{ states.number.zhimi_airpurifier_mc1_favorite_level.state }}'

Following last update I do not see the favorite level anymore amongst the State attributes. I’m using a Xiaomi Air Purifier 2S (state attribute: model: zhimi.airpurifier.mc1). Anyone else solved this issue?

@ Bergerie
Its a separate entity call [ number.zhimi_airpurifier_mc1_favorite_level] … look in developer tools

Bingo! Thanks a lot. Is it still possible to convert the number box to an input slider for favorite level?

Yep see liuk4friends question above, have to use automation like before but for that new entity.

just edit script for the select template to ignore the “null” error.

template:
- select:
    - name: "Air Purifier Mode"
      state: >
        {% if is_state('fan.zhimi_airpurifier_mc1', 'off') %}
          Silent
        {% else %}
          {{ state_attr('fan.zhimi_airpurifier_mc1', 'preset_mode') }}
        {% endif %}
      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 }}"

This goes in the configuration.yaml replace the input_select.air_purifier_mode and can remove the two associated automation.

1 Like

All done and working perfect. Thanks!

Hi everybody,
First of all, I want to thank you for taking your time to me.
Above all, I want thank @paddy0174 for sacrificing your rest for my incompetence.

I’ve tried the two modified automations (the first by @paddy0174 and the second by @huu) and, unfortunately, in the first scenario (@paddy0174 's suggestion) I’ve found some errors in my logs.

The automations written by @huu, on the other hand, do not cause errors.

Therefore I will try for some time to keep this last configuration.

I still have to try the new template suggested by @huu by removing “input_select.air_purifier_mode”.

2 Likes

For anyone who like a compact view for mobile, only show all entities when the airpurifier is on. Here is an idea for a Lovelace conditional card (Use text ‘search and replace’ to replace all instance off “zhimi_airpurifier_mc1” to your device name - assuming keeping naming consistent). Just add card → show code editor and paste this in. Two entity that also need edit is select.air_purifier_mode (your select mode) and number.zhimi_airpurifier_mc1_favorite_level (your select fav level).
example

type: vertical-stack
cards:
  - type: conditional
    conditions:
      - entity: fan.zhimi_airpurifier_mc1
        state: 'on'
    card:
      type: vertical-stack
      cards:
        - type: horizontal-stack
          cards:
            - type: entities
              entities:
                - entity: fan.zhimi_airpurifier_mc1
              state_color: true
            - type: entities
              entities:
                - entity: select.air_purifier_mode
              state_color: true
        - type: horizontal-stack
          cards:
            - type: horizontal-stack
              cards:
                - type: entities
                  entities:
                    - entity: number.zhimi_airpurifier_mc1_favorite_level
                      name: Favorite Level
                    - entity: switch.zhimi_airpurifier_mc1_child_lock
                      name: Child Lock
                    - entity: switch.zhimi_airpurifier_mc1_led
                      name: LED
                    - entity: sensor.zhimi_airpurifier_mc1_temperature
                      name: Temperature
                    - entity: sensor.zhimi_airpurifier_mc1_filter_use
                      name: Filter Use
                  state_color: true
                - type: entities
                  entities:
                    - entity: sensor.zhimi_airpurifier_mc1_motor_speed
                      name: Motor Speed
                    - entity: sensor.zhimi_airpurifier_mc1_pm2_5
                      name: Particle
                    - entity: switch.zhimi_airpurifier_mc1_buzzer
                      name: Buzzer
                    - entity: sensor.zhimi_airpurifier_mc1_humidity
                      name: Humidity
                    - entity: sensor.zhimi_airpurifier_mc1_filter_life_remaining
                      name: Filter Remaining
                  state_color: true
  - type: conditional
    conditions:
      - entity: fan.zhimi_airpurifier_mc1
        state: 'off'
    card:
      type: horizontal-stack
      cards:
        - type: entities
          entities:
            - entity: fan.zhimi_airpurifier_mc1
          state_color: true
1 Like

I have completely removed everything from my configuration files for my two Xiaomi air purifiers. They are models “zhimi.airpurifier.mc1” and “zhimi.airpurifier.mb3”.

But in the HA integration, only “zhimi.airpurifier.mc1” automatically appeared to me, the other one “zhimi.airpurifier.mb3” is not visible.

Do I need to configure anything further to see the other one as well?

Also, the switch for modes and fan speed settings did not appear in the device tab. What to do?

Can anyone help please?

Hi guys, I have problem with changing my automatizations after changes in HA. Could you help me? My action looks

  action:
    - service: fan.set_preset_mode
      entity_id: fan.zhimi_airpurifier_mc1
      data:
        preset_mode: Favorite
    - service: xiaomi_miio.fan_set_Favorite_level
      data_template:
        entity_id: fan.zhimi_airpurifier_mc1
        level: >
            {% if states('sensor.poziom_pm2_5') | int > 30 %}
              14
            {% elif states('sensor.poziom_pm2_5') | int > 25 %}
              10
            {% elif states('sensor.poziom_pm2_5') | int > 15 %}
              5
            {% elif states('sensor.poziom_pm2_5') | int > 10 %}
              3
            {% elif states('sensor.poziom_pm2_5') | int > 5 %}
              1
            {% else %}
              1
            {% endif %}
            

This works, remember to remove the additional conditions I have in there.

The services fan_set_favorite_level have been removed and number entity have been created instead.

  action:
    - service: fan.set_preset_mode
      entity_id: fan.zhimi_airpurifier_mc1
      data:
        preset_mode: Favorite
    - service: number.xiaomi_air_purifier_favorite_level
      data_template:
        entity_id: fan.zhimi_airpurifier_mc1
        value: >
            {% if states('sensor.poziom_pm2_5') | int > 30 %}
              14
            {% elif states('sensor.poziom_pm2_5') | int > 25 %}
              10
            {% elif states('sensor.poziom_pm2_5') | int > 15 %}
              5
            {% elif states('sensor.poziom_pm2_5') | int > 10 %}
              3
            {% elif states('sensor.poziom_pm2_5') | int > 5 %}
              1
            {% else %}
              1
            {% endif %}
            

Where can I find the device token of my Xiaomi Air purifier 3H ?

Hi all,
I’m using the “Pro H” and could connect it as “mb3” ( zhimi.airpurifier.mb3).

All Sensors and switches seem to show up, but:

  • The only switch, that seems not to exist is the general “power” switch.
    That means, I can switch it on by increasing fan speed to 1-3. But cannot switch it off, again.
  • And the “Operation modes (Auto, Silent, Favorite, Fan)” are also missing.

Anyone else had that or can give me some direction?

Thanks

My xiaomi air purifier pro H identifies as a fan (fan.xiaomi_miio_device). Therefore the “power” button is incorporated in the fan control. Hope that helps…

1 Like

Amazing, that was it!

There was another “unnamed device” without unique ID. Hence, it didn’t show up in the GUI.