Ha esp32 fan control problem

Hi guys.
New here.

i have spent way too much time on this and i am stuck.
i am trying to control 4 fans speed depending on temperature. the higher the temperature difference the faster the fans spin. . My problem is that she fan relay "fan_power doesnt switch on when the temperature is high. do you have any ideas on what am i doing wrong? i have checked the code in yaml checker and it removed all the comments. also i am reverse engineering this from another project.

---
substitutions:
  name: MPPT Chladenie
  max_temp: "50"
  dallas_addr: "0xff455bd443c84d28"
  dallas_addr1: "0xda605ed4436a9b28"
  dallas_addr2: "0x1524b3d443e83b28"
  dallas_addr3: "0x6269b8d443293b28"
esphome:
  name: ventilatory-victron-chladenie
  friendly_name: Ventilatory Victron chladenie
esp32:
  board: esp32dev
  framework:
    type: arduino

logger:
  logs:
    dallas sensor: none
    number: none
    sensor: none
    light: none
    fan: none
api:
  encryption:
    key: 5s92kG9kX5565gsNWUDuyaSC/rXfGRMhiXiU2iTDt2Y=
ota:
  - platform: esphome
    password: 0f5e0bc8334cc7fa09a63e95aba05905
wifi:
  manual_ip:
    static_ip: 192.168.1.111
    gateway: 192.168.1.1
    subnet: 255.255.255.0
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap:
    ssid: Ventilatory-Victron-Chladenie
    password: kncRpVx4GlOn
captive_portal: null
number:
  - platform: template
    id: set_temp
    name: MPPT 250/100 Nast. Tepl.
    optimistic: true
    min_value: 10
    max_value: 50
    initial_value: 25
    step: 1
    restore_value: true

  - platform: template
    id: set_temp1
    name: MPPT 250/85 Nast. Tepl.
    optimistic: true
    min_value: 10
    max_value: 50
    initial_value: 25
    step: 1
    restore_value: true

  - platform: template
    id: set_temp2
    name: multiplus L1 Nast. Tepl.
    optimistic: true
    min_value: 10
    max_value: 50
    initial_value: 25
    step: 1
    restore_value: true

  - platform: template
    id: set_temp3
    name: Multiplus L2 Nast. Tepl.
    optimistic: true
    min_value: 10
    max_value: 50
    initial_value: 25
    step: 1
    restore_value: true
one_wire:
  - platform: gpio
    pin: GPIO17
sensor:
  - platform: dallas_temp
    address: $dallas_addr
    name: MPPT 250/100 Teplota
    id: temp_sensor
    update_interval: 2s
    accuracy_decimals: 0
  - platform: dallas_temp
    address: $dallas_addr1
    name: MPPT 250/85 Teplota
    id: temp_sensor1
    update_interval: 2s
    accuracy_decimals: 0
  - platform: dallas_temp
    address: $dallas_addr2
    name: Multiplus L1 Teplota
    id: temp_sensor2
    update_interval: 2s
    accuracy_decimals: 0
  - platform: dallas_temp
    address: $dallas_addr3
    name: Multiplus L2 Teplota
    id: temp_sensor3
    update_interval: 2s
    accuracy_decimals: 0

    # Adjust fan speed(1-100%). Else, turn it off and set the speed to 1
    on_value:
      - lambda: !lambda |
          auto pct = map(x, id(set_temp).state, id(set_temp).state+20, 1, 100);
          if (pct>1) {
            auto call = id(the_fan).turn_on(); call.set_speed(pct); call.perform();
          } else {
            auto call = id(the_fan).turn_off(); call.set_speed(1); call.perform();
          }

       # Adjust fan speed(1-100%). Else, turn it off and set the speed to 1

      - lambda: !lambda |
          auto pct = map(x, id(set_temp1).state, id(set_temp1).state+20, 1, 100);
          if (pct>1) {
            auto call = id(the_fan1).turn_on(); call.set_speed(pct); call.perform();
          } else {
            auto call = id(the_fan1).turn_off(); call.set_speed(1); call.perform();
          }      
      - lambda: !lambda |
          auto pct = map(x, id(set_temp2).state, id(set_temp2).state+20, 1, 100);

          if (pct>1) {
            auto call = id(the_fan2).turn_on(); call.set_speed(pct); call.perform();
          } else {
            auto call = id(the_fan2).turn_off(); call.set_speed(1); call.perform();
          }            
      - lambda: !lambda |
          auto pct = map(x, id(set_temp3).state, id(set_temp3).state+20, 1, 100);

          if (pct>1) {
            auto call = id(the_fan3).turn_on(); call.set_speed(pct); call.perform();
          } else {
            auto call = id(the_fan3).turn_off(); call.set_speed(1); call.perform();
          }      
      - if:
          condition:
            for:
              time: 5s
              condition:
                lambda: return id(temp_sensor).state > id(set_temp).state+20;
          then:
            - light.turn_on:
                id: d4_light
                effect: flashfast
            - lambda: id(alarm1).publish_state(true);
          else:
            - light.turn_off: d4_light
            - lambda: id(alarm1).publish_state(false);
      - if:
          condition:
            for:
              time: 5s
              condition:
                lambda: return id(temp_sensor1).state > id(set_temp1).state+20;
          then:
            - light.turn_on:
                id: d4_light
                effect: flashfast
            - lambda: id(alarm2).publish_state(true);
          else:
            - light.turn_off: d4_light
            - lambda: id(alarm2).publish_state(false);
      - if:
          condition:
            for:
              time: 5s
              condition:
                lambda: return id(temp_sensor2).state > id(set_temp2).state+20;
          then:
            - light.turn_on:
                id: d4_light
                effect: flashfast
            - lambda: id(alarm3).publish_state(true);
          else:
            - light.turn_off: d4_light
            - lambda: id(alarm3).publish_state(false);
      - if:
          condition:
            for:
              time: 5s
              condition:
                lambda: return id(temp_sensor3).state > id(set_temp3).state+20;
          then:
            - light.turn_on:
                id: d4_light
                effect: flashfast
            - lambda: id(alarm4).publish_state(true);
          else:
            - light.turn_off: d4_light
            - lambda: "id(alarm4).publish_state(false);                                "
switch:
  - platform: gpio
    pin: GPIO5
    id: fan_power
    inverted: true
  - platform: gpio
    pin: GPIO18
    id: fan_power1
    inverted: True
  - platform: gpio
    pin: GPIO19
    id: fan_power2
    inverted: true
  - platform: gpio
    pin: GPIO21
    id: fan_power3
    inverted: true
fan:
  - platform: speed
    id: the_fan
    output: fan_pwm
    name: MPPT 250/100 Ventilator
    speed_count: 100
    on_turn_on:
      - switch.turn_on: fan_power
    on_turn_off:
      - switch.turn_off: fan_power
  - platform: speed
    id: the_fan1
    output: fan_pwm1
    name: MPPT 250/85 Ventilator
    speed_count: 100
    on_turn_on:
      - switch.turn_on: fan_power1
    on_turn_off:
      - switch.turn_off: fan_power1
  - platform: speed
    id: the_fan2
    output: fan_pwm2
    name: Multiplus L1 Ventilator
    speed_count: 100
    on_turn_on:
      - switch.turn_on: fan_power2
    on_turn_off:
      - switch.turn_off: fan_power2
  - platform: speed
    id: the_fan3
    output: fan_pwm3
    name: Multiplus L2 Ventilator
    speed_count: 100
    on_turn_on:
      - switch.turn_on: fan_power3
    on_turn_off:
      - switch.turn_off: fan_power3
binary_sensor:
  - platform: template
    id: alarm1
    name: Alarm mppt 250/100
    icon: mdi:fire
  - platform: template
    id: alarm2
    name: Alarm mppt250/85
    icon: mdi:fire
  - platform: template
    id: alarm3
    name: Alarm Multiplus L1
    icon: mdi:fire
  - platform: template
    id: alarm4
    name: Alarm Multiplus L2
    icon: mdi:fire
light:
  - platform: monochromatic
    id: d4_light
    output: d4_light_pwm
    effects:
      - pulse:
          name: flashfast
          transition_length: 0.5s
          update_interval: 0.5s
output:
  - platform: ledc
    id: fan_pwm
    pin:
      number: GPIO13
    min_power: 0.05
    frequency: 25.0kHz
  - platform: ledc
    id: fan_pwm1
    pin:
      number: GPIO12
    min_power: 0.05
    frequency: 25.0kHz
  - platform: ledc
    id: fan_pwm2
    pin:
      number: GPIO14
    min_power: 0.05
    frequency: 25.0kHz
  - platform: ledc
    id: fan_pwm3
    pin:
      number: GPIO27
    min_power: 0.05
    frequency: 25.0kHz
  - platform: slow_pwm
    period:
      seconds: 1
    id: d4_light_pwm
    pin:
      number: GPIO2
      inverted: true

type or paste code here

What you mean with this? Just fan_power doesn’t or any of them (3) don’t?
Also, your code switches fan_power on only when you switch speed fan on.

Maybe this will help.
i have a set temperature when the fan should start spinning and when the pwm starts to control the fan the ralay sill switch on to put power to the fan. but now what happens is the fan doesnt turn on when the temperature reaches the treshold. it will only turn on when i manually move the slider for the temperature settings. hope this helps.

You didn’t answer my first question, just fan_power or all of them?
Also be aware that you have automations only for temp_sensor3.