Iām still working on the needed circuit to provide 5V PWM signal to the fans. Transistor and resistors only just arrived this evening.
There is one 3v3 relay to switch the 12VDC power to the fans on and off. There is a DHT22 temperature sensor to determine the current ambient/air temperature in the cabinet. Based on temperature ranges (in degrees Fahrenheit, US units of measure) the power relay is turned on when needed, and off when not. Four speeds (not including off) are: Low (25% PWM), Medium (50% PWM), High (75% PWM), and Maximum (100% PWM).
Here is the current YAML, using a BMP280 I2C device for temperature instead of the DHT22.
Itās a Wemos D1 Mini ESP8266 device. Pin D5 controls the power relay for 12VDC to the fans. Pin D6 is the PWM control line to the fans. It will be connected to an BC548 NPN transistor to switch the 5VDC from the Wemos D1 Mini as a PWM signal to the fans. This is necessary because the default PWM signal is only a 3v3 level, and computer fans expect 5v PWM signals. Pins D1 and D2 are used for the I2C signals from the BMP280. Switching to a DHT22 removes the I2C requirement and frees those two pins.
Hope this helps you in the current time.
switch:
- platform: template
id: fan_speed_off
turn_on_action:
- logger.log:
format: "The temperature sensor reports value %.1f, fans are OFF"
args: [ 'id(rack_temp_f).state' ]
- lambda: |-
id(rack_fan_speed).publish_state("Off");
- output.turn_off:
id: fan_power
- fan.turn_off:
id: fan_pwm
- platform: template
id: fan_speed_low
turn_on_action:
- logger.log:
format: "The temperature sensor reports value %.1f, fans are LOW"
args: [ 'id(rack_temp_f).state' ]
- lambda: |-
id(rack_fan_speed).publish_state("Low");
- fan.turn_on:
id: fan_pwm
speed: 25
- output.turn_on:
id: fan_power
- platform: template
id: fan_speed_medium
turn_on_action:
- logger.log:
format: "The temperature sensor reports value %.1f, fans are MEDIUM"
args: [ 'id(rack_temp_f).state' ]
- lambda: |-
id(rack_fan_speed).publish_state("Medium");
- fan.turn_on:
id: fan_pwm
speed: 50
- output.turn_on:
id: fan_power
- platform: template
id: fan_speed_high
turn_on_action:
- logger.log:
format: "The temperature sensor reports value %.1f, fans are HIGH"
args: [ 'id(rack_temp_f).state' ]
- lambda: |-
id(rack_fan_speed).publish_state("High");
- fan.turn_on:
id: fan_pwm
speed: 75
- output.turn_on:
id: fan_power
- platform: template
id: fan_speed_max
turn_on_action:
- logger.log:
format: "The temperature sensor reports value %.1f, fans are MAXIMUM"
args: [ 'id(rack_temp_f).state' ]
- lambda: |-
id(rack_fan_speed).publish_state("MAXIMUM");
- fan.turn_on:
id: fan_pwm
speed: 100
- output.turn_on:
id: fan_power
sensor:
- platform: bmp280
update_interval: 60s
address: 0x76
temperature:
id: rack_temp_f
name: "Rack Temperature"
unit_of_measurement: "°F"
filters:
lambda: |-
return (x * 1.8) + 32.0;
on_value_range:
- below: 75.0
then:
switch.turn_on: fan_speed_off
- above: 75.1
below: 77.0
then:
switch.turn_on: fan_speed_low
- above: 77.1
below: 79.0
then:
switch.turn_on: fan_speed_medium
- above: 79.1
below: 80.0
then:
switch.turn_on: fan_speed_high
- above: 80.1
then:
switch.turn_on: fan_speed_max
pressure:
id: rack_pressure
name: "Rack Pressure"
unit_of_measurement: "in"
filters:
lambda: |-
return (x * 0.02953);
#
# Text sensor provides literal speed
# Off / Low / Medium / High / MAXIMUM
#
text_sensor:
platform: template
id: rack_fan_speed
name: "Rack Fan Speed"
#
# fan_power is a relay switching 12VDC fan power on and off
# pwm_output is a speed control line to the PWM fan
#
output:
- platform: gpio
pin: D5
id: fan_power
- platform: esp8266_pwm
pin: D6
frequency: 500 Hz
id: pwm_output
#
# The fan object
#
fan:
- platform: speed
id: fan_pwm
name: "Rack Fan PWM"
output: pwm_output
speed_count: 100
restore_mode: ALWAYS_OFF