How to automate based on temperature with maximum on time and cooldown?

Hello all,

New to HA, I tried looking around but not even sure how to start.

I’m looking to automate a fan based on humidity, but getting confused with complex triggers/conditions. Here’s what I would like it to do.

  • Turn ON fan if humidity drops below 70
  • If humidity reaches 80 → Turn OFF fan
  • If fan has been ON for 20 mins (doesn’t matter what the humidity is) → Turn OFF fan to let it cooldown
  • After 20 mins of the fan being OFF, if humidity is still below 70, Turn fan ON and repeat the logic above.

How should I automate this? Thank you so much in advanced.

EDIT:
I managed to solve this, in case anyone comes along later. Hopefully this helps whoever arrives on this page.

I ended up with 3 automations below:

This automation is the main one that checks every time the humidity changes. Then decides whether it needs to turn the fan on, based on temperature and a cooldown boolean.

In the yaml code I call the fan “evap”, but really it’s a fan+pump combo. It’s for normal oyster mushroom, nothing illegal I swear.

alias: Humidity Control
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.mushroom_1_humidity
    id: id_humid_change
  - platform: state
    entity_id:
      - input_boolean.evap_cooldown
    to: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 5
    id: id_evap_cooldown_off
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - id_humid_change
              - id_evap_cooldown_off
          - condition: numeric_state
            entity_id: sensor.mushroom_1_humidity
            below: 70
          - condition: state
            entity_id: input_boolean.evap_cooldown
            state: "off"
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              entity_id: switch.evap_group
      - conditions:
          - condition: trigger
            id:
              - id_humid_change
          - condition: numeric_state
            entity_id: sensor.mushroom_1_humidity
            above: 80
        sequence:
          - if:
              - condition: state
                entity_id: switch.evap_group
                state: "on"
            then:
              - service: switch.turn_off
                data: {}
                target:
                  entity_id: switch.evap_group
              - service: input_boolean.turn_on
                data: {}
                target:
                  entity_id: input_boolean.evap_cooldown
mode: single

The second automation checks how long the fan (evap) has been on for, and turn it off after 20 minutes. It also flip a boolean to true to be checked later.

alias: Check Evap ON time
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.evap_group
    to: "on"
    for:
      hours: 0
      minutes: 20
      seconds: 0
condition: []
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.evap_group
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.evap_cooldown
mode: single

The third automation checks the cooldown time, if evap_cooldown time has been true for 20 minutes, it flips the boolean to false. Which then lets the first automation turn on the fan/evap.

alias: Check cooldown time
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.evap_cooldown
    to: "on"
    for:
      hours: 0
      minutes: 20
      seconds: 0
condition: []
action:
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.evap_cooldown
mode: single