Automation or script for Vesync Air purifier

Hello all
as I am new to home assistant, I am trying to set up a new automation or script (?)
I have a vesync air purifier in every room (all devices are set up and visible to HA), and I want to make them automatically turn on after a value and turn off when the lower value or limit is reached.
Then this has to be in a loop during the day or at specific times
What would you suggest, please?

alias: AirPurifierGreatRoom
description: ""
trigger:
  - platform: time_pattern
    minutes: "5"
condition: []
action:
  - if:
      - condition: numeric_state
        entity_id: sensor.awair_element_22003_pm2_5
        above: 10
        below: 20000
    then:
      - type: turn_on
        device_id: 55c434ef176a67b0e458fc1608ce9a3d
        entity_id: fan.air_purifier
        domain: fan
      - service: fan.set_preset_mode
        data:
          preset_mode: auto
        target:
          entity_id: fan.air_purifier
    else:
      - type: turn_off
        device_id: 55c434ef176a67b0e458fc1608ce9a3d
        entity_id: fan.air_purifier
        domain: fan
mode: single

Here’s what I setup… I’m using a PM2.5 sensor nearby and checking on the 5th minute of every hour.
Change “5” to /5 if you’d prefer a check every 5 minutes.

Thanks I will try :slight_smile: