Lovelace: Xiaomi - Mi air purifier 3H card

Hi @eadin79.
you can easily add the lovelace code through the GUI. Go to the dashboard where you want to add it and click the three dots in right upper corner and select Edit Dashboard.

image

Then click the “+ Add Card” in lower right, scroll all the way down and select “Manual”.


And then just replace the default text type: ' ' with the lovelace.yaml code

great
thanks

This is a general issue for 3H https://github.com/home-assistant/core/issues/36972

At first: thank you again for your great work :slight_smile:
Made a few changes! If the creator has no problem with it, i can share the changes!
Changes are: bigger Power Button, in Standby Display is dark, every Mode is Displayed as in Real Display (inc. Fan Mode 1-3), Background is Transparent (clear)!

3 Likes

Please, share the changes.

If can share the changes if the creators allow it!

Would the newest release impact the code related to fan.speed?

Breaking Changes

Yes not all preset modes are available, Silent is missing. And of course set_speed must be changed to set_preset_mode.

1 Like

Nice work, sure, you can present. This is an open topic :grinning:

Put the files in the www folder!
Files

Lovelace:

type: picture-elements
image: local/Air3H.png
elements:
  - type: conditional
    conditions:
      - entity: sensor.mi_air_purifier_pm25_severity
        state: clean
      - entity: binary_sensor.mi_air_purifier_mode_off
        state: 'off'
    elements:
      - type: image
        entity: sensor.mi_air_purifier_pm25_severity
        title: PM2.5 severity level
        tap_action:
          action: more-info
        state_image:
          clean: local/Air3H1.png
        style:
          top: 34%
          left: 69%
  - type: conditional
    conditions:
      - entity: sensor.mi_air_purifier_pm25_severity
        state: polluted
      - entity: binary_sensor.mi_air_purifier_mode_off
        state: 'off'
    elements:
      - type: image
        entity: sensor.mi_air_purifier_pm25_severity
        title: PM2.5 severity level
        tap_action:
          action: more-info
        state_image:
          polluted: local/Air3H2.png
        style:
          top: 34%
          left: 69%
  - type: conditional
    conditions:
      - entity: sensor.mi_air_purifier_pm25_severity
        state: critical
      - entity: binary_sensor.mi_air_purifier_mode_off
        state: 'off'
    elements:
      - type: image
        entity: sensor.mi_air_purifier_pm25_severity
        title: PM2.5 severity level
        tap_action:
          action: more-info
        state_image:
          critical: local/Air3H3.png
        style:
          top: 34%
          left: 69%
  - type: state-icon
    entity: binary_sensor.mi_air_purifier_mode_off
    title: 'Off'
    icon: 'mdi:power-standby'
    tap_action:
      action: call-service
      service: fan.turn_off
      service_data:
        entity_id: fan.mi_air_purifier_3h
    style:
      top: 1%
      left: 5%
      '--mdc-icon-size': 70px
      transform: 'translate(-50%, 0)'
      '--paper-item-icon-color': 'rgb(128, 128, 128)'
      '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
  - type: state-icon
    entity: fan.mi_air_purifier_3h
    title: More Info
    icon: 'mdi:dots-vertical'
    tap_action:
      action: more-info
    style:
      top: 1%
      left: 36%
      transform: 'translate(-50%, 0)'
      '--paper-item-icon-color': 'rgb(128, 128, 128)'
      '--paper-item-icon-active-color': 'rgb(128, 128, 128)'
  - type: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_off
        state: 'off'
    elements:
      - type: state-label
        entity: sensor.mi_air_purifier_air_quality_pm25
        title: PM2.5
        tap_action:
          action: more-info
        style:
          top: 19%
          left: 68.5%
          min-width: 40px
          min-height: 40px
          text-align: center
          font-size: 400%
          transform: 'translate(-50%, 0)'
          color: 'rgb(255,255,255)'
      - type: state-label
        entity: sensor.mi_air_purifier_temp
        title: Temperature
        tap_action:
          action: more-info
        style:
          top: 32%
          left: 62%
          min-width: 40px
          min-height: 40px
          text-align: center
          font-size: 75%
          transform: 'translate(-50%, 0)'
          color: 'rgb(255,255,255)'
      - type: state-label
        entity: sensor.mi_air_purifier_humidity
        title: Humidity
        tap_action:
          action: more-info
        style:
          top: 32%
          left: 69%
          min-width: 40px
          min-height: 40px
          text-align: center
          font-size: 75%
          transform: 'translate(-50%, 0)'
          color: 'rgb(255,255,255)'
      - type: state-icon
        entity: switch.mi_air_purifier_led
        title: Display
        tap_action:
          action: toggle
        style:
          top: 15%
          left: 36%
          transform: 'translate(-50%, 0)'
          '--paper-item-icon-color': 'rgb(128, 128, 128)'
          '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
      - type: state-icon
        entity: switch.mi_air_purifier_buzzer
        title: Buzzer
        tap_action:
          action: toggle
        style:
          top: 29%
          left: 36%
          transform: 'translate(-50%, 0)'
          '--paper-item-icon-color': 'rgb(128, 128, 128)'
          '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
      - type: state-icon
        entity: switch.mi_air_purifier_child_lock
        title: Child lock
        tap_action:
          action: toggle
        style:
          top: 1%
          left: 26%
          transform: 'translate(-50%, 0)'
          '--paper-item-icon-color': 'rgb(128, 128, 128)'
          '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
      - type: state-label
        entity: sensor.mi_air_purifier_filter_remaining
        title: Filter remaining
        tap_action:
          action: more-info
        style:
          top: 10%
          left: 92%
          min-width: 40px
          min-height: 40px
          text-align: center
          font-size: 80%
          color: 'rgb(128,128,128)'
  - type: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_off
        state: 'off'
    elements:
      - type: image
        entity: binary_sensor.mi_air_purifier
        title: Divider
        image: local/Air3HDivider.png
        style:
          top: 33%
          left: 69%
          width: 24%
          transform: 'translate(-50%, 0)'
      - type: state-label
        entity: sensor.mi_air_purifier_air_quality_pm25
        title: PM2.5
        tap_action:
          action: more-info
        style:
          top: 19%
          left: 68.5%
          min-width: 40px
          min-height: 40px
          text-align: center
          font-size: 400%
          transform: 'translate(-50%, 0)'
          color: 'rgb(255, 255, 255)'
      - type: state-label
        entity: sensor.mi_air_purifier_temp
        title: Temperature
        tap_action:
          action: more-info
        style:
          top: 32%
          left: 62%
          min-width: 40px
          min-height: 40px
          text-align: center
          font-size: 75%
          transform: 'translate(-50%, 0)'
          color: 'rgb(255, 255, 255)'
      - type: state-label
        entity: sensor.mi_air_purifier_humidity
        title: Humidity
        tap_action:
          action: more-info
        style:
          top: 32%
          left: 69%
          min-width: 40px
          min-height: 40px
          text-align: center
          font-size: 75%
          transform: 'translate(-50%, 0)'
          color: 'rgb(255, 255, 255)'
  - type: state-icon
    entity: binary_sensor.mi_air_purifier_mode_auto
    title: Auto
    icon: 'mdi:autorenew'
    tap_action:
      action: call-service
      service: fan.set_speed
      service_data:
        entity_id: fan.mi_air_purifier_3h
        speed: Auto
    style:
      top: 50%
      left: 6%
      transform: 'translate(-50%, 0)'
      '--paper-item-icon-color': 'rgb(192, 192, 192)'
      '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
  - type: state-icon
    entity: binary_sensor.mi_air_purifier_mode_silent
    title: Silent
    icon: 'mdi:power-sleep'
    tap_action:
      action: call-service
      service: fan.set_speed
      service_data:
        entity_id: fan.mi_air_purifier_3h
        speed: Silent
    style:
      top: 50%
      left: 16%
      transform: 'translate(-50%, 0)'
      '--paper-item-icon-color': 'rgb(192, 192, 192)'
      '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
  - type: state-icon
    entity: binary_sensor.mi_air_purifier_mode_fan
    title: Fan
    icon: 'mdi:fan'
    tap_action:
      action: call-service
      service: fan.set_speed
      service_data:
        entity_id: fan.mi_air_purifier_3h
        speed: Fan
    style:
      top: 50%
      left: 26%
      transform: 'translate(-50%, 0)'
      '--paper-item-icon-color': 'rgb(192, 192, 192)'
      '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
  - type: state-icon
    entity: binary_sensor.mi_air_purifier_mode_favorite
    title: Favorite
    icon: 'mdi:heart'
    tap_action:
      action: call-service
      service: fan.set_speed
      service_data:
        entity_id: fan.mi_air_purifier_3h
        speed: Favorite
    style:
      top: 50%
      left: 36%
      transform: 'translate(-50%, 0)'
      '--paper-item-icon-color': 'rgb(192, 192, 192)'
      '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
  - type: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_fan
        state: 'on'
    elements:
      - type: state-icon
        entity: binary_sensor.mi_air_purifier_mode_fan_1
        title: Fan level 1
        icon: 'mdi:fan-speed-1'
        tap_action:
          action: call-service
          service: xiaomi_miio.fan_set_fan_level
          service_data:
            entity_id: fan.mi_air_purifier_3h
            level: 1
        style:
          top: 64%
          left: 11%
          transform: 'translate(-50%, 0)'
          '--paper-item-icon-color': 'rgb(192, 192, 192)'
          '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
      - type: state-icon
        entity: binary_sensor.mi_air_purifier_mode_fan_2
        title: Fan level 2
        icon: 'mdi:fan-speed-2'
        tap_action:
          action: call-service
          service: xiaomi_miio.fan_set_fan_level
          service_data:
            entity_id: fan.mi_air_purifier_3h
            level: 2
        style:
          top: 64%
          left: 21%
          transform: 'translate(-50%, 0)'
          '--paper-item-icon-color': 'rgb(192, 192, 192)'
          '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
      - type: state-icon
        entity: binary_sensor.mi_air_purifier_mode_fan_3
        title: Fan level 3
        icon: 'mdi:fan-speed-3'
        tap_action:
          action: call-service
          service: xiaomi_miio.fan_set_fan_level
          service_data:
            entity_id: fan.mi_air_purifier_3h
            level: 3
        style:
          top: 64%
          left: 31%
          transform: 'translate(-50%, 0)'
          '--paper-item-icon-color': 'rgb(192, 192, 192)'
          '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
  - type: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_favorite
        state: 'on'
    elements:
      - type: state-label
        entity: sensor.mi_air_purifier_favorite_level
        title: Favorite level
        tap_action:
          action: none
        style:
          top: 64%
          left: 21%
          min-width: 40px
          min-height: 40px
          text-align: center
          font-size: 200%
          transform: 'translate(-50%, 0)'
          color: 'rgb(255, 128, 0)'
      - type: icon
        icon: 'mdi:plus'
        title: Favorite level +
        tap_action:
          action: call-service
          service: script.favorite_up
          service_data:
            entity_id: fan.mi_air_purifier_3h
            step: 2
        style:
          top: 66%
          left: 30%
          min-width: 40px
          min-height: 40px
          transform: 'translate(-50%, 0)'
          color: 'rgb(192, 192, 192)'
          color_off: 'rgb(255, 128, 0)'
      - type: icon
        icon: 'mdi:minus'
        title: Favorite level -
        tap_action:
          action: call-service
          service: script.favorite_down
          service_data:
            entity_id: fan.mi_air_purifier_3h
            step: 1
        style:
          top: 66%
          left: 16%
          min-width: 40px
          min-height: 40px
          transform: 'translate(-50%, 0)'
          color: 'rgb(192, 192, 192)'
          color_off: 'rgb(255, 128, 0)'
      - type: state-label
        entity: input_select.mi_air_purifier_coverage
        title: Coverage
        tap_action:
          action: none
        style:
          top: 74%
          left: 23%
          min-width: 40px
          min-height: 40px
          text-align: center
          font-size: 100%
          transform: 'translate(-50%, 0)'
          color: 'rgb(255, 128, 0)'
  - type: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_auto
        state: 'on'
    elements:
      - type: image
        entity: binary_sensor.mi_air_purifier_mode_auto
        title: AutoMode
        image: local/Air3HAuto.png
        style:
          top: 34%
          left: 79%
          width: 4.5%
          transform: 'translate(-50%, 0)'
  - type: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_silent
        state: 'on'
    elements:
      - type: image
        entity: binary_sensor.mi_air_purifier_mode_silent
        title: SilentMode
        image: local/Air3HSilent.png
        style:
          top: 34%
          left: 79%
          width: 4.5%
          transform: 'translate(-50%, 0)'
  - type: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_fan_1
        state: 'on'
    elements:
      - type: image
        entity: binary_sensor.mi_air_purifier_mode_fan_1
        title: FanMode
        image: local/Air3HFan1.png
        style:
          top: 34%
          left: 79%
          width: 4.5%
          transform: 'translate(-50%, 0)'
  - type: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_fan_2
        state: 'on'
    elements:
      - type: image
        entity: binary_sensor.mi_air_purifier_mode_fan_2
        title: FanMode
        image: local/Air3HFan2.png
        style:
          top: 34%
          left: 79%
          width: 4.5%
          transform: 'translate(-50%, 0)'
  - type: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_fan_3
        state: 'on'
    elements:
      - type: image
        entity: binary_sensor.mi_air_purifier_mode_fan_3
        title: FanMode
        image: local/Air3HFan3.png
        style:
          top: 34%
          left: 79%
          width: 4.5%
          transform: 'translate(-50%, 0)'
  - type: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_favorite
        state: 'on'
    elements:
      - type: image
        entity: binary_sensor.mi_air_purifier_mode_favorite
        title: FavoriteMode
        image: local/Air3HFavorite.png
        style:
          top: 34%
          left: 79%
          width: 4.5%
          transform: 'translate(-50%, 0)'

2 Likes

Files are not available for me. 403 Forbinden

I used an other Filehoster! try now :slight_smile:

Thx, got it now.
You have some errors in the code for Lovelace, but i fixed them.

type: picture-elements
image: local/Air3H.png
elements:
  - type: conditional
    conditions:
      - entity: sensor.mi_air_purifier_pm25_severity
        state: clean
      - entity: binary_sensor.mi_air_purifier_mode_off
        state: 'off'
    elements:
      - type: image
        entity: sensor.mi_air_purifier_pm25_severity
        title: PM2.5 severity level
        tap_action:
          action: more-info
        state_image:
          clean: local/Air3H1.png
        style:
          top: 34%
          left: 69%
  - type: conditional
    conditions:
      - entity: sensor.mi_air_purifier_pm25_severity
        state: polluted
      - entity: binary_sensor.mi_air_purifier_mode_off
        state: 'off'
    elements:
      - type: image
        entity: sensor.mi_air_purifier_pm25_severity
        title: PM2.5 severity level
        tap_action:
          action: more-info
        state_image:
          polluted: local/Air3H2.png
        style:
          top: 34%
          left: 69%
  - type: conditional
    conditions:
      - entity: sensor.mi_air_purifier_pm25_severity
        state: critical
      - entity: binary_sensor.mi_air_purifier_mode_off
        state: 'off'
    elements:
      - type: image
        entity: sensor.mi_air_purifier_pm25_severity
        title: PM2.5 severity level
        tap_action:
          action: more-info
        state_image:
          critical: local/Air3H3.png
        style:
          top: 34%
          left: 69%
  - type: state-icon
    entity: fan.mi_air_purifier_3h
    title: 'Off'
    icon: 'mdi:power-standby'
    tap_action:
      action: call-service
      service: fan.toggle
      service_data:
        entity_id: fan.mi_air_purifier_3h
    style:
      top: 1%
      left: 5%
      '--mdc-icon-size': 70px
      transform: 'translate(-50%, 0)'
      '--paper-item-icon-color': 'rgb(128, 128, 128)'
      '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
  - type: state-icon
    entity: fan.mi_air_purifier_3h
    title: 'On'
    icon: 'mdi:power-standby'
    tap_action:
      action: call-service
      service: fan.toggle
      service_data:
        entity_id: fan.mi_air_purifier_3h
    style:
      top: 1%
      left: 5%
      '--mdc-icon-size': 70px
      transform: 'translate(-50%, 0)'
      '--paper-item-icon-color': 'rgb(128, 128, 128)'
      '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
  - type: state-icon
    entity: fan.mi_air_purifier_3h
    title: More Info
    icon: 'mdi:dots-vertical'
    tap_action:
      action: more-info
    style:
      top: 1%
      left: 36%
      transform: 'translate(-50%, 0)'
      '--paper-item-icon-color': 'rgb(128, 128, 128)'
      '--paper-item-icon-active-color': 'rgb(128, 128, 128)'
  - type: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_off
        state: 'off'
    elements:
      - type: state-label
        entity: sensor.mi_air_purifier_air_quality_pm25
        title: PM2.5
        tap_action:
          action: more-info
        style:
          top: 19%
          left: 68.5%
          min-width: 40px
          min-height: 40px
          text-align: center
          font-size: 400%
          transform: 'translate(-50%, 0)'
          color: 'rgb(255,255,255)'
      - type: state-label
        entity: sensor.mi_air_purifier_temp
        title: Temperature
        tap_action:
          action: more-info
        style:
          top: 32%
          left: 62%
          min-width: 40px
          min-height: 40px
          text-align: center
          font-size: 75%
          transform: 'translate(-50%, 0)'
          color: 'rgb(255,255,255)'
      - type: state-label
        entity: sensor.mi_air_purifier_humidity
        title: Humidity
        tap_action:
          action: more-info
        style:
          top: 32%
          left: 69%
          min-width: 40px
          min-height: 40px
          text-align: center
          font-size: 75%
          transform: 'translate(-50%, 0)'
          color: 'rgb(255,255,255)'
      - type: state-icon
        entity: switch.mi_air_purifier_led
        title: Display
        tap_action:
          action: toggle
        style:
          top: 15%
          left: 36%
          transform: 'translate(-50%, 0)'
          '--paper-item-icon-color': 'rgb(128, 128, 128)'
          '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
      - type: state-icon
        entity: switch.mi_air_purifier_buzzer
        title: Buzzer
        tap_action:
          action: toggle
        style:
          top: 29%
          left: 36%
          transform: 'translate(-50%, 0)'
          '--paper-item-icon-color': 'rgb(128, 128, 128)'
          '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
      - type: state-icon
        entity: switch.mi_air_purifier_child_lock
        title: Child lock
        tap_action:
          action: toggle
        style:
          top: 1%
          left: 26%
          transform: 'translate(-50%, 0)'
          '--paper-item-icon-color': 'rgb(128, 128, 128)'
          '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
      - type: state-label
        entity: sensor.mi_air_purifier_filter_remaining
        title: Filter remaining
        tap_action:
          action: more-info
        style:
          top: 10%
          left: 92%
          min-width: 40px
          min-height: 40px
          text-align: center
          font-size: 80%
          color: 'rgb(128,128,128)'
  - type: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_off
        state: 'off'
    elements:
      - type: image
        entity: binary_sensor.mi_air_purifier
        title: Divider
        image: local/Air3HDivider.png
        style:
          top: 33%
          left: 69%
          width: 24%
          transform: 'translate(-50%, 0)'
      - type: state-label
        entity: sensor.mi_air_purifier_air_quality_pm25
        title: PM2.5
        tap_action:
          action: more-info
        style:
          top: 19%
          left: 68.5%
          min-width: 40px
          min-height: 40px
          text-align: center
          font-size: 400%
          transform: 'translate(-50%, 0)'
          color: 'rgb(255, 255, 255)'
      - type: state-label
        entity: sensor.mi_air_purifier_temp
        title: Temperature
        tap_action:
          action: more-info
        style:
          top: 32%
          left: 62%
          min-width: 40px
          min-height: 40px
          text-align: center
          font-size: 75%
          transform: 'translate(-50%, 0)'
          color: 'rgb(255, 255, 255)'
      - type: state-label
        entity: sensor.mi_air_purifier_humidity
        title: Humidity
        tap_action:
          action: more-info
        style:
          top: 32%
          left: 69%
          min-width: 40px
          min-height: 40px
          text-align: center
          font-size: 75%
          transform: 'translate(-50%, 0)'
          color: 'rgb(255, 255, 255)'
  - type: state-icon
    entity: binary_sensor.mi_air_purifier_mode_auto
    title: Auto
    icon: 'mdi:autorenew'
    tap_action:
      action: call-service
      service: fan.set_speed
      service_data:
        entity_id: fan.mi_air_purifier_3h
        speed: Auto
    style:
      top: 50%
      left: 6%
      transform: 'translate(-50%, 0)'
      '--paper-item-icon-color': 'rgb(192, 192, 192)'
      '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
  - type: state-icon
    entity: binary_sensor.mi_air_purifier_mode_silent
    title: Silent
    icon: 'mdi:power-sleep'
    tap_action:
      action: call-service
      service: fan.set_speed
      service_data:
        entity_id: fan.mi_air_purifier_3h
        speed: Silent
    style:
      top: 50%
      left: 16%
      transform: 'translate(-50%, 0)'
      '--paper-item-icon-color': 'rgb(192, 192, 192)'
      '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
  - type: state-icon
    entity: binary_sensor.mi_air_purifier_mode_fan
    title: Fan
    icon: 'mdi:fan'
    tap_action:
      action: call-service
      service: fan.set_speed
      service_data:
        entity_id: fan.mi_air_purifier_3h
        speed: Fan
    style:
      top: 50%
      left: 26%
      transform: 'translate(-50%, 0)'
      '--paper-item-icon-color': 'rgb(192, 192, 192)'
      '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
  - type: state-icon
    entity: binary_sensor.mi_air_purifier_mode_favorite
    title: Favorite
    icon: 'mdi:heart'
    tap_action:
      action: call-service
      service: fan.set_speed
      service_data:
        entity_id: fan.mi_air_purifier_3h
        speed: Favorite
    style:
      top: 50%
      left: 36%
      transform: 'translate(-50%, 0)'
      '--paper-item-icon-color': 'rgb(192, 192, 192)'
      '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
  - type: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_fan
        state: 'on'
    elements:
      - type: state-icon
        entity: binary_sensor.mi_air_purifier_mode_fan_1
        title: Fan level 1
        icon: 'mdi:fan-speed-1'
        tap_action:
          action: call-service
          service: xiaomi_miio.fan_set_fan_level
          service_data:
            entity_id: fan.mi_air_purifier_3h
            level: 1
        style:
          top: 64%
          left: 11%
          transform: 'translate(-50%, 0)'
          '--paper-item-icon-color': 'rgb(192, 192, 192)'
          '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
      - type: state-icon
        entity: binary_sensor.mi_air_purifier_mode_fan_2
        title: Fan level 2
        icon: 'mdi:fan-speed-2'
        tap_action:
          action: call-service
          service: xiaomi_miio.fan_set_fan_level
          service_data:
            entity_id: fan.mi_air_purifier_3h
            level: 2
        style:
          top: 64%
          left: 21%
          transform: 'translate(-50%, 0)'
          '--paper-item-icon-color': 'rgb(192, 192, 192)'
          '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
      - type: state-icon
        entity: binary_sensor.mi_air_purifier_mode_fan_3
        title: Fan level 3
        icon: 'mdi:fan-speed-3'
        tap_action:
          action: call-service
          service: xiaomi_miio.fan_set_fan_level
          service_data:
            entity_id: fan.mi_air_purifier_3h
            level: 3
        style:
          top: 64%
          left: 31%
          transform: 'translate(-50%, 0)'
          '--paper-item-icon-color': 'rgb(192, 192, 192)'
          '--paper-item-icon-active-color': 'rgb(255, 128, 0)'
  - type: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_favorite
        state: 'on'
    elements:
      - type: state-label
        entity: sensor.mi_air_purifier_favorite_level
        title: Favorite level
        tap_action:
          action: none
        style:
          top: 64%
          left: 21%
          min-width: 40px
          min-height: 40px
          text-align: center
          font-size: 200%
          transform: 'translate(-50%, 0)'
          color: 'rgb(255, 128, 0)'
      - type: icon
        icon: 'mdi:plus'
        title: Favorite level +
        tap_action:
          action: call-service
          service: script.favorite_up
          service_data:
            entity_id: fan.mi_air_purifier_3h
            step: 2
        style:
          top: 66%
          left: 30%
          min-width: 40px
          min-height: 40px
          transform: 'translate(-50%, 0)'
          color: 'rgb(192, 192, 192)'
          color_off: 'rgb(255, 128, 0)'
      - type: icon
        icon: 'mdi:minus'
        title: Favorite level -
        tap_action:
          action: call-service
          service: script.favorite_down
          service_data:
            entity_id: fan.mi_air_purifier_3h
            step: 1
        style:
          top: 66%
          left: 16%
          min-width: 40px
          min-height: 40px
          transform: 'translate(-50%, 0)'
          color: 'rgb(192, 192, 192)'
          color_off: 'rgb(255, 128, 0)'
      - type: state-label
        entity: input_select.mi_air_purifier_coverage
        title: Coverage
        tap_action:
          action: none
        style:
          top: 74%
          left: 23%
          min-width: 40px
          min-height: 40px
          text-align: center
          font-size: 100%
          transform: 'translate(-50%, 0)'
          color: 'rgb(255, 128, 0)'
  - type: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_auto
        state: 'on'
    elements:
      - type: image
        entity: binary_sensor.mi_air_purifier_mode_auto
        title: AutoMode
        image: local/Air3HAuto.png
        style:
          top: 34%
          left: 79%
          width: 4.5%
          transform: 'translate(-50%, 0)'
  - type: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_silent
        state: 'on'
    elements:
      - type: image
        entity: binary_sensor.mi_air_purifier_mode_silent
        title: SilentMode
        image: local/Air3HSilent.png
        style:
          top: 34%
          left: 79%
          width: 4.5%
          transform: 'translate(-50%, 0)'
  - type: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_fan_1
        state: 'on'
    elements:
      - type: image
        entity: binary_sensor.mi_air_purifier_mode_fan_1
        title: FanMode
        image: local/Air3HFan1.png
        style:
          top: 34%
          left: 79%
          width: 4.5%
          transform: 'translate(-50%, 0)'
  - type: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_fan_2
        state: 'on'
    elements:
      - type: image
        entity: binary_sensor.mi_air_purifier_mode_fan_2
        title: FanMode
        image: local/Air3HFan2.png
        style:
          top: 34%
          left: 79%
          width: 4.5%
          transform: 'translate(-50%, 0)'
  - type: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_fan_3
        state: 'on'
    elements:
      - type: image
        entity: binary_sensor.mi_air_purifier_mode_fan_3
        title: FanMode
        image: local/Air3HFan3.png
        style:
          top: 34%
          left: 79%
          width: 4.5%
          transform: 'translate(-50%, 0)'
  - type: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_favorite
        state: 'on'
    elements:
      - type: image
        entity: binary_sensor.mi_air_purifier_mode_favorite
        title: FavoriteMode
        image: local/Air3HFavorite.png
        style:
          top: 34%
          left: 79%
          width: 4.5%
          transform: 'translate(-50%, 0)'

I see the issue is raised here, and the fix has already been approved and released.

I basically replaced set_speed with set_preset_mode and it worked beautifully, except for my automation related to setting favorite level based on PM2.5 value. I suppose the levels (1/14) needs to be changed into percentages.

But I am not skilled enough to figure that one out.

- id: '1234567891012'
  alias: AP02 - Air Purifier set favorite level based on PM2.5
  description: ''
  trigger:
  - minutes: /5
    platform: time_pattern
  condition:
  - condition: state
    entity_id: fan.xiaomi_miio_device
    state: 'on'
  - condition: state
    entity_id: binary_sensor.mi_air_purifier_mode_fan
    state: 'off'
  - condition: time
    after: 08:00:00
    before: '20:00:00'
  action:
  - data:
      speed: Favorite
    entity_id: fan.xiaomi_miio_device
    service: fan.set_speed
  - data:
      level: '{% if states("sensor.mi_air_purifier_air_quality_pm25") | int > 40 -%}
        10 {%- elif states("sensor.mi_air_purifier_air_quality_pm25") | int > 30 -%}
        8 {%- elif states("sensor.mi_air_purifier_air_quality_pm25") | int > 20 -%}
        6 {%- elif states("sensor.mi_air_purifier_air_quality_pm25") | int > 10 -%}
        4 {%- else -%} 1 {%- endif %}'
    entity_id: fan.xiaomi_miio_device
    service: xiaomi_miio.fan_set_favorite_level
  mode: single
2 Likes

Automation should work simply by changing fan.set_speed to fan.set_preset_mode as the level is set by a specific miio integration service: xiaomi_miio.fan_set_favorite_level. There is no other change required.

Here is my automation:


- id: '12345678910112'
  alias: AP02 - Air Purifier set favorite level based on PM2.5
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.mi_air_purifier_air_quality_pm25
  condition:
  - condition: state
    entity_id: fan.mi_air_purifier_3h
    state: 'on'
  - condition: or
    conditions:
    - condition: and
      conditions:
      - condition: numeric_state
        entity_id: sensor.mi_air_purifier_air_quality_pm25
        above: '50'
      - condition: not
        conditions:
        - condition: state
          entity_id: sensor.mi_air_purifier_favorite_level
          state: '14'
    - condition: and
      conditions:
      - condition: numeric_state
        entity_id: sensor.mi_air_purifier_air_quality_pm25
        above: '35'
        below: '51'
      - condition: not
        conditions:
        - condition: state
          entity_id: sensor.mi_air_purifier_favorite_level
          state: '12'
    - condition: and
      conditions:
      - condition: numeric_state
        entity_id: sensor.mi_air_purifier_air_quality_pm25
        above: '20'
        below: '36'
      - condition: not
        conditions:
        - condition: state
          entity_id: sensor.mi_air_purifier_favorite_level
          state: '9'
    - condition: and
      conditions:
      - condition: numeric_state
        entity_id: sensor.mi_air_purifier_air_quality_pm25
        above: '5'
        below: '21'
      - condition: not
        conditions:
        - condition: state
          entity_id: sensor.mi_air_purifier_favorite_level
          state: '6'
    - condition: and
      conditions:
      - condition: numeric_state
        entity_id: sensor.mi_air_purifier_air_quality_pm25
        below: '6'
      - condition: not
        conditions:
        - condition: state
          entity_id: sensor.mi_air_purifier_favorite_level
          state: '4'
  action:
  - service: fan.set_preset_mode
    data:
      preset_mode: Favorite
    target:
      entity_id: fan.mi_air_purifier_3h
  - data:
      level: '{% if states("sensor.mi_air_purifier_air_quality_pm25") | int > 50 -%}
        14 {%- elif states("sensor.mi_air_purifier_air_quality_pm25") | int > 35 -%}
        12 {%- elif states("sensor.mi_air_purifier_air_quality_pm25") | int > 20 -%}
        9 {%- elif states("sensor.mi_air_purifier_air_quality_pm25") | int > 5 -%}
        6 {%- else -%} 4 {%- endif %}'
    entity_id: fan.mi_air_purifier_3h
    service: xiaomi_miio.fan_set_favorite_level
  - data:
      message: Mi Air Purifier 3H - PM2.5 = {{ states('sensor.mi_air_purifier_air_quality_pm25')
        }} μg/m³ set favorite level to {{ state_attr('fan.mi_air_purifier_3h', 'favorite_level')
        }} (coverage {{ states('input_select.mi_air_purifier_coverage') }}) at {{
        states('sensor.date_time') }}
    service: notify.notify
  mode: single
1 Like

Hi, thank you very much for your work. I am trying to remove the name “Mi Air Purifier 3H” below but can’t figure out how to do it. Can anybody help me? Thanks in advance!

You have to edit the baseline purifier picture from www/local.

1 Like

Sorry, I had not noticed that the name comes in the image of the purifier… thank you! :sweat_smile:

Hi guys, quick questions, when receiving the notifications in state of the time it shows unknown, the message bit is as bellow. I tried different combinations, it just doesn’t read the states('sensor.date_time)

service: notify.notify
data:
message: ‘Mi Air Purifier 3H turn on at {{ states(’‘sensor.date_time’’) }}’

ok, got it fixed. added the time_date sensor co configuration

sensor:

  • platform: time_date
    display_options:
    • ‘time’
    • ‘date’
    • ‘date_time’
    • ‘date_time_utc’
    • ‘date_time_iso’
    • ‘time_date’
    • ‘time_utc’
    • ‘beat’