Nothing special here, just a little script to wait for the air purifier (a Levoit 131) to clean the air before switching off…
fan_auto_off_script:
mode: restart
sequence:
- service: fan.set_preset_mode
target:
entity_id: fan.levoit_131_air_purifier
data:
preset_mode: auto
- choose:
- conditions:
- condition: template
value_template: "{{ not is_state_attr('fan.levoit_131_air_purifier', 'air_quality', 'excellent')}}"
sequence:
- service: logbook.log
data_template:
name: "Air Purifier On"
message: "Air quality is {{ state_attr('fan.levoit_131_air_purifier', 'air_quality') }} - waiting for air quality to improve"
- wait_for_trigger:
- platform: state
entity_id: fan.levoit_131_air_purifier
attribute: "air_quality"
to: "excellent"
timeout: '04:00:00'
- service: logbook.log
data_template:
name: "Air Purifier On"
message: "Air quality excellent"
- wait_for_trigger:
- platform: template
value_template: "{{ not is_state_attr('fan.levoit_131_air_purifier', 'air_quality', 'excellent')}}"
timeout: '00:30:00'
- choose:
- conditions:
- condition: template
value_template: "{{ not wait.trigger }}"
sequence:
- service: logbook.log
data_template:
name: Turning off air purifier
message: "Air quality has been excellent for 30 minutes"
- service: homeassistant.turn_off
entity_id: fan.levoit_131_air_purifier
- delay: "00:00:10"
- service: script.turn_off
entity_id: script.fan_auto_off_script
default:
- service: script.turn_on
entity_id: script.fan_auto_off_script
Amanda