ESPHome floor heating pump

Hello, I have a floor heating pump and I need to control it with two temperature sensors, that are on different pipes, the controller is ESP8266. The first condition is that the pump is turned on when the first sensor reads the water temperature above 30 degrees and turned off when it is below 29 degrees, the second condition is that the pump is turned off when the temperature of the second sensor reaches 40 degrees and turned on at 39 degrees.

I have this code below and it works until, say, the power goes out. When its power returns configuration doesn’t work, the temperature neet passing the temperature over the specified values.

How can I arrange the configuration in the ESPHome to toggle my pump on any temperature change in the specified range to turn on or off the pump? How to add a condition to check if the pump turns on or not when its temperature is in the specified values?

switch:
  - platform: gpio
    name: "Pin GPIO5"
    id: my_switch
    pin:
      number: 5   
      inverted: true

dallas:
  - pin: 15
    update_interval: 15s
  
sensor:
  - platform: uptime
    name: Uptime Sensor
    
  - platform: dallas
    address: 0xA33C01D60794B728
    name: "Floor heating pump"  
    id: my_sensor1
    on_value_range:
     - above: 40.0
       then:
            - switch.turn_off: my_switch
     - below: 39.0
       then:
            - switch.turn_on: my_switch
    
  - platform: dallas
    address: 0x263C01D607EBA328
    name: "Floor heating seperator"     
    id: my_sensor2
    on_value_range:
     - above: 30.0
       then:
            - switch.turn_on: my_switch
     - below: 29.0
       then:
            - switch.turn_off: my_switch

Your indentation is off in several places

    on_value_range:
      above: 40.0
      then:
        - switch.turn_off: my_switch

Thanks for the help, it helped me in my next step.

I just realized I deleted the - before above. If you use both above and below, I think you need the dash. It turns on and off as expected now?

sensor:
  - platform: dht
    humidity:
      name: "Living Room Humidity"
      on_value_range:
        - above: 65.0
          then:
            - switch.turn_on: dehumidifier1
        - below: 50.0
          then:
            - switch.turn_off: dehumidifier1

Yes, need to be the dash if use both above and below.

  - platform: dallas
    address: 0x263C01D607EBA328
    name: "Floor heating seperator"     
    id: my_sensor2
    on_value_range:
     - above: 30.0
       below: 32.0
       then:
        - switch.turn_on: my_switch
     - below: 29.0
       then:
        - switch.turn_off: my_switch