Automating air purifier and including door and window sensors

I have door and window binary sensors and air quality sensors all over my house. I just purchased an air purifier so I want to automate it given all these inputs. I drew up a flowchart trying to describe how (I think) I’d like it to operate but I am finding it very difficult to decide on the trigger/conditions/choose clauses and what platform(s) to use for triggering.

I have a group.all_house_windows and group.all_house_doors that can be used but I don’t want them to trigger right away if we’re using the door to come/go. Obviously, if we have the windows or doors open (to let the air through) I don’t want the purifier to run. But it would be nice if the purifier started running if the AQI was bad as soon as we closed up all the windows/doors for ~5 minutes. I also want some hysteresis on the fan speed so that it runs if the AQI is bad until the AQI is good for some time.

Here’s the flowchart I drew up and I’m sure it can be improved but I’m not sure how to adjust it. If you have suggestions, please respond.

image

Very interested in opinions on implementation this type of operation in an automation.

Hi, I would like to get the exact same thing working. Did you succeed?

I have a version of this flow with my Xiaomi Air Purifier Pro but using 3 automations: 1 automation each for AQI < 19 (Turn off); AQI >20 and <50 (Turn on, Fan speed 5); AQI >50 (Turn on, Fan speed 9).

I don’t use door contact sensors but I use Time Conditions to coincide with the times people are actually home.

I’m interested in combining the 3 automations into 1 and adding an Input Boolean condition to easier allow for exceptions i.e. someone takes an unplanned sick day, school holiday, etc. Anyone can point me in the right direction to get started? I imagine there would be loops involved?