For the last few days I have been working on the automation for my Xiaomi Air Purifier 2S. After many trials and versions, and thanks to the help of the guys on this forum, I have reached the optimal version. A number of problems arose from the fact that the “off” mode is not clearly interpreted and theoretically the only valid preset modes are: Auto, Silent, Favourite. In any case, the actual code works as expected.
alias: Air purifier automation
description: ""
trigger:
- platform: numeric_state
entity_id:
- sensor.air_purifier_pm2_5
above: 85
below: 2000
id: Auto
- platform: numeric_state
entity_id:
- sensor.air_purifier_pm2_5
above: 35
below: 84.9
id: Silent
- platform: numeric_state
entity_id:
- sensor.air_purifier_pm2_5
below: 34.9
id: "off"
for:
hours: 0
minutes: 5
seconds: 0
- platform: state
entity_id:
- schedule.nighttime
condition: []
action:
- choose:
- conditions:
- condition: state
entity_id: schedule.nighttime
state: "on"
sequence:
- service: switch.turn_off
target:
entity_id:
- switch.air_purifier_led
- switch.air_purifier_buzzer
data: {}
- conditions:
- condition: state
entity_id: schedule.nighttime
state: "off"
sequence:
- service: switch.turn_on
metadata: {}
data: {}
target:
entity_id:
- switch.air_purifier_buzzer
- switch.air_purifier_led
- if:
- condition: template
value_template: "{{ trigger.id != 'off' }}"
then:
- service: fan.set_preset_mode
data:
preset_mode: "{{ trigger.id }}"
target:
entity_id: fan.air_purifier
else:
- service: fan.turn_off
target:
entity_id: fan.air_purifier
data: {}
mode: restart
I have a second automation handling the control of the device by the window opening sensor. Unfortunately, I don’t know how to integrate the two and whether such an integration even makes sense. I have looked through many threads on the forum but nothing comes out of them to apply to my case. Please look at what I have created and give some suggestions on what to do and how to do it. My knowledge is still too small to figure out something for practical application myself.
alias: Air purifier on/off
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.ikea_window_sensor_opening
from: "off"
to: "on"
for:
hours: 0
minutes: 0
seconds: 0
condition: []
action:
- service: fan.turn_off
target:
entity_id:
- fan.air_purifier
data: {}
- service: automation.turn_off
data:
stop_actions: false
enabled: true
target:
entity_id: automation.air_purifier
- wait_for_trigger:
- platform: state
entity_id:
- binary_sensor.ikea_window_sensor_opening
from: "on"
to: "off"
for:
hours: 0
minutes: 0
seconds: 10
continue_on_timeout: false
- service: automation.turn_on
target:
entity_id:
- automation.air_purifier
data: {}
enabled: true
- condition: numeric_state
entity_id: sensor.air_purifier_pm2_5
above: 1
enabled: true
- service: fan.turn_on
target:
entity_id:
- fan.air_purifier
data: {}
enabled: true
mode: restart