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

I did not checked it, however I have added more complicated conditions take look at my config for Purifier night mode

- id: set_favorite_level_at_nights
  alias: Set favorite fan speed during night
  trigger: 
    platform: time_pattern
    minutes: '/5'
    # seconds: '00'
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: fan.mi_2s
      state: 'on'
    - condition: time
      after: '22:30:00'
      before: '07:59:00'
  action:
    - service: fan.set_speed
      data_template:
        entity_id: fan.mi_2s
        speed: Favorite
    - service: fan.xiaomi_miio_set_favorite_level
      data_template:
        entity_id: fan.mi_2s
        level: >-
            {% if state_attr('fan.mi_2s', 'aqi') | int >10 %}
              1
            {% else %}
              0
            {% endif %}

the key here is additional condition (and) state: on
that way if I switch Mi Purifier off my automations never triggers, other way without this small addition if I switch it off my automations turn it on again. This allows me to turn purifier off manually and it stays off until it is switched on manually or by some other automations that don’t care whether purifier is on or off.
I am not sure if it answers your question but this is one way of dealing with more complicated conditions.

2 Likes

Thanks a lot! I’ll try this and I think it helps.
I hate when my log is full of junk :wink:

1 Like

Is v3 supported ?

Same question – will this work with Air Purifier 3?

I’ve adde some Air Purifier Pro (v.7) volume control based on guys previous great job in this topic! Thanks! :slight_smile:

automations.yaml

- alias: Air Purifier volume level change
  trigger:
    entity_id: input_number.xiaomi_airpurifier_volume
    platform: state
  action:
    service: fan.xiaomi_miio_set_volume
    data_template:
      entity_id: fan.xiaomi_miio_device
      volume: '{{ states.input_number.xiaomi_airpurifier_volume.state | int }}'
- alias: Air Purifier volume level changed
  trigger:
    platform: state
    entity_id: fan.xiaomi_miio_device
  condition:
    condition: and
    conditions:
    - condition: template
      value_template: "{{ (state_attr('fan.xiaomi_miio_device', 'volume') | int) != (states('input_number.xiaomi_airpurifier_volume') | int) }}"
  action:
    service: input_number.set_value
    entity_id: input_number.xiaomi_airpurifier_volume
    data_template:
      value: '{{ states.fan.xiaomi_miio_device.attributes.volume }}'

configuration.yaml

# INPUT_NUMBER
input_number:
  # Xiaomi Air Purifier PRO
  xiaomi_airpurifier_favorite_level:
    name: "Favorite level"
    initial: 0
    min: 0
    max: 14
    step: 1
    icon: "mdi:weather-windy"
  xiaomi_airpurifier_volume:
    name: "Volume level"
    initial: 20
    min: 0
    max: 100
    step: 1
    icon: "mdi:volume-medium"

lovelace card

entities:
  - entity: input_number.xiaomi_airpurifier_volume
2 Likes

Thank you for great work.
I think that groups.yaml also can be helpful. Especially for those who don’t use cards yaml and use automatic interface.

  airpurifier:
    name: Xiaomi Air Purifier Pro
    entities:
      - fan.xiaomi_miio_device
      - input_select.xiaomi_airpurifier_mode
      - input_number.xiaomi_airpurifier_favorite_level
#      - input_number.xiaomi_airpurifier_volume # AirPurifier Pro
      - switch.xiaomi_airpurifier_child_lock
      - switch.xiaomi_airpurifier_led
      - switch.xiaomi_airpurifier_buzzer
      - sensor.xiaomi_airpurifier_speed
      - sensor.xiaomi_airpurifier_filter_remaining
      - sensor.xiaomi_airpurifier_air_quality_pm25
      - sensor.xiaomi_airpurifier_temp
      - sensor.xiaomi_airpurifier_humidity

HA log says that maximum favorite level for Pro is 16, not 14.
You can see this notification in HA log if turn maximum level from Mi Home application.

1 Like

Thanks for info! I’ll fix it.

Thanks for the great work putting things together for Mi Air Purifier.

I ported the automations for switch controls in the first post to Node-Red if anyone interested. (some entities name are changed)

image

[
    {
        "id": "93baa36e.9ebff",
        "type": "server-state-changed",
        "z": "52c9cd1c.793d94",
        "name": "when mode switch is selected",
        "server": "1c37c39d.61b2fc",
        "version": 1,
        "entityidfilter": "input_select.miair_mode",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "output_only_on_state_change": true,
        "x": 220,
        "y": 440,
        "wires": [
            [
                "10ae046f.c847bc"
            ]
        ]
    },
    {
        "id": "10ae046f.c847bc",
        "type": "api-call-service",
        "z": "52c9cd1c.793d94",
        "name": "set purifier mode",
        "server": "1c37c39d.61b2fc",
        "version": 1,
        "debugenabled": true,
        "service_domain": "fan",
        "service": "set_speed",
        "entityId": "fan.xiaomi_miio_device",
        "data": "{\"speed\":\"{{payload}}\"}",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 490,
        "y": 440,
        "wires": [
            []
        ]
    },
    {
        "id": "826c4203.6edcd",
        "type": "server-state-changed",
        "z": "52c9cd1c.793d94",
        "name": "when purifier turned on",
        "server": "1c37c39d.61b2fc",
        "version": 1,
        "entityidfilter": "fan.xiaomi_miio_device",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "on",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 2,
        "output_only_on_state_change": true,
        "x": 240,
        "y": 520,
        "wires": [
            [
                "a69f5269.141b3"
            ],
            []
        ]
    },
    {
        "id": "a69f5269.141b3",
        "type": "api-call-service",
        "z": "52c9cd1c.793d94",
        "name": "change input_select to running mode",
        "server": "1c37c39d.61b2fc",
        "version": 1,
        "debugenabled": true,
        "service_domain": "input_select",
        "service": "select_option",
        "entityId": "input_select.miair_mode",
        "data": "{\"option\": \"{{data.new_state.attributes.speed}}\"}",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 550,
        "y": 520,
        "wires": [
            []
        ]
    },
    {
        "id": "b64f1f25.c1eb1",
        "type": "comment",
        "z": "52c9cd1c.793d94",
        "name": "Mi Air Purifier basic switch controls",
        "info": "",
        "x": 340,
        "y": 380,
        "wires": []
    },
    {
        "id": "45cb24aa.f0f81c",
        "type": "server-state-changed",
        "z": "52c9cd1c.793d94",
        "name": "when fav_level is selected",
        "server": "1c37c39d.61b2fc",
        "version": 1,
        "entityidfilter": "input_number.miair_fav_level",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "num",
        "haltifstate": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "output_only_on_state_change": true,
        "x": 230,
        "y": 600,
        "wires": [
            [
                "4a224d74.01fc04"
            ]
        ]
    },
    {
        "id": "4a224d74.01fc04",
        "type": "api-call-service",
        "z": "52c9cd1c.793d94",
        "name": "set purifier fav_level",
        "server": "1c37c39d.61b2fc",
        "version": 1,
        "debugenabled": true,
        "service_domain": "fan",
        "service": "xiaomi_miio_set_favorite_level",
        "entityId": "fan.xiaomi_miio_device",
        "data": "{\"level\":\"{{payload}}\"}",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 500,
        "y": 600,
        "wires": [
            []
        ]
    },
    {
        "id": "695f06ce.0372d8",
        "type": "server-state-changed",
        "z": "52c9cd1c.793d94",
        "name": "when purifier turned on",
        "server": "1c37c39d.61b2fc",
        "version": 1,
        "entityidfilter": "fan.xiaomi_miio_device",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "on",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 2,
        "output_only_on_state_change": true,
        "x": 240,
        "y": 680,
        "wires": [
            [
                "f73a9ba8.9848c8"
            ],
            []
        ]
    },
    {
        "id": "f73a9ba8.9848c8",
        "type": "api-call-service",
        "z": "52c9cd1c.793d94",
        "name": "change input_number to running level",
        "server": "1c37c39d.61b2fc",
        "version": 1,
        "debugenabled": true,
        "service_domain": "input_number",
        "service": "set_value",
        "entityId": "input_number.miair_fav_level",
        "data": "{\"value\": \"{{data.new_state.attributes.favorite_level}}\"}",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 550,
        "y": 680,
        "wires": [
            []
        ]
    },
    {
        "id": "1c37c39d.61b2fc",
        "type": "server",
        "z": "",
        "name": "Home Assistant"
    }
]

Is the card still working for all of you? I’m having problems with fan speed, turning on the screen and sound, after updating HA.

possibly because miio service calls were moved to its own domain since last update.

Mmm, how can I solve these problems?

Change service call domain to “xiaomi_miio”.

Where do I change that?

Wherever you call the service.

Using this piece of OP’s automation code as example

- alias: Air Purifier favorite level change
  trigger:
    entity_id: input_number.xiaomi_airpurifier_favorite_level
    platform: state
  action:
    service: fan.xiaomi_miio_set_favorite_level
    data_template:
      entity_id: fan.xiaomi_miio_device
      level: '{{ states.input_number.xiaomi_airpurifier_favorite_level.state | int }}'

This line
“service: fan.xiaomi_miio_set_favorite_level”

change to “service: xiaomi_miio.fan_set_favorite_level”

2 Likes

Various errors:

  • Error call service switch/turn_on. Unable to find service fan/xiaomi_miio_set_child_lock_on
  • Error service call switch/turn_on. Unable to find service fan/xiaomi_miio_set_led_on
  • Error service call switch/turn_on. Unable to find service fan/xiaomi_miio_set_buzzer_on

How too solved?

Is for Air Purifier Xiaomi 2S

1 Like

change your

service: fan.xiaomi_miio_xxxxxxxx

lines to

service: xiaomi_miio.fan_xxxxxxxx

If your use configurator add-on, you should be able to select the correct service calls from the left side panel.

3 Likes

I have Xiaomi Purifier 2 and good working only two options (on/off and change mode). Any other doesn’t works - like air quality, fan speed, led etc.

I tried change the line service: fan.xiamio_miio_xxxxx and doesn’t help

Lots of different models with small differences.
I have Pro v7 and had to change bit… it is the way it goes :slight_smile: