I’m working on a project that on the face of it seems pretty simple:
ESP32 (ESP32_DevkitC_V4)
BME280 (using I2C)
Display (1602A with I2C)
PWM (HW-517)
12v computer fan
I want to take the humidity reading of the BME280 and depending on the reading, make the fan speed up or slow down. I think I’m close but close isn’t on target. I’ve given up on having the fan use a sliding scale (like one would use for dimming an LED bulb) because it was taking way too much time and going nowhere and for this project, it is unnecessary. I did want to learn that though so I could reuse the code to make an artificial sunrise and sunset for my chicken coop over winter.
Back to the fan. I cannot seem to generate YAML code that ESPhome will take and upload. I’ve searched online but there seem to be holes in the documentation regarding use of the speed setting in the Speed Fan. Here is what I have:
i2c:
sda: GPIO21
scl: GPIO22
scan: True
sensor:
- platform: bme280
temperature:
name: "Weedbox Temperature"
id: weed_temperature
oversampling: 16x
pressure:
name: "Weedbox Pressure"
id: weed_pressure
humidity:
name: "Weedbox Humidity"
id: weed_humidity
filters:
offset: -0
on_value_range:
- below: 30
then:
- fan.turn_off: weed_fan
- above: 30.1
below: 30.5
then:
- fan.turn_on: weed_fan
speed: low
- above: 30.6
below: 31
then:
- fan.turn_on: weed_fan
speed: medium
- above: 31.1
then:
- fan.turn_on: weed_fan
speed: high
address: 0x76
update_interval: 60s
- platform: wifi_signal
name: "Weedbox Wifi Signal"
id: weedbox_wifi_signal
update_interval: 60s
force_update: false
unit_of_measurement: dB
icon: mdi:wifi
accuracy_decimals: 0
- platform: uptime
name: "Weedbox Uptime"
id: weed_uptime
filters:
lambda: return x / 3600;
output:
- platform: ledc
pin: GPIO19
id: weed_pwm
fan:
- platform: speed
output: weed_pwm
name: "Weed Fan"
id: weed_fan
speed:
low: 0.33
medium: 0.66
high: 1
binary_sensor:
- platform: status
name: "Weedbox Status"
text_sensor:
- platform: wifi_info
mac_address:
name: "Weedbox Mac Address"
icon: mdi:network
switch:
- platform: restart
name: "Weedbox Restart"
display:
- platform: lcd_pcf8574
dimensions: 16x2
address: 0x27
lambda: |-
it.printf(0, 0, "T:%.1f", id(weed_temperature).state);
it.printf(8, 0, "H:%.1f", id(weed_humidity).state);
it.printf(0, 1, "U:%.1f", id(weed_uptime).state);
it.printf(8, 1, "F:%.0f", id(weed_fan).state);
The errors seem to be here:
then:
- fan.turn_on: weed_fan
speed: low
with ESPhome complaining that I can’t have ‘fan.turn_on’ and ‘speed:’ in the same block but I can’t figure out how to set the speed of the fan any other way.
I should add that for this project, I want to stay away from using Home Assistant as part of the solution as I have some other ESP projects that I want to use the code on where they will not be part of a HA system. The automation needs to run on the ESP32, not on HA.
As a bonus question, I’d like to have the display show the fan state (off, low, medium, high) in the last line of code. At present, it doesn’t do that but I have to solve the upstream problem first.