Hi, I’ve been following for a while I’m a stubborn neophyte, and by dint of reading and trying I managed to make a package and to me everything seems to work on Home Assistant 2021.3.4 if I can and if anyone is interested I can publish it.
Of course!
There continues to be the fan_set speed error but if I change it to fan.set_preset_mode the problem remains. So I left it as it was, just bundled it into a package, maybe it will be easier to put away. pkg_my_purifier_3h.yaml copy file in /config/packages
#======================#
# Mi Air Purifier 3H #
#======================#
fan:
- platform: xiaomi_miio
name: "Mi Air Purifier 3H"
host: xxx.xxx.xxx.xxx
token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
model: zhimi.airpurifier.mb3
input_select:
mi_air_purifier_mode:
name: Mode
options:
- Auto
- Silent
- Favorite
- Fan
initial: Auto
icon: mdi:animation-outline
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²
initial: 2-4 m²
icon: mdi:texture-box
input_number:
mi_air_purifier_favorite_level:
name: "Favorite level"
initial: 0
min: 0
max: 14
step: 1
icon: mdi:weather-windy
mi_air_purifier_fan_level:
name: "Fan level"
initial: 1
min: 1
max: 3
step: 1
icon: mdi:jquery
input_boolean:
mi_air_purifier_attributes:
name: Attributes
icon: mdi:pencil
switch:
- 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: "{{ is_state_attr('fan.mi_air_purifier_3h', 'child_lock', true) }}"
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: "{{ is_state_attr('fan.mi_air_purifier_3h', 'buzzer', true) }}"
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:
- platform: template
sensors:
mi_air_purifier_temp:
friendly_name: "Temperature"
value_template: "{{ state_attr('fan.mi_air_purifier_3h', 'temperature') }}"
unit_of_measurement: "°C"
device_class: "temperature"
mi_air_purifier_humidity:
friendly_name: "Humidity"
value_template: "{{ state_attr('fan.mi_air_purifier_3h', 'humidity') }}"
unit_of_measurement: "%"
device_class: "humidity"
mi_air_purifier_air_quality_pm25:
friendly_name: "Air quality (AQI) PM2.5"
value_template: "{{ state_attr('fan.mi_air_purifier_3h', 'aqi') }}"
unit_of_measurement: "μg/m³"
icon_template: "mdi:weather-fog"
mi_air_purifier_avg_air_quality_pm25:
friendly_name: "Average air quality (AvgAQI) PM2.5"
value_template: "{{ state_attr('fan.mi_air_purifier_3h', 'average_aqi') }}"
unit_of_measurement: "μg/m³"
icon_template: "mdi:weather-hazy"
mi_air_purifier_use_time:
friendly_name: "Time used"
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(', ') }}
icon_template: "mdi:heart-pulse"
mi_air_purifier_filter_used:
friendly_name: "Filter used"
value_template: "{{ state_attr('fan.mi_air_purifier_3h', 'filter_hours_used') }}"
unit_of_measurement: "hrs"
icon_template: "mdi:heart-off"
mi_air_purifier_filter_remaining:
friendly_name: "Filter remaining"
value_template: "{{ state_attr('fan.mi_air_purifier_3h', 'filter_life_remaining') }}"
unit_of_measurement: "%"
icon_template: "mdi:heart-outline"
mi_air_purifier_purify_volume:
friendly_name: "Purified volume"
value_template: "{{ state_attr('fan.mi_air_purifier_3h', 'purify_volume') }}"
unit_of_measurement: "m³"
icon_template: "mdi:warehouse"
mi_air_purifier_speed:
friendly_name: "Motor speed"
value_template: "{{ state_attr('fan.mi_air_purifier_3h', 'motor_speed') }}"
unit_of_measurement: "rpm"
icon_template: "mdi:speedometer"
mi_air_purifier_led_brightness:
friendly_name: "Led brightness"
value_template: "{{ state_attr('fan.mi_air_purifier_3h', 'led_brightness') }}"
unit_of_measurement: "lx"
icon_template: "mdi:brightness-5"
should the lovelace cards also be done?
Hi FeromonDe, your lovelace card uses the fan.set_speed, which is about to be deprecated.
Do you have any suggestions on what to exchange them with, so it’s a bit more futureproof?
fan.set_preset_mode
Ahh gotcha, forgot to change speed: auto to preset_mode: ‘auto’.
The other part is the favorite fan levels (1-2-3), to my understanding, it needs to be changed into the fan_percentage. I will try work on that. The outdated part of the code is below:
- 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.xiaomi_miio_device
speed: Fan
style:
top: 0%
left: 36.67%
transform: 'translate(-50%, -50%) scale(1.5)'
'--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.xiaomi_miio_device
level: 1
style:
top: 70%
left: 29.67%
transform: 'translate(-50%, -50%) scale(1.2, 1.2)'
'--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.xiaomi_miio_device
level: 2
style:
top: 70%
left: 36.37%
transform: 'translate(-50%, -50%) scale(1.2, 1.2)'
'--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.xiaomi_miio_device
level: 3
style:
top: 70%
left: 43.67%
transform: 'translate(-50%, -50%) scale(1.2, 1.2)'
'--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: 70%
left: 10%
min-width: 40px
min-height: 40px
text-align: center
font-size: 150%
transform: 'translate(-50%, -50%) scale(1.5)'
color: 'rgb(255, 128, 0)'
Hi to all,
starting from this morning, the Air Quality Index (AQI) PM2.5 (μg/m³) give me following error: entity is not numeric.
I tried to reset Purifier and generate another token, but I have same issue.
Do you have this issue?
Thanks
Yes,me too. And the related graph is changed from numeric to non-numeric:
For me,AQI doesn’t provide a value if aqi=1 is measured but report unknown. I think it’s a bug resolved in next release.
Don’t know if the 2 problems are related.
Maybe yes. I tried to increase pm2.5 and started to display the numbers, when returned to 1, again same issue.
It’s a known issue, it should be fixed soon
no matter what i do i cannot get the dots icon working. Any idea ?
Sry for the late reply! Did you got it working?
So there’s a discussion happening over at github about the fan speed percentage mapping to either fan speed presets (I/II/III) or to favorite rpm (300-1200).
My vote is for favorite rpm since it allows for much finer control. Instead of just 3 speeds (33, 66 and 100%), you get to use the entire 0-100% fan speed range.
Rationale for 3 speed fan speed is that you get accurate icons on the actual device (though, tiny and hard to see). If using favorite rpm you only see heart icon instead of 1/2/3 dashes in that tiny circle.
If you guys want the finer control of speed and also consistent display of fan speed in lovelace UI and further integrations like Homekit, vote my comment up on GitHub.
you can share your customization?
for me it controlls on and off and thats it my device is zhimi.airpurifier.ma4 change host and API it reads all informations like humidity temperature just doesnt cotroll fan speed or mode, anyone had similar issue ?
Unable to find referenced entities fan.mi_air_purifier_3h
Loading Xiaomi Miio Fan via platform setup is deprecated. Please remove it from your configuration
Logger: homeassistant.config_entries
Source: components/xiaomi_miio/__init__.py:180
First occurred: 13:11:12 (1 occurrences)
Last logged: 13:11:12
Error unloading entry Mi Air Purifier 3H for xiaomi_miio
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 432, in async_unload
result = await component.async_unload_entry(hass, self) # type: ignore
File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/__init__.py", line 180, in async_unload_entry
hass.data[DOMAIN].pop(config_entry.entry_id)
KeyError: '7e1b21e51409c8bdefb488b6103faa47'
I have the same problem as you. I removed Integrations, restarted HA. it works again.
thanks to you I have been able to make a card
I share with you to be able to debug it.
Many thanks for your work
type: picture-elements
title: Purificador de aire
image: local/purificador_aire/2/purificador1200px.png
elements:
- type: conditional
conditions:
- entity: sensor.purificador_aire_pm25_severity
state: clean
- entity: binary_sensor.purificador_aire_mode_off
state: 'off'
elements:
- type: image
entity: sensor.purificador_aire_pm25_severity
title: PM2.5 severity level
tap_action:
action: more-info
state_image:
clean: local/purificador_aire/2/clean.png
style:
top: 53%
left: 49%
min-width: 58%
- type: conditional
conditions:
- entity: sensor.purificador_aire_pm25_severity
state: polluted
- entity: binary_sensor.purificador_aire_mode_off
state: 'off'
elements:
- type: image
entity: sensor.purificador_aire_pm25_severity
title: PM2.5 severity level
tap_action:
action: more-info
state_image:
polluted: local/purificador_aire/2/polluted.png
style:
top: 53%
left: 49%
min-width: 58%
- type: conditional
conditions:
- entity: sensor.purificador_aire_pm25_severity
state: critical
- entity: binary_sensor.purificador_aire_mode_off
state: 'off'
elements:
- type: image
entity: sensor.purificador_aire_pm25_severity
title: PM2.5 severity level
tap_action:
action: more-info
state_image:
critical: local/purificador_aire/2/critical.png
style:
top: 53%
left: 49%
min-width: 58%
- type: state-icon
entity: binary_sensor.purificador_aire_mode_off
title: 'Off'
icon: mdi:power-standby
tap_action:
action: call-service
service: fan.turn_off
service_data:
entity_id: fan.purificador_aire
style:
top: 20%
left: 20%
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.purificador_aire
title: More Info
icon: mdi:dots-vertical
tap_action:
action: more-info
style:
top: 20%
left: 80%
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.purificador_aire_mode_off
state: 'off'
elements:
- type: state-label
entity: sensor.purificador_aire_air_quality_pm25
title: PM2.5
tap_action:
action: more-info
style:
top: 30%
left: 50%
min-width: 40px
min-height: 40px
text-align: center
font-size: 330%
transform: translate(-50%, 0)
color: rgb(255,255,255)
- type: state-label
entity: sensor.purificador_aire_temp
title: Temperature
tap_action:
action: more-info
style:
top: 40%
left: 31%
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.purificador_aire_humidity
title: Humidity
tap_action:
action: more-info
style:
top: 40%
left: 43%
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.purificador_aire_led
title: Display
tap_action:
action: toggle
style:
top: 39%
left: 69%
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.purificador_aire_buzzer
title: Buzzer
tap_action:
action: toggle
style:
top: 39%
left: 56%
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.purificador_aire_child_lock
title: Child lock
tap_action:
action: toggle
style:
top: 31%
left: 34%
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.purificador_aire_filter_remaining
title: Filter remaining
tap_action:
action: more-info
style:
top: 36%
left: 65%
min-width: 40px
min-height: 40px
text-align: center
font-size: 80%
color: rgb(128,128,128)
- type: conditional
conditions:
- entity: binary_sensor.purificador_aire_mode_off
state: 'on'
elements:
- type: state-label
entity: sensor.purificador_aire_air_quality_pm25
title: PM2.5
tap_action:
action: more-info
style:
top: 30%
left: 50%
min-width: 40px
min-height: 40px
text-align: center
font-size: 400%
transform: translate(-50%, 0)
color: rgb(128, 128, 128)
- type: state-label
entity: sensor.purificador_aire_temp
title: Temperature
tap_action:
action: more-info
style:
top: 40%
left: 31%
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.purificador_aire_humidity
title: Humidity
tap_action:
action: more-info
style:
top: 40%
left: 43%
min-width: 40px
min-height: 40px
text-align: center
font-size: 75%
transform: translate(-50%, 0)
color: rgb(128, 128, 128)
- type: state-icon
entity: binary_sensor.purificador_aire_mode_auto
title: Auto
icon: mdi:autorenew
tap_action:
action: call-service
service: fan.set_speed
service_data:
entity_id: fan.purificador_aire
speed: Auto
style:
top: 48%
left: 30%
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.purificador_aire_mode_silent
title: Silent
icon: mdi:power-sleep
tap_action:
action: call-service
service: fan.set_speed
service_data:
entity_id: fan.purificador_aire
speed: Silent
style:
top: 48%
left: 43%
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.purificador_aire_mode_fan
title: Fan
icon: mdi:fan
tap_action:
action: call-service
service: fan.set_speed
service_data:
entity_id: fan.purificador_aire
speed: Fan
style:
top: 48%
left: 56%
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.purificador_aire_mode_favorite
title: Favorite
icon: mdi:heart
tap_action:
action: call-service
service: fan.set_speed
service_data:
entity_id: fan.purificador_aire
speed: Favorite
style:
top: 48%
left: 69%
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.purificador_aire_mode_fan
state: 'on'
elements:
- type: state-icon
entity: binary_sensor.purificador_aire_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.purificador_aire
level: 1
style:
top: 58%
left: 36%
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.purificador_aire_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.purificador_aire
level: 2
style:
top: 58%
left: 49%
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.purificador_aire_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.purificador_aire
level: 3
style:
top: 58%
left: 63%
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.purificador_aire_mode_favorite
state: 'on'
elements:
- type: state-label
entity: sensor.purificador_aire_favorite_level
title: Favorite level
tap_action:
action: none
style:
top: 59%
left: 42%
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.purificador_aire_favorite_up
service_data:
entity_id: fan.purificador_aire
step: 2
style:
top: 60%
left: 52%
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.purificador_aire_favorite_down
service_data:
entity_id: fan.purificador_aire
step: 1
style:
top: 60%
left: 35%
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.purificador_aire_coverage
title: Coverage
tap_action:
action: none
style:
top: 59%
left: 66%
min-width: 40px
min-height: 40px
text-align: center
font-size: 100%
transform: translate(-50%, 0)
color: rgb(255, 128, 0)