Wemos D1 Mini + Get fan-speed (RPM)

I’m trying to get the RPM from a CPU fan.
I don’t know if I’m at the right spot, while using: platform: pulse_width.

Part of my config looks like this:

substitutions:
  hostid: fireplace_fan
  hostname: Fireplace Fan
  comment: Fireplace fan controller
  node_platform: ESP8266
  node_board: d1_mini

packages:
  core: !include common/core.yaml
  basic_sensors: !include common/basic_sensors.yaml

esphome:
  on_boot:
    then:
      - fan.turn_on: 
          id: ${hostid}_fanid
          speed: low

sensor:
  - platform: pulse_width
    pin: D2
    id: ${hostid}_speed
    name: ${hostname} Speed
    update_interval: 15s

fan:
  - platform: speed
    id: ${hostid}_fanid
    name: ${hostname}
    output: ${hostid}_fan_speed

output:
 - platform: esp8266_pwm
   pin: D3
   frequency: 25000 Hz
   id: ${hostid}_fan_speed

Log shows:
[D][sensor:092]: 'Fireplace Fan Speed': Sending state 0.00000 s with 3 decimals of accuracy

I have D2 connected directly to the sensor pin at the CPU fan (the Wemos D1 mini uses common gound with the fan).

Am I missing something here?

Most CPU fan sensors are open drain / open collector. So you need a pull up resistor to convert the pulsed connections to ground to a voltage that the ESP can detect. Try:

sensor:
  - platform: pulse_width
    pin: 
      number: D2
      mode: INPUT_PULLUP
    id: ${hostid}_speed
    name: ${hostname} Speed
    update_interval: 15s

You probably also want the pulse counter not pulse width, and you may have to scale the result to get RPM.

e.g. Noctua fans output 2 pulses per rotation. Thus if using one of their fans you would need this to get RPM:

sensor:
  - platform: pulse_counter
    pin: 
      number: D2
      mode: INPUT_PULLUP
    unit_of_measurement: 'RPM'
    id: ${hostid}_speed
    name: ${hostname} Speed
    filters:
      - multiply: 0.5
1 Like

Thanks!

For test I’m unsung an intel stock fan. But the real application will use a noctua fan from their industri-series (powerful but more noisy).

But the resistor, I guess it’s not just a yaml change. I need a physical resistor also? What value and how to connect?.. :grinning:

Just tried without any additional hardware, It seems to be working… :slight_smile: I’ll try to verify the speed…

Yes it is just a yaml change, as per my post above. The software enabled internal resistor will be fine for this application.

1 Like