Hey community!
You know that sometimes you start out out with an idea and it rolls on and eventually you get so caught up in the journey that you can no longer see above the weeds? Yeah, that me right now.
The project seemed pretty simple on paper; I have a chamber that I want to control to some fairly tight tolerances in terms of temperature and humidity. I’ve got prototype hardware built using a fan and heater from a small space heater that runs 120v and I plan to control fan speed and heat output by having an ESP32 switch solid state relays. I can’t use PWM due to the 120v causing electrical noise and interference. Sensors are a pair of BME280, one for control and one as a reference in a different part of the box, mostly for testing purposes to make sure I don’t have hotspots or cold spots. Anyways, that’s the background…
I’ve mostly debugged the code except for one issue that is related to float vs binary outputs. What I would like to ask is for folks to take a look and tell me if the code can be improved. It is not going to interface with HA, I need this to run entirely standalone on an ESP32 and I’ll connect via a simple phone app.
i2c:
sda: GPIO21
scl: GPIO22
scan: True
sensor:
- platform: bme280
address: 0x76
temperature:
name: "Box Control Temperature"
id: box_control_temperature
oversampling: 16x
pressure:
name: "box Control Pressure"
id: box_control_pressure
humidity:
name: "Box Control Humidity"
id: box_control_humidity
- platform: bme280
address: 0x77
temperature:
name: "Box Reference Temperature"
oversampling: 16x
pressure:
name: "Box Reference Pressure"
oversampling: 16x
humidity:
name: "Box Reference Humidity"
update_interval: 60s
output:
- platform: gpio
pin: GPIO16
id: heater_ssr
- platform: gpio
pin: GPIO5
id: fan_ssr
switch:
- platform: output
name: "Heater SSR"
output: heater_ssr
- platform: output
name: "Fan SSR"
output: fan_ssr
fan:
- platform: speed
output: fan_ssr
name: "Heater Fan"
id: heater_fan
speed_count: 100
on_turn_on:
- output.turn_on: fan_ssr
on_turn_off:
- output.turn_off: fan_ssr
- platform: speed
output: heater_ssr
name: "Heater Element"
id: heater_element
speed_count: 100
on_turn_on:
- output.turn_on: heater_ssr
on_turn_off:
- output.turn_off: heater_ssr
interval:
- interval: 1min
then:
- lambda: |-
float desired_temp = 35.0;
float temp_tolerance = 0.5;
if (id(box_control_temperature).has_state() && id(box_control_humidity).has_state()) {
float temperature = id(box_control_temperature).state;
float humidity = id(box_control_humidity).state;
// Calculate box control temperature
float box_control_temperature = temperature + ((humidity - 50.0) / 5.0);
// Check if current temperature is below desired temperature minus tolerance
if (box_control_temperature < desired_temp - temp_tolerance) {
id(heater_fan).set_speed(50);
id(heater_ssr).turn_on();
} else {
id(heater_fan).turn_off();
id(heater_ssr).turn_off();
}
}