I’m configuring a controller for my hydroponic tower and figured I’d share some of the ESPHome code for the sensors to give you a nice flat curve that can read for automations. Using a sliding window I found that getting a 30 minute average reading brought it all together. Anything more was too chaotic of a sample rate. I have the Water Level sensor dialed in, I will likely follow suit with the nutrient sensor but I just haven’t gotten there yet. Hopefully this helps someone out.
#TDS Sensor
sensor:
- platform: adc
pin: GPIO01
name: "TDS Sensor Voltage"
update_interval: 10s
attenuation: 12db
filters:
- lambda: |-
float voltage = x; //Raw ADC Voltage
float tds = (voltage * 1000) / 2; // Requires calibration using salt and distilled water
return tds;
unit_of_measurement: "ppm"
accuracy_decimals: 1
- platform: ultrasonic
trigger_pin: GPIO04
echo_pin: GPIO09
name: "Ultrasonic Distance"
update_interval: 10s
unit_of_measurement: µm
filters:
- lambda: "return x * 100.0;"
- sliding_window_moving_average:
window_size: 1800
send_every: 1800
timeout: 4.0m
accuracy_decimals: 2