PWM controlled fan with ESPhome on ESP32

Minimum speed of the fan depends on the fan.
Mine are running about 500rpm at 1%.

You can try reduce supply voltage, for example 9v or less at a 12v fan.

@nikPo @ilgio Have you managed to solve this problem? My fan is 12V DC (max 0.12A). Mosfet (IRF520N) connected to ESP32. Without the fan, the output is 12V, and with the fan connected it is a little over 3V, which of course does not let it start.

Hi there,
I have a 24v fan that can run in 2 directions.
I manage to connect my Cytron Mdc30R2 to a esp8266 gpio 2 and 4
2 is pwm and 4 is direction
It works fine , but direction is not available in HA and not working.
Here is my code:

substitutions:
  device_name: largefan24v
  device_description: Large 24V Fan controller
  friendly_name: fan24pwm

esphome:
  name: ${device_name}
  comment: ${device_description}
  platform: ESP8266
  board: nodemcuv2
  on_boot:
    - priority: 200.0
      then:
        - output.set_level:
            id: pwmfan
            level: 0%

wifi:
  ssid: BRAIN
  password: $$

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: ${friendly_name}_AP
    password: techuser

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: techuser

# Enable OTA
ota:
  password: techuser

switch:
  - platform: restart
    name: ${friendly_name} Restart

binary_sensor:
# Reports if this device is Connected or not
  - platform: status
    name: ${friendly_name} Status

sensor:
# Reports the WiFi signal strength
  - platform: wifi_signal
    name: ${friendly_name} Signal
    update_interval: 60s

# Reports RPM by pulse_counter
  - platform: pulse_counter
    pin: D7
    name: ${friendly_name} Fan Speed
    unit_of_measurement: 'RPM'
    filters:
      - multiply: 0.5
      - lambda: |-
          if (x <= 1500) return x;
          else return {};
    count_mode:
      rising_edge: INCREMENT
      falling_edge: DISABLE
    update_interval: 30s

# Reports how long the device has been powered (in minutes)
  - platform: uptime
    name: ${friendly_name} Uptime
    filters:
      - lambda: return x / 60.0;
    unit_of_measurement: minutes

text_sensor:
# Reports the ESPHome Version with compile date
  - platform: version
    name: ${friendly_name} ESPHome Version

# Reports WiFi name
  - platform: wifi_info
    ssid:
      name: ${friendly_name} WiFi

# Reports IP
  - platform: wifi_info
    ip_address:
      name: ${friendly_name} IP

status_led:
  pin: 
    number: D0
    inverted: False

output:
  - platform: gpio
    pin: D3
    id: fan_supply
  - platform: gpio
    pin: D4                 #### i added this
    id: fan_direction       #### but it is not working, not detected by homeassistant
  - platform: esp8266_pwm
    pin: D2
    frequency: 5000 Hz
    id: pwmfan

fan:
  - platform: speed
    output: pwmfan
    name: ${friendly_name} Fan
    on_turn_on:
      - output.turn_on: fan_supply
      - logger.log: "Power of Fan turned ON"
    on_turn_off:
      - output.turn_off: fan_supply
      - logger.log: "Power of Fan turned OFF"
      - delay: 1s
      - logger.log: "Write 100%% to output pwmfan"
      - output.set_level:
          id: pwmfan
          level: 0%
1 Like

You dont have direction configured for your fan. You have an Ouput but no way to use it with your fan. You dont have any speeds configured either.

Thanks for the reply.
I am a newbee …
How to solve it?

Look at the Fan documentation.

Speed works perfict with a slider

Yes, but its easier to have presets for use in automations or whatever else you might do.

It is a 24v Truck fan 40cm and a MDC30 speedcontroller bu Cytron
Not much documentation

The esphome documentation

I searched , but no examples with direction

As i understand : if i define it in the esp code, it schould be detected by HA…

Searched where? You havnt defined it though

i searched esp forums google …

Yes i saw thatone but no direction…

Esphome has a website for documentation… It was probably the first search result you got.

Dude… it’s literally called Direction. Look harder

That is wher i got the espcode … but no direction switch