Hi guys, here is the update. By the way, I noticed the integration is now updating the values quite slow. Sometimes it took half a minute after it starts to update the values. Also for the 3 Fun mode buttons.
In paralel I an using MIOT integration from the HACS that seems to be more responsive and also didn’t noticed the “unavailable” periods from MIIO.
configuration.yaml (I am still keeping the Coverage relation to Favourite level but if you are not interested you could comment it. Also the last state-label on the card.
#======================#
# Mi Air Purifier 3H #
#======================#
fan:
- platform: xiaomi_miio
name: "Mi Air Purifier 3H"
host: !secret mi_air_host
token: !secret mi_air_token
model: zhimi.airpurifier.mb3
input_select:
mi_air_purifier_3h_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
#===========#
# Sensors #
#===========#
sensor:
#======================#
# Mi Air Purifier 3H #
#======================#
- platform: template
sensors:
mi_air_purifier_3h_pm2_5_severity:
friendly_name: "PM2.5 severity level"
value_template: >-
{% if states('sensor.mi_air_purifier_3h_pm2_5') | int > 30 %}
{{ 'critical' }}
{% elif states('sensor.mi_air_purifier_3h_pm2_5') | int > 15 %}
{{ 'polluted' }}
{% else %}
{{ 'clean' }}
{% endif %}
icon_template: "mdi:air-filter"
mi_air_purifier_3h_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"
#==================#
# Binary Sensors #
#==================#
binary_sensor:
#======================#
# Mi Air Purifier 3H #
#======================#
- platform: template
sensors:
mi_air_purifier_3h_mode_auto:
friendly_name: "Purifier Auto mode"
value_template: "{{ is_state_attr('fan.mi_air_purifier_3h', 'preset_mode', 'Auto') and is_state('fan.mi_air_purifier_3h', 'on') }}"
mi_air_purifier_3h_mode_silent:
friendly_name: "Purifier Silent mode"
value_template: "{{ is_state_attr('fan.mi_air_purifier_3h', 'preset_mode', 'Silent') and is_state('fan.mi_air_purifier_3h', 'on') }}"
mi_air_purifier_3h_mode_favorite:
friendly_name: "Purifier Favorite mode"
value_template: "{{ is_state_attr('fan.mi_air_purifier_3h', 'preset_mode', 'Favorite') and is_state('fan.mi_air_purifier_3h', 'on') }}"
mi_air_purifier_3h_mode_fan:
friendly_name: "Purifier Fan mode"
value_template: "{{ is_state_attr('fan.mi_air_purifier_3h', 'preset_mode', 'Fan') and is_state('fan.mi_air_purifier_3h', 'on') }}"
mi_air_purifier_3h_mode_fan_1:
friendly_name: "Purifier Fan mode 1"
value_template: "{{ is_state_attr('fan.mi_air_purifier_3h', 'preset_mode', 'Fan') and is_state('number.mi_air_purifier_3h_fan_level', '1') and is_state('fan.mi_air_purifier_3h', 'on') }}"
mi_air_purifier_3h_mode_fan_2:
friendly_name: "Purifier Fan mode 2"
value_template: "{{ is_state_attr('fan.mi_air_purifier_3h', 'preset_mode', 'Fan') and is_state('number.mi_air_purifier_3h_fan_level', '2') and is_state('fan.mi_air_purifier_3h', 'on') }}"
mi_air_purifier_3h_mode_fan_3:
friendly_name: "Purifier Fan mode 3"
value_template: "{{ is_state_attr('fan.mi_air_purifier_3h', 'preset_mode', 'Fan') and is_state('number.mi_air_purifier_3h_fan_level', '3') and is_state('fan.mi_air_purifier_3h', 'on') }}"
card (lovelace.yaml)
type: picture-elements
image: local/mi_air_purifier_3h.png
elements:
- type: conditional
conditions:
- entity: sensor.mi_air_purifier_3h_pm2_5_severity
state: clean
- entity: fan.mi_air_purifier_3h
state: 'on'
elements:
- type: image
entity: sensor.mi_air_purifier_3h_pm2_5_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_3h_pm2_5_severity
state: polluted
- entity: fan.mi_air_purifier_3h
state: 'on'
elements:
- type: image
entity: sensor.mi_air_purifier_3h_pm2_5_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_3h_pm2_5_severity
state: critical
- entity: fan.mi_air_purifier_3h
state: 'on'
elements:
- type: image
entity: sensor.mi_air_purifier_3h_pm2_5_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: 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: 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.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: fan.mi_air_purifier_3h
state: 'off'
elements:
- type: state-label
entity: sensor.mi_air_purifier_3h_pm2_5
title: PM2.5
tap_action:
action: more-info
style:
top: 21%
left: 68.5%
min-width: 40px
min-height: 40px
text-align: center
font-size: 150%
transform: translate(-50%, 0)
color: rgb(128, 128, 128)
- type: state-label
entity: sensor.mi_air_purifier_3h_temperature
title: Temperature
tap_action:
action: more-info
style:
top: 32.5%
left: 64%
min-width: 40px
min-height: 40px
text-align: center
font-size: 75%
transform: translate(-50%, 0)
color: rgb(128, 128, 128)
- type: state-label
entity: sensor.mi_air_purifier_3h_humidity
title: Humidity
tap_action:
action: more-info
style:
top: 32.5%
left: 71%
min-width: 40px
min-height: 40px
text-align: center
font-size: 75%
transform: translate(-50%, 0)
color: rgb(128, 128, 128)
- type: conditional
conditions:
- entity: fan.mi_air_purifier_3h
state: 'on'
elements:
- type: state-label
entity: sensor.mi_air_purifier_3h_pm2_5
title: PM2.5
tap_action:
action: more-info
style:
top: 21%
left: 68.5%
min-width: 40px
min-height: 40px
text-align: center
font-size: 150%
transform: translate(-50%, 0)
color: rgb(255,255,255)
- type: state-label
entity: sensor.mi_air_purifier_3h_temperature
title: Temperature
tap_action:
action: more-info
style:
top: 32.5%
left: 64%
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_3h_humidity
title: Humidity
tap_action:
action: more-info
style:
top: 32.5%
left: 71%
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_3h_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_3h_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_3h_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: state-label
entity: sensor.mi_air_purifier_3h_filter_use
title: Filter Use
tap_action:
action: more-info
style:
top: 15%
left: 91%
min-width: 40px
min-height: 40px
text-align: center
font-size: 80%
color: rgb(128,128,128)
- type: state-label
entity: sensor.mi_air_purifier_3h_motor_speed
title: Motor Speed
tap_action:
action: more-info
style:
top: 60%
left: 90%
min-width: 40px
min-height: 40px
text-align: center
font-size: 80%
color: rgb(128,128,128)
- type: conditional
conditions:
- entity: select.mi_air_purifier_3h_led_brightness
state: bright
elements:
- type: state-icon
entity: select.mi_air_purifier_3h_led_brightness
title: Led Brightness
icon: mdi:brightness-7
tap_action:
action: call-service
service: script.led_brightness
style:
top: 15%
left: 36%
transform: translate(-50%, 0)
'--paper-item-icon-color': rgb(255, 128, 0)
'--paper-item-icon-active-color': rgb(128, 128, 128)
- type: conditional
conditions:
- entity: select.mi_air_purifier_3h_led_brightness
state: dim
elements:
- type: state-icon
entity: select.mi_air_purifier_3h_led_brightness
title: Led Brightness
tap_action:
action: call-service
service: script.led_brightness
style:
top: 15%
left: 36%
transform: translate(-50%, 0)
'--paper-item-icon-color': rgb(255, 128, 0)
'--paper-item-icon-active-color': rgb(128, 128, 128)
- type: conditional
conditions:
- entity: select.mi_air_purifier_3h_led_brightness
state: 'off'
elements:
- type: state-icon
entity: select.mi_air_purifier_3h_led_brightness
title: Led Brightness
icon: mdi:brightness-5
tap_action:
action: call-service
service: script.led_brightness
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: binary_sensor.mi_air_purifier_3h_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_3h_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_3h_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_3h_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_3h_mode_fan
state: 'on'
elements:
- type: state-icon
entity: binary_sensor.mi_air_purifier_3h_mode_fan_1
title: Fan level 1
icon: mdi:fan-speed-1
tap_action:
action: call-service
service: number.set_value
service_data:
entity_id: number.mi_air_purifier_3h_fan_level
value: 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_3h_mode_fan_2
title: Fan level 2
icon: mdi:fan-speed-2
tap_action:
action: call-service
service: number.set_value
service_data:
entity_id: number.mi_air_purifier_3h_fan_level
value: 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_3h_mode_fan_3
title: Fan level 3
icon: mdi:fan-speed-3
tap_action:
action: call-service
service: number.set_value
service_data:
entity_id: number.mi_air_purifier_3h_fan_level
value: 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_3h_mode_favorite
state: 'on'
elements:
- type: state-label
entity: number.mi_air_purifier_3h_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
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
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_3h_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)
scripts.yaml
favorite_up:
sequence:
- service: number.set_value
data:
value: '{% if (states(''number.mi_air_purifier_3h_favorite_level'') | int +
2 ) < 14 -%} {{ (states(''number.mi_air_purifier_3h_favorite_level'') | int
+ 2 )}} {%- else -%} {{ 14 }} {%- endif %}'
target:
entity_id: number.mi_air_purifier_3h_favorite_level
mode: single
favorite_down:
sequence:
- service: number.set_value
data:
value: '{% if (states(''number.mi_air_purifier_3h_favorite_level'') | int -
1 ) > 0 -%} {{ (states(''number.mi_air_purifier_3h_favorite_level'') | int
- 1 ) }} {%- else -%} {{ 0 }} {%- endif %}'
target:
entity_id: number.mi_air_purifier_3h_favorite_level
mode: single
led_brightness:
sequence:
- service: select.select_option
data:
option: '{% if states(''select.mi_air_purifier_3h_led_brightness'') == ''bright'' -%}
{{ ''dim'' }} {% elif states(''select.mi_air_purifier_3h_led_brightness'')
== ''dim'' -%} {{ ''off'' }} {%- else -%} {{ ''bright'' }} {%- endif %}'
target:
entity_id: select.mi_air_purifier_3h_led_brightness
mode: single
alias: led_brightness
automations.yaml
- id: '1234567891011'
alias: AP01 - Air Purifier turn on
description: ''
trigger:
- above: '15'
entity_id: sensor.mi_air_purifier_3h_pm2_5
for: 0:01:00
platform: numeric_state
condition:
- condition: state
entity_id: fan.mi_air_purifier_3h
state: 'off'
action:
- data:
preset_mode: Auto
service: fan.turn_on
target:
entity_id: fan.mi_air_purifier_3h
- service: notify.notify
data:
message: Mi Air Purifier 3H turn on at {{ states('sensor.date_time') }}
mode: single
- id: '1234567891012'
alias: AP02 - Air Purifier set favorite level based on PM2.5
description: ''
trigger:
- platform: state
entity_id: sensor.mi_air_purifier_3h_pm2_5
condition:
- condition: state
entity_id: fan.mi_air_purifier_3h
state: 'on'
- condition: not
conditions:
- condition: state
entity_id: fan.mi_air_purifier_3h
state: Favorite
attribute: preset_mode
- condition: or
conditions:
- condition: and
conditions:
- condition: numeric_state
entity_id: sensor.mi_air_purifier_3h_pm2_5
above: '50'
- condition: not
conditions:
- condition: state
entity_id: number.mi_air_purifier_3h_favorite_level
state: '14'
- condition: and
conditions:
- condition: numeric_state
entity_id: sensor.mi_air_purifier_3h_pm2_5
above: '35'
below: '51'
- condition: not
conditions:
- condition: state
entity_id: number.mi_air_purifier_3h_favorite_level
state: '12'
- condition: and
conditions:
- condition: numeric_state
entity_id: sensor.mi_air_purifier_3h_pm2_5
above: '20'
below: '36'
- condition: not
conditions:
- condition: state
entity_id: number.mi_air_purifier_3h_favorite_level
state: '9'
- condition: and
conditions:
- condition: numeric_state
entity_id: sensor.mi_air_purifier_3h_pm2_5
above: '5'
below: '21'
- condition: not
conditions:
- condition: state
entity_id: number.mi_air_purifier_3h_favorite_level
state: '6'
- condition: and
conditions:
- condition: numeric_state
entity_id: sensor.mi_air_purifier_3h_pm2_5
below: '6'
- condition: not
conditions:
- condition: state
entity_id: number.mi_air_purifier_3h_favorite_level
state: '4'
action:
- service: fan.set_preset_mode
data:
preset_mode: Favorite
target:
entity_id: fan.mi_air_purifier_3h
- data:
value: '{% if states("sensor.mi_air_purifier_3h_pm2_5") | int > 50 -%} 14 {%-
elif states("sensor.mi_air_purifier_3h_pm2_5") | int > 35 -%} 12 {%- elif
states("sensor.mi_air_purifier_3h_pm2_5") | int > 20 -%} 9 {%- elif states("sensor.mi_air_purifier_3h_pm2_5")
| int > 5 -%} 6 {%- else -%} 4 {%- endif %}'
entity_id: number.mi_air_purifier_3h_favorite_level
service: number.set_value
- data:
message: Mi Air Purifier 3H - PM2.5 = {{ states('sensor.mi_air_purifier_3h_pm2_5')
}} μg/m³ set favorite level to {{ states('number.mi_air_purifier_3h_favorite_level')
}} (coverage {{ states('input_select.mi_air_purifier_3h_coverage') }}) at
{{ states('sensor.date_time') }}
service: notify.notify
mode: single
- id: '1234567891013'
alias: AP03 - Air Purifier turn off
description: ''
trigger:
- entity_id: sensor.mi_air_purifier_3h_pm2_5
for: 0:01:00
platform: numeric_state
below: '5'
condition:
- condition: state
entity_id: fan.mi_air_purifier_3h
state: 'on'
action:
- data: {}
entity_id: fan.mi_air_purifier_3h
service: fan.turn_off
- service: notify.notify
data:
message: Mi Air Purifier 3H turn off at {{ states('sensor.date_time') }}
mode: single
- id: '1234567891014'
alias: AP04 - Air Purifier favorite level to coverage
description: ''
trigger:
- platform: state
entity_id: number.mi_air_purifier_3h_favorite_level
condition: []
action:
- service: input_select.set_options
entity_id: input_select.mi_air_purifier_3h_coverage
data:
options: '{% if states("number.mi_air_purifier_3h_favorite_level") | int ==
0 -%} 2-4 m² {%- elif states("number.mi_air_purifier_3h_favorite_level") |
int == 1 -%} 5-9 m² {%- elif states("number.mi_air_purifier_3h_favorite_level")
| int == 2 -%} 7-12 m² {%- elif states("number.mi_air_purifier_3h_favorite_level")
| int == 3 -%} 12-22 m² {%- elif states("number.mi_air_purifier_3h_favorite_level")
| int == 4 -%} 14-24 m² {%- elif states("number.mi_air_purifier_3h_favorite_level")
| int == 5 -%} 14-25 m² {%- elif states("number.mi_air_purifier_3h_favorite_level")
| int == 6 -%} 16-27 m² {%- elif states("number.mi_air_purifier_3h_favorite_level")
| int == 7 -%} 17-30 m² {%- elif states("number.mi_air_purifier_3h_favorite_level")
| int == 8 -%} 18-32 m² {%- elif states("number.mi_air_purifier_3h_favorite_level")
| int == 9 -%} 19-33 m² {%- elif states("number.mi_air_purifier_3h_favorite_level")
| int == 10 -%} 20-34 m² {%- elif states("number.mi_air_purifier_3h_favorite_level")
| int == 11 -%} 22-38 m² {%- elif states("number.mi_air_purifier_3h_favorite_level")
| int == 12 -%} 23-40 m² {%- elif states("number.mi_air_purifier_3h_favorite_level")
| int == 13 -%} 26-45 m² {%- elif states("number.mi_air_purifier_3h_favorite_level")
| int == 14 -%} 28-49 m² {%- else -%} {%- endif %}'
mode: single