Hello everyone!
Share a little ESPHome project to control 4-pin PWM FAN.
Goal
- Control the fan speed by fan PWM.
- Ability to turn off the fan.
- Read RPM data from the fan.
Common PWN FAN doesn’t stop on 0% PWM signal and still running on minimum RPM. It is possible to control the fan speed not by fan PWM, but by PWM of DC input. In that case the fan can be stopped, but RPM data from the fan is messed up.
We will start/stop the fan with a MOSFET and set the speed with the FAN PWM input signal.
https://github.com/nordeep/esphome_fan_controller
substitutions:
device_name: fanmaster
device_description: FanMaster Fan controller
friendly_name: fanmaster
esphome:
name: ${device_name}
comment: ${device_description}
platform: ESP8266
board: nodemcuv2
on_boot:
- priority: 200.0
then:
- output.set_level:
id: pwmfan
level: 100%
wifi:
ssid: !secret ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: ${friendly_name}_AP
password: !secret wifi_password
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
password: !secret api_password
# Enable OTA
ota:
password: !secret api_password
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: D6
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: D5
id: fan_supply
- platform: esp8266_pwm
pin: D7
frequency: 25000 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: 100%
A little bit trick to stop PWM fan is set 100% level of PWM on output after remove power.