Problem with a auttomation PLEASE HELP

Hello i create a simple controller for my terrarium! I like to controll Temp and Humidity with a bme280 sensor and 2 Relays. The Temp automation run, the humidity not :frowning:
Have everyone a idea? Sorry my English is bad.

is the prolem solved, i like is Humidity below 60% then relay 5sec on then out and wait 30sec and restart to value up 60%

best greets
Emanuel

captive_portal:

i2c:
   - id: bus_1
     sda: GPIO4
     scl: GPIO5
     scan: true 

time:
  - platform: sntp
    id: sntp_time

display:
  - platform: lcd_pcf8574
    dimensions: 20x4
    address: 0x27
    update_interval: 20sec
    lambda: |-
      it.print(2, 0, "SchneckenControll");   
      it.printf(0, 1, "Temperatur: %6.1f", id(bme280_temperatur2).state);
      it.printf(0, 2, "Feuchtigkeit: %2.1f", id(bme_luftfeuchte2).state);  
      it.strftime(0, 3, " %H:%M   %d.%m.%Y", id(sntp_time).now());          

sensor:
  - platform: bme280
    i2c_id: bus_1
    temperature:
      name: "Temperatur"
      id: bme280_temperatur2
      oversampling: 16x
      accuracy_decimals: 1
      on_value_range:
        - above: 30.0
          then:
            - switch.turn_off: heizung
        - below: 27.0
          then:
            - switch.turn_on: heizung  

    humidity:
      name: "Luftfeuchte"
      id: "bme_luftfeuchte2"
      accuracy_decimals: 1 
      on_value_range:
        - above: 70.0
          then:
            - switch.turn_off: sprayer
        - below: 60.0
          then:
            - switch.turn_on: sprayer         
    update_interval: 10s
    address: 0x76  


      
# The relay control pin (local only)
switch:
  - platform: gpio
    pin: GPIO14
    id: heizung
    inverted: true


  - platform: gpio
    pin: GPIO12
    id: sprayer
    inverted: true

  - platform: template
    name: "Heizung"
    optimistic: true
    lambda: |-
      if (id(heizung).state) {
        return true;
      } else {
        return false;
      }    
    on_turn_on:
      - switch.turn_on: heizung
    on_turn_off:
      - switch.turn_off: heizung

  - platform: template
    name: "WassersprĂźher"
    optimistic: true
      if (id(sprayer).state) {
        return true;
      } else {
        return false;
      }    
    on_turn_on:
      - switch.turn_on: sprayer
    on_turn_off:
      - switch.turn_off: sprayer    

Maybe look at using a while.

While below threshold, spray, wait, repeat.

Scripts can also be handy for this kind of thing since you can stop, start and wait for them.

You could limit the maximum cycles in the while by using a repeat if you like.

Does the humidity ever cross below 60 or above 70? If it starts at 75 for example, your above 70 automation won’t start. It will only work if it’s below 70 and then rises to 70 or above and same for your lower limit. You need to use a “while” condition or the simplest and better way would be to make a thermostat. This way you can quickly change settings from the front end.Thermostat Climate Controller — ESPHome

Thanks the climate thermostat is it thanks!
i learn this all with learning by doing
THANKS