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)
I wanted to post my latest rendition as well, I am as always going for a bit simpler look, that fits with the rest of my dashboard. And I am trying to keep out the things I don’t actually use.
One idea, is to remove the filter level, and just somehow let Amazon auto-order a new filter for me.
I keep it in auto-mode, with custom defined values of when it starts picking up the fan. But if my windows or balcony door opens, it shuts off. And at night, it goes to night mode.
Fan mode is kept in there, because my wife sometimes like to manually toggle the intensity, but I feel like she is using it less and less, and trust the auto-mode more, which is a huge success.
Here is the lovelace code:
type: custom:stack-in-card
cards:
- type: vertical-stack
cards:
- type: picture-elements
image: local/AP-Card-Background2.png
title: Bedroom Air Purifier
elements:
- type: state-label
prefix: 'Filter Left '
entity: sensor.mi_air_purifier_filter_remaining
style:
top: 90%
left: 85%
- 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.bedroom_purifier
style:
top: 0%
left: 90%
min-width: 40px
min-height: 40px
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: 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.bedroom_purifier
preset_mode: Auto
style:
top: 0%
left: 10%
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: state-icon
entity: binary_sensor.mi_air_purifier_mode_silent
title: Silent
icon: mdi:power-sleep
tap_action:
action: call-service
service: fan.set_preset_mode
service_data:
entity_id: fan.bedroom_purifier
preset_mode: Silent
style:
top: 0%
left: 63.34%
transform: translate(-50%, -50%) scale(1.5)
'--paper-item-icon-color': rgb(192, 192, 192)
'--paper-item-icon-active-color': rgb(255, 128, 0)
'--iron-icon-height': 120px
'--iron-icon-width': 120px
- 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.bedroom_purifier
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.bedroom_purifier
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.bedroom_purifier
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.bedroom_purifier
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)
- type: custom:mini-graph-card
entities:
- sensor.mi_air_purifier_air_quality_pm25
points_per_hour: 5
animate: true
show:
icon: false
name: false
state: true
Be careful everyone, the integration has breaking changes coming up in the next release in September. All the sensors and switches will show up at their own entity. Yeah, finally!
I guess we could already prepare now, by changing from Favorite Mode to fan.set_percentage? I have no idea if the below will work, but maybe someone else does?
Going from:
deleted
Edit: I fixed it, and it now looks like this, which works!
I do got some conditions in there, that only let’s the auto-mode run if the purifier is in Favorite mode, if it’s between 8 AM and 8 PM, and if my balcony door is closed.
- id: '1234567891012'
alias: AP03 - Air Purifier set favorite level based on PM2.5
description: ''
trigger:
- platform: time_pattern
minutes: /5
condition:
- condition: state
entity_id: fan.bedroom_purifier
state: Favorite
attribute: preset_mode
- condition: state
entity_id: fan.bedroom_purifier
state: 'on'
- condition: time
after: 08:00
before: '20:00'
- type: is_not_open
condition: device
device_id: caab6403190bf76661e96c600a77dc08
entity_id: binary_sensor.bedroom_door_sensor
domain: binary_sensor
action:
- service: fan.set_preset_mode
target:
entity_id: fan.bedroom_purifier
data:
preset_mode: Favorite
- service: number.set_value
entity_id: number.bedroom_purifier_favorite_level
data_template:
value: "{% if states('sensor.bedroomair_purifier_pm2_5') | int > 140 %}\n 14\n\
{% elif states('sensor.bedroomair_purifier_pm2_5') | int > 120 %}\n 12\n\
{% elif states('sensor.bedroomair_purifier_pm2_5') | int > 100 %}\n 10\n\
{% elif states('sensor.bedroomair_purifier_pm2_5') | int > 80 %}\n 8\n{%\
\ elif states('sensor.bedroomair_purifier_pm2_5') | int > 60 %}\n 6\n{% elif\
\ states('sensor.bedroomair_purifier_pm2_5') | int > 40 %}\n 4\n{% elif states('sensor.bedroomair_purifier_pm2_5')\
\ | int > 20 %}\n 3\n{% elif states('sensor.bedroomair_purifier_pm2_5') |\
\ int > 10 %}\n 2\n{% else %}\n 1\n{% endif %}\n"
Any progress with your stuff @schilea ?
Edit: I’ve updated the above automation to work with 2021.9. And my card is almost working now, only need the fan mode translated into 3 steps, perhaps speed_percentage 10%, 50% and 100%.
And I think we still need the binary sensors to display what mode the fan is in.
You may use number.set_value to set the fan level to 1,2 or 3. Binary sensors are indeed needed to determine the fan mode
action: call-service
service: number.set_value
service_data:
entity_id: number.zhimi_airpurifier_fan_level
value: 1
Ah thank you for the help @fly3r01
Now I just wish the old sensors would work. Do you have any idea how they should be modified?
binary_sensor:
- platform: template
sensors:
mi_air_purifier_mode_fan:
friendly_name: "Purifier Fan mode"
value_template: "{{ is_state_attr('fan.bedroom_purifier', 'mode', 3) and is_state('fan.bedroom_purifier', 'on') }}"
It should work
Mine is as below:
mi_air_purifier_mode_off:
friendly_name: "Purifier Off"
value_template: "{{ is_state('fan.mi_air_purifier_3h', 'off') }}"
mi_air_purifier_mode_auto:
friendly_name: "Purifier Auto mode"
value_template: "{{ is_state_attr('fan.mi_air_purifier_3h', 'mode', 0) and is_state('fan.mi_air_purifier_3h', 'on') }}"
mi_air_purifier_mode_silent:
friendly_name: "Purifier Silent mode"
value_template: "{{ is_state_attr('fan.mi_air_purifier_3h', 'mode', 1) and is_state('fan.mi_air_purifier_3h', 'on') }}"
mi_air_purifier_mode_favorite:
friendly_name: "Purifier Favorite mode"
value_template: "{{ is_state_attr('fan.mi_air_purifier_3h', 'mode', 2) and is_state('fan.mi_air_purifier_3h', 'on') }}"
mi_air_purifier_mode_fan:
friendly_name: "Purifier Fan mode"
value_template: "{{ is_state_attr('fan.mi_air_purifier_3h', 'mode', 3) and is_state('fan.mi_air_purifier_3h', 'on') }}"
mi_air_purifier_mode_fan_1:
friendly_name: "Purifier Fan mode 1"
value_template: "{{ is_state_attr('fan.mi_air_purifier_3h', 'mode', 3) and is_state('number.zhimi_airpurifier_fan_level', '1') and is_state('fan.mi_air_purifier_3h', 'on') }}"
mi_air_purifier_mode_fan_2:
friendly_name: "Purifier Fan mode 2"
value_template: "{{ is_state_attr('fan.mi_air_purifier_3h', 'mode', 3) and is_state('number.zhimi_airpurifier_fan_level', '2') and is_state('fan.mi_air_purifier_3h', 'on') }}"
mi_air_purifier_mode_fan_3:
friendly_name: "Purifier Fan mode 3"
value_template: "{{ is_state_attr('fan.mi_air_purifier_3h', 'mode', 3) and is_state('number.zhimi_airpurifier_fan_level', '3') and is_state('fan.mi_air_purifier_3h', 'on') }}"
Got some entity names wrong, got it working!
Hi hegohaizea,
thanks a lot for sharing!! I really like your conditional sensor state usage! Would you be so kind to share your sensor template? I am not a developer… more a prosumer and I went crazy by adopting it from somewhere else… all these syntax thingies…
Best
Olli
Managed it on my own - Done.
Its hard to get all snippets together in one working package and one working card.
Latest Status…
Picture Elements Card:
- type: picture-elements
title: Luftreiniger Wohnzimmer
image: local/img/air/bg.png
elements:
- type: conditional
conditions:
- entity: sensor.luftreiniger_wohnzimmer_pm25_severity
state: clean
- entity: binary_sensor.luftreiniger_wohnzimmer_mode_off
state: 'off'
elements:
- type: image
entity: sensor.luftreiniger_wohnzimmer_pm25_severity
title: PM2.5 severity level
tap_action:
action: more-info
state_image:
clean: local/img/air/clean.png
style:
top: 60%
left: 50%
min-width: 52%
- type: conditional
conditions:
- entity: sensor.luftreiniger_wohnzimmer_pm25_severity
state: polluted
- entity: binary_sensor.luftreiniger_wohnzimmer_mode_off
state: 'off'
elements:
- type: image
entity: sensor.luftreiniger_wohnzimmer_pm25_severity
title: PM2.5 severity level
tap_action:
action: more-info
state_image:
polluted: local/img/air/polluted.png
style:
top: 60%
left: 50%
min-width: 52%
- type: conditional
conditions:
- entity: sensor.luftreiniger_wohnzimmer_pm25_severity
state: critical
- entity: binary_sensor.luftreiniger_wohnzimmer_mode_off
state: 'off'
elements:
- type: image
entity: sensor.luftreiniger_wohnzimmer_pm25_severity
title: PM2.5 severity level
tap_action:
action: more-info
state_image:
critical: local/img/air/critical.png
style:
top: 60%
left: 50%
min-width: 52%
- type: state-icon
entity: binary_sensor.luftreiniger_wohnzimmer_mode_off
title: 'Off'
icon: mdi:power-standby
tap_action:
action: call-service
service: fan.turn_off
service_data:
entity_id: fan.luftreiniger_wohnzimmer
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.luftreiniger_wohnzimmer
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.luftreiniger_wohnzimmer_mode_off
state: 'off'
elements:
- type: state-label
entity: sensor.luftreiniger_wohnzimmer_air_quality_pm25
title: PM2.5
tap_action:
action: more-info
style:
top: 32%
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.luftreiniger_wohnzimmer_temperature
title: Temperature
tap_action:
action: more-info
style:
top: 42%
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.luftreiniger_wohnzimmer_humidity
title: Humidity
tap_action:
action: more-info
style:
top: 42%
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: select.luftreiniger_wohnzimmer_led_brightness
title: Display
tap_action:
action: more-info
style:
top: 41%
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.luftreiniger_wohnzimmer_buzzer
title: Buzzer
tap_action:
action: toggle
style:
top: 41%
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.luftreiniger_wohnzimmer_child_lock
title: Child lock
tap_action:
action: toggle
style:
top: 34%
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-label
entity: sensor.luftreiniger_wohnzimmer_filter_life_remaining
title: Filter remaining
tap_action:
action: more-info
style:
top: 39%
left: 63%
min-width: 40px
min-height: 40px
text-align: center
font-size: 80%
color: rgb(128,128,128)
- type: conditional
conditions:
- entity: binary_sensor.luftreiniger_wohnzimmer_mode_off
state: 'on'
elements:
- type: state-label
entity: sensor.luftreiniger_wohnzimmer_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.luftreiniger_wohnzimmer_temperature
title: Temperature
tap_action:
action: more-info
style:
top: 42%
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.luftreiniger_wohnzimmer_humidity
title: Humidity
tap_action:
action: more-info
style:
top: 42%
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.luftreiniger_wohnzimmer_mode_auto
title: Auto
icon: mdi:autorenew
tap_action:
action: call-service
service: fan.set_speed
service_data:
entity_id: fan.luftreiniger_wohnzimmer
speed: Auto
style:
top: 50%
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.luftreiniger_wohnzimmer_mode_silent
title: Silent
icon: mdi:power-sleep
tap_action:
action: call-service
service: fan.set_speed
service_data:
entity_id: fan.luftreiniger_wohnzimmer
speed: Silent
style:
top: 50%
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.luftreiniger_wohnzimmer_mode_fan
title: Fan
icon: mdi:fan
tap_action:
action: call-service
service: fan.set_speed
service_data:
entity_id: fan.luftreiniger_wohnzimmer
speed: Fan
style:
top: 50%
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.luftreiniger_wohnzimmer_mode_favorite
title: Favorite
icon: mdi:heart
tap_action:
action: call-service
service: fan.set_speed
service_data:
entity_id: fan.luftreiniger_wohnzimmer
speed: Favorite
style:
top: 50%
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.luftreiniger_wohnzimmer_mode_fan
state: 'on'
elements:
- type: state-icon
entity: binary_sensor.luftreiniger_wohnzimmer_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.luftreiniger_wohnzimmer_fan_level
value: 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.luftreiniger_wohnzimmer_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.luftreiniger_wohnzimmer_fan_level
value: 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.luftreiniger_wohnzimmer_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.luftreiniger_wohnzimmer_fan_level
value: 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.luftreiniger_wohnzimmer_mode_favorite
state: 'on'
elements:
- type: state-label
entity: sensor.luftreiniger_wohnzimmer_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.luftreiniger_wohnzimmer_favorite_up
service_data:
entity_id: fan.luftreiniger_wohnzimmer
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.luftreiniger_wohnzimmer_favorite_down
service_data:
entity_id: fan.luftreiniger_wohnzimmer
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.luftreiniger_wohnzimmer_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)
and the package:
####################################################
# Package Luftreiniger Wohnzimmer #
####################################################
#extendet package inspired by: https://community.home-assistant.io/t/lovelace-xiaomi-mi-air-purifier-3h-card/192100/146?u=ollli
input_select:
luftreiniger_wohnzimmer_mode:
name: Mode
options:
- Auto
- Silent
- Favorite
- Fan
initial: Auto
icon: mdi:animation-outline
luftreiniger_wohnzimmer_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: 28-49 m²
icon: mdi:texture-box
input_number:
luftreiniger_wohnzimmer_favorite_level:
name: "Favorite level"
initial: 3
min: 0
max: 14
step: 1
icon: mdi:weather-windy
luftreiniger_wohnzimmer_fan_level:
name: "Fan level"
initial: 1
min: 1
max: 3
step: 1
icon: mdi:jquery
input_boolean:
luftreiniger_wohnzimmer_attributes:
name: Attributes
icon: mdi:pencil
switch:
- platform: template
switches:
luftreiniger_wohnzimmer_led:
friendly_name: "Display"
value_template: "{{ is_state_attr('fan.luftreiniger_wohnzimmer', 'led', true) }}"
turn_on:
service: xiaomi_miio.fan_set_led_on
data:
entity_id: fan.luftreiniger_wohnzimmer
turn_off:
service: xiaomi_miio.fan_set_led_off
data:
entity_id: fan.luftreiniger_wohnzimmer
icon_template: mdi:lightbulb-outline
luftreiniger_wohnzimmer_child_lock:
friendly_name: "Child lock"
value_template: "{{ is_state_attr('fan.luftreiniger_wohnzimmer', 'child_lock', true) }}"
turn_on:
service: xiaomi_miio.fan_set_child_lock_on
data:
entity_id: fan.luftreiniger_wohnzimmer
turn_off:
service: xiaomi_miio.fan_set_child_lock_off
data:
entity_id: fan.luftreiniger_wohnzimmer
icon_template: "mdi:lock-outline"
luftreiniger_wohnzimmer_buzzer:
friendly_name: "Buzzer"
value_template: "{{ is_state_attr('fan.luftreiniger_wohnzimmer', 'buzzer', true) }}"
turn_on:
service: xiaomi_miio.fan_set_buzzer_on
data:
entity_id: fan.luftreiniger_wohnzimmer
turn_off:
service: xiaomi_miio.fan_set_buzzer_off
data:
entity_id: fan.luftreiniger_wohnzimmer
icon_template: "mdi:volume-high"
sensor:
- platform: template
sensors:
luftreiniger_wohnzimmer_temp:
friendly_name: "Temperature"
value_template: "{{ state_attr('fan.luftreiniger_wohnzimmer', 'temperature') }}"
unit_of_measurement: "°C"
device_class: "temperature"
luftreiniger_wohnzimmer_humidity:
friendly_name: "Humidity"
value_template: "{{ state_attr('fan.luftreiniger_wohnzimmer', 'humidity') }}"
unit_of_measurement: "%"
device_class: "humidity"
luftreiniger_wohnzimmer_air_quality_pm25:
friendly_name: "Luftqualität Wohnzimmer (μg/m³)"
value_template: "{{ states('sensor.luftreiniger_wohnzimmer_pm2_5') | float | round(0) }}"
unit_of_measurement: " "
icon_template: "mdi:air-purifier"
luftreiniger_wohnzimmer_avg_air_quality_pm25:
friendly_name: "Average air quality (AvgAQI) PM2.5"
value_template: "{{ state_attr('fan.luftreiniger_wohnzimmer', 'average_aqi') }}"
unit_of_measurement: "μg/m³"
icon_template: "mdi:weather-hazy"
luftreiniger_wohnzimmer_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.luftreiniger_wohnzimmer', 'use_time') | int / 604800) | int %}
{% set days = ((state_attr('fan.luftreiniger_wohnzimmer', 'use_time') | int - (weeks * 604800)) / 86400) | int %}
{% set hours = ((state_attr('fan.luftreiniger_wohnzimmer', 'use_time') | int - (weeks * 604800) - (days * 86400)) / 3600) | int %}
{% set minutes = ((state_attr('fan.luftreiniger_wohnzimmer', 'use_time') | int - (weeks * 604800) - (days * 86400) - (hours * 3600)) / 60) | int %}
{% set seconds = (state_attr('fan.luftreiniger_wohnzimmer', '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"
luftreiniger_wohnzimmer_filter_used:
friendly_name: "Filter used"
value_template: "{{ state_attr('fan.luftreiniger_wohnzimmer', 'filter_hours_used') }}"
unit_of_measurement: "hrs"
icon_template: "mdi:heart-off"
luftreiniger_wohnzimmer_filter_remaining:
friendly_name: "Filter remaining"
value_template: "{{ state_attr('fan.luftreiniger_wohnzimmer', 'filter_life_remaining') }}"
unit_of_measurement: "%"
icon_template: "mdi:heart-outline"
luftreiniger_wohnzimmer_purify_volume:
friendly_name: "Purified volume"
value_template: "{{ state_attr('fan.luftreiniger_wohnzimmer', 'purify_volume') }}"
unit_of_measurement: "m³"
icon_template: "mdi:warehouse"
luftreiniger_wohnzimmer_speed:
friendly_name: "Motor speed"
value_template: "{{ state_attr('fan.luftreiniger_wohnzimmer', 'motor_speed') }}"
unit_of_measurement: "rpm"
icon_template: "mdi:speedometer"
luftreiniger_wohnzimmer_led_brightness:
friendly_name: "Led brightness"
value_template: "{{ state_attr('fan.luftreiniger_wohnzimmer', 'led_brightness') }}"
unit_of_measurement: "lx"
icon_template: "mdi:brightness-5"
luftreiniger_wohnzimmer_pm25_severity:
friendly_name: "Luftreiniger Wohnzimmer PM2.5 severity level"
value_template: >-
{% if state_attr('fan.luftreiniger_wohnzimmer', 'aqi') | int > 30 %}
{{ 'critical' }}
{% elif state_attr('fan.luftreiniger_wohnzimmer', 'aqi') | int > 15 %}
{{ 'polluted' }}
{% else %}
{{ 'clean' }}
{% endif %}
icon_template: "mdi:air-filter"
binary_sensor:
- platform: template
sensors:
luftreiniger_wohnzimmer_mode_off:
friendly_name: "Luftreiniger Wohnzimmer Aus"
value_template: "{{ is_state('fan.luftreiniger_wohnzimmer', 'off') }}"
luftreiniger_wohnzimmer_mode_auto:
friendly_name: "Luftreiniger Wohnzimmer Auto"
value_template: "{{ is_state_attr('fan.luftreiniger_wohnzimmer', 'mode', 0) and is_state('fan.luftreiniger_wohnzimmer', 'on') }}"
luftreiniger_wohnzimmer_mode_silent:
friendly_name: "Luftreiniger Wohnzimmer Leise"
value_template: "{{ is_state_attr('fan.luftreiniger_wohnzimmer', 'mode', 1) and is_state('fan.luftreiniger_wohnzimmer', 'on') }}"
luftreiniger_wohnzimmer_mode_favorite:
friendly_name: "Luftreiniger Wohnzimmer Favorit"
value_template: "{{ is_state_attr('fan.luftreiniger_wohnzimmer', 'mode', 2) and is_state('fan.luftreiniger_wohnzimmer', 'on') }}"
luftreiniger_wohnzimmer_mode_fan:
friendly_name: "Luftreiniger Wohnzimmer Fan mode"
value_template: "{{ is_state_attr('fan.luftreiniger_wohnzimmer', 'mode', 3) and is_state('fan.luftreiniger_wohnzimmer', 'on') }}"
luftreiniger_wohnzimmer_mode_fan_1:
friendly_name: "Luftreiniger Wohnzimmer Fan mode 1"
value_template: "{{ is_state_attr('fan.luftreiniger_wohnzimmer', 'mode', 3) and is_state_attr('fan.luftreiniger_wohnzimmer', 'fan_level', 1) and is_state('fan.luftreiniger_wohnzimmer', 'on') }}"
luftreiniger_wohnzimmer_mode_fan_2:
friendly_name: "Luftreiniger Wohnzimmer Fan mode 2"
value_template: "{{ is_state_attr('fan.luftreiniger_wohnzimmer', 'mode', 3) and is_state_attr('fan.luftreiniger_wohnzimmer', 'fan_level', 2) and is_state('fan.luftreiniger_wohnzimmer', 'on') }}"
luftreiniger_wohnzimmer_mode_fan_3:
friendly_name: "Luftreiniger Wohnzimmer Fan mode 3"
value_template: "{{ is_state_attr('fan.luftreiniger_wohnzimmer', 'mode', 3) and is_state_attr('fan.luftreiniger_wohnzimmer', 'fan_level', 3) and is_state('fan.luftreiniger_wohnzimmer', 'on') }}"
####################################################
# END OF Package #
####################################################
the result:
Minor Issues:
The selected Fan speed does net get colored and sometimes it tooks ages until the conditions are “updated” and the right icons are shown.
So if someone has a hint here, I would be very happy!
It was my first post “with content” - please be kind if something is not as expected
You can make binary sensors that trigger if it is fan mode, 1, 2 or 3, and use that in the card, then they will be coloured.
mi_air_purifier_mode_fan_1:
friendly_name: "Purifier Fan mode 1"
value_template: "{{ is_state_attr('fan.bedroom_purifier', 'mode', 3) and is_state('number.bedroomair_purifier_fan_level', '1') and is_state('fan.bedroom_purifier', 'on') }}"
mi_air_purifier_mode_fan_2:
friendly_name: "Purifier Fan mode 2"
value_template: "{{ is_state_attr('fan.bedroom_purifier', 'mode', 3) and is_state('number.bedroomair_purifier_fan_level', '2') and is_state('fan.bedroom_purifier', 'on') }}"
mi_air_purifier_mode_fan_3:
friendly_name: "Purifier Fan mode 3"
value_template: "{{ is_state_attr('fan.bedroom_purifier', 'mode', 3) and is_state('number.bedroomair_purifier_fan_level', '3') and is_state('fan.bedroom_purifier', 'on') }}"
and for the card:
- 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: number.set_value
service_data:
entity_id: number.bedroomair_purifier_fan_level
value: 1
Also consider making the numbered fan buttons conditional, so they only show if the purifier is in fan mode.
Thanks for your Reply!
Maybe I am already blind on the code failures… I believe I have done exactly that.
the adopted binary_sensor is in the package (end of file / last lines)
luftreiniger_wohnzimmer_mode_fan_1:
friendly_name: "Luftreiniger Wohnzimmer Fan mode 1"
value_template: "{{ is_state_attr('fan.luftreiniger_wohnzimmer', 'mode', 3) and is_state_attr('fan.luftreiniger_wohnzimmer', 'fan_level', 1) and is_state('fan.luftreiniger_wohnzimmer', 'on') }}"
luftreiniger_wohnzimmer_mode_fan_2:
friendly_name: "Luftreiniger Wohnzimmer Fan mode 2"
value_template: "{{ is_state_attr('fan.luftreiniger_wohnzimmer', 'mode', 3) and is_state_attr('fan.luftreiniger_wohnzimmer', 'fan_level', 2) and is_state('fan.luftreiniger_wohnzimmer', 'on') }}"
luftreiniger_wohnzimmer_mode_fan_3:
friendly_name: "Luftreiniger Wohnzimmer Fan mode 3"
value_template: "{{ is_state_attr('fan.luftreiniger_wohnzimmer', 'mode', 3) and is_state_attr('fan.luftreiniger_wohnzimmer', 'fan_level', 3) and is_state('fan.luftreiniger_wohnzimmer', 'on') }}"
####################################################
# END OF Package #
####################################################
and the mentioned card part (conditional):
- type: conditional
conditions:
- entity: binary_sensor.luftreiniger_wohnzimmer_mode_fan
state: 'on'
elements:
- type: state-icon
entity: binary_sensor.luftreiniger_wohnzimmer_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.luftreiniger_wohnzimmer_fan_level
value: 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)
this is what you mean right?
I can see your binary sensor is not right.
Go from:
value_template: "{{ is_state_attr('fan.luftreiniger_wohnzimmer', 'mode', 3) and is_state_attr('fan.luftreiniger_wohnzimmer', 'fan_level', 1) and is_state('fan.luftreiniger_wohnzimmer', 'on') }}"
to
value_template: "{{ is_state_attr('fan.luftreiniger_wohnzimmer', 'mode', 3) and is_state('number.luftreiniger_wohnzimmer_fan_level', '1') and is_state('fan.luftreiniger_wohnzimmer', 'on') }}"
I am of course assuming your number value for fan is called: 'number.luftreiniger_wohnzimmer_fan_level, you should go check what it really is.
That should make the behaviour similar to this:
Guys, better later than never. Finally had some time yesterday to look on the card. 99% done, still had to fix one isssue and than can be posted.
@bjorn.sivertsen @ollli here are my binary sensors
#==================#
# 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') }}"
@schilea @bjorn.sivertsen
Thanks a lot for your help!
It works like a charm
Looking forward to your improvements and kudos for your great work so far!
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