Xiaomi Air Puriffier "zhimi_airpurifier_mb4" 3C Lovelace Card

Hello. I modified a bit this post:
https://community.home-assistant.io/t/lovelace-xiaomi-mi-air-purifier-3h-card/192100

And created card and settings for my purifier. I have no idea why some 3C optios not working for me but:
image

image

configuration.yaml


#======================#
#  Mi Air Purifier 3H  #
#======================#
fan:
  - platform: xiaomi_miio
    name: "Mi Air Purifier 3H"
    host: !secret mi_air_host
    token: !secret mi_air_token
    model: fan.zhimi_airpurifier_mb4
    input_number:
  # Xiaomi Air Purifier 2S
        xiaomi_airpurifier_favorite_level:
        name: "Favorite level"
        initial: 0
        min: 0
        max: 14
        step: 1
        icon: "mdi:weather-windy"
input_select:
    mi_air_purifier_coverage:
      name: Coverage
      options:
        - 2-4 m²
        - 5-9 m²
        - 7-12 m²
        - 12-22 m²
        - 14-24 m²
        - 14-25 m²
        - 16-27 m²
        - 17-30 m²
        - 18-32 m²
        - 19-33 m²
        - 20-34 m²
        - 22-38 m²
        - 23-40 m²
        - 26-45 m²
        - 28-49 m²
      icon: mdi:texture-box

switch:

  #======================#
  #  Mi Air Purifier 3H  #
  #======================#
  - platform: template
    switches:
      mi_air_purifier_led:
        friendly_name: "Display"
        value_template: "{{ is_state_attr('fan.mi_air_purifier_3h', 'led', true) }}"
        turn_on:
          service: xiaomi_miio.fan_set_led_on
          data:
            entity_id: fan.mi_air_purifier_3h
        turn_off:
          service: xiaomi_miio.fan_set_led_off
          data:
            entity_id: fan.mi_air_purifier_3h
        icon_template: mdi:lightbulb-outline
      mi_air_purifier_child_lock:
        friendly_name: "Child lock"
        value_template: "{{ states('switch.zhimi_airpurifier_mb4_child_lock') }}"
        turn_on:
          service: xiaomi_miio.fan_set_child_lock_on
          data:
            entity_id: fan.mi_air_purifier_3h
        turn_off:
          service: xiaomi_miio.fan_set_child_lock_off
          data:
            entity_id: fan.mi_air_purifier_3h
        icon_template: "mdi:lock-outline"
      mi_air_purifier_buzzer:
        friendly_name: "Buzzer"
        value_template: "{{ states('switch.zhimi_airpurifier_mb4_buzzer') }}"
        turn_on:
          service: xiaomi_miio.fan_set_buzzer_on
          data:
            entity_id: fan.mi_air_purifier_3h
        turn_off:
          service: xiaomi_miio.fan_set_buzzer_off
          data:
            entity_id: fan.mi_air_purifier_3h
        icon_template: "mdi:volume-high"

sensor:

  #======================#
  #  Mi Air Purifier 3H  #
  #======================#
  - platform: template
    sensors:
      mi_air_purifier_air_quality_pm25:
        friendly_name: "Air Quality Index (AQI) PM2.5 (μg/m³)"
#        value_template: "{{ state_attr('sensor.zhimi_airpurifier_mb4_pm2_5') }}"
        value_template: >-
         {{ states('sensor.zhimi_airpurifier_mb4_pm2_5') }}
        unit_of_measurement: " "
#        unit_of_measurement: "μg/m³"
        icon_template: "mdi:air-purifier"
      mi_air_purifier_pm25_severity:
        friendly_name: "PM2.5 severity level"
        value_template: >-
           {% if  states('sensor.zhimi_airpurifier_mb4_pm2_5') | int > 400 %}
                {{ 'critical' }}              
            {% elif states('sensor.zhimi_airpurifier_mb4_pm2_5') | int > 200 %}
                {{ 'polluted' }}              
              {% else %}
                {{ 'clean' }}      
              {% endif %}

        icon_template: "mdi:air-filter"
      mi_air_purifier_use_time:
        friendly_name: "Time used"
#        value_template: "{{ state_attr('fan.mi_air_purifier_3h', 'use_time') }}"
        value_template: >
           " {% macro phrase(value, name) %}
            {%- set value = value | int %}
            {%- set end = 's' if value > 1 else '' %}
            {{- '{} {}{}'.format(value, name, end) if value | int > 0 else '' }}
            {%- endmacro %}
            
            {% set weeks = (state_attr('fan.mi_air_purifier_3h', 'use_time') | int / 604800) | int %}
            {% set days = ((state_attr('fan.mi_air_purifier_3h', 'use_time') | int - (weeks * 604800)) / 86400) | int %}
            {% set hours = ((state_attr('fan.mi_air_purifier_3h', 'use_time') | int - (weeks * 604800) - (days * 86400)) / 3600) | int %}
            {% set minutes = ((state_attr('fan.mi_air_purifier_3h', 'use_time') | int - (weeks * 604800) - (days * 86400) - (hours * 3600)) / 60) | int %}
            {% set seconds = (state_attr('fan.mi_air_purifier_3h', 'use_time') | int - (weeks * 604800) - (days * 86400) - (hours * 3600) - (minutes*60)) | int %}
            {{ [ phrase(weeks, 'week'), phrase(days, 'day'), phrase(hours, 'hr'), phrase(minutes, 'min'), phrase(seconds, 'sec') ] | select('!=','') | list | join(', ') }}"
#        unit_of_measurement: "sec"
        icon_template: "mdi:heart-pulse"
      mi_air_purifier_filter_used:
        friendly_name: "Filter used"
        value_template: "{{ states('sensor.zhimi_airpurifier_mb4_filter_use') }}"
        unit_of_measurement: "hrs"
        icon_template: "mdi:heart-off"
      mi_air_purifier_filter_remaining:
        friendly_name: "Filter remaining"
        value_template: "{{ states('sensor.zhimi_airpurifier_mb4_filter_life_remaining') }}"
        unit_of_measurement: "%"
        icon_template: "mdi:heart-outline"
      mi_air_purifier_purify_volume:
        friendly_name: "Purified volume"
        value_template: "{{ state_attr('switch.zhimi_airpurifier_mb4_buzzer') }}"
        unit_of_measurement: "m³"
        icon_template: "mdi:warehouse"
      mi_air_purifier_speed:
        friendly_name: "Motor speed"
        value_template: "{{ states('sensor.zhimi_airpurifier_mb4_motor_speed') }}"
        unit_of_measurement: "rpm"
        icon_template: "mdi:speedometer"
      mi_air_purifier_led_brightness:
        friendly_name: "Led brightness"
        value_template: "{{ states('number.zhimi_airpurifier_mb4_led_brightness') }}"
        unit_of_measurement: "lx"
        icon_template: "mdi:brightness-5"

binary_sensor:

#======================#
#  Mi Air Purifier 3H  #
#======================#
  - platform: template
    sensors:
      mi_air_purifier_mode_off:
        friendly_name: "Purifier Off"
        value_template: "{{ is_state('fan.zhimi_airpurifier_mb4','off') }}"
      mi_air_purifier_mode_auto:
        friendly_name: "Purifier Auto mode"
        value_template: "{{ is_state_attr('fan.zhimi_airpurifier_mb4', 'preset_mode', 'Auto') and is_state('fan.zhimi_airpurifier_mb4', 'on') }}"
      mi_air_purifier_mode_silent:
        friendly_name: "Purifier Silent mode"
        value_template: "{{ is_state_attr('fan.zhimi_airpurifier_mb4', 'preset_mode', 'Silent') and is_state('fan.zhimi_airpurifier_mb4', 'on') }}"
      mi_air_purifier_mode_favorite:
        friendly_name: "Purifier Favorite mode"
        value_template: "{{ is_state_attr('fan.zhimi_airpurifier_mb4', 'preset_mode', 'Favorite') and is_state('fan.zhimi_airpurifier_mb4', 'on') }}"

lovelace.yaml / raw edit of your screen:

type: picture-elements
image: local/mi_air_purifier_3h.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/mi_air_purifier_3h_clean.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/mi_air_purifier_3h_polluted.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/mi_air_purifier_3h_critical.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.toggle
      service_data:
        entity_id: fan.zhimi_airpurifier_mb4
    style:
      top: 1%
      left: 6%
      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.zhimi_airpurifier_mb4
    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: 350%
          transform: translate(-50%, 0)
          color: rgb(255,255,255)
      - type: state-icon
        entity: sensor.mi_air_purifier_led_brightness
        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: custom:slider-entity-row
        entity: number.zhimi_airpurifier_mb4_led_brightness
        name: ' '
        style:
          left: 10%
          top: 21%
          width: 50%
      - type: state-icon
        entity: switch.zhimi_airpurifier_mb4_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.zhimi_airpurifier_mb4_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.zhimi_airpurifier_mb4_filter_life_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: 'on'
    elements:
      - type: state-label
        entity: sensor.
        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(128, 128, 128)
  - type: state-icon
    entity: binary_sensor.mi_air_purifier_mode_auto
    title: Auto
    icon: mdi:autorenew
    tap_action:
      action: call-service
      service: fan.set_preset_mode
      service_data:
        entity_id: fan.zhimi_airpurifier_mb4
        preset_mode: 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
    attribute: preset_mode
    title: Silent
    icon: mdi:power-sleep
    tap_action:
      action: call-service
      service: fan.set_preset_mode
      service_data:
        entity_id: fan.zhimi_airpurifier_mb4
        preset_mode: 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_favorite
    title: Favorite
    icon: mdi:heart
    tap_action:
      action: call-service
      service: fan.set_preset_mode
      service_data:
        entity_id: fan.zhimi_airpurifier_mb4
        preset_mode: Favorite
    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: conditional
    conditions:
      - entity: binary_sensor.mi_air_purifier_mode_fan
        state: 'on'
    elements:
      - type: state-icon
        entity: binary_sensor.mi_air_purifier_mode_fan_3
        title: Fan level 3
        icon: mdi:fan-speed-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: custom:slider-entity-row
        entity: number.zhimi_airpurifier_mb4_favorite_motor_speed_new
        name: ' '
        style:
          left: 19%
          top: 70%

No scripts and no automations.

Images as always:

mi_air_purifier_3h_polluted
mi_air_purifier_3h_critical
mi_air_purifier_3h_clean

1 Like