Installing and configuring an ESP32, with a flow sensor into Home Assistant
ESP32 4 way Relay Board
https://amzn.to/3ZqxRWO
Documentation Reference:
https://templates.blakadder.com/assets/ESP12F_Relay_X4.pdf
GPIO pintouts as shown in the pic.
Flow Sensor
https://amzn.to/3ZmfRfW
Connect Flow sensor to 3.3v, Gnd and GPIO15
Connect Water Full sensor to GPIO01 and Gnd
Waste Full sensor to GPIO03 and Gnd
use Google Gemini AI, with this prompt : (or ammend to your requirements)
I'm creating a water tank fill level sensor for my campervan using ESPHome. I have a flow sensor connected to GPIO pin 15 with a calibration factor of 450 pulses per liter. The fresh water tank has a capacity of 90L and a full sensor connected to GPIO pin 12. The waste water tank has a capacity of 45L and a full sensor connected to GPIO pin 14.
Please provide an ESPHome configuration that:
Uses a pulse_counter to measure the flow from the sensor.
Calculates the water level in both tanks using template sensors.
Integrates the full sensors into the tank level calculations.
Sets the fresh water tank level to full when the full sensor is triggered.
Keeps the waste water tank level at zero until the full sensor is triggered or the estimated level reaches the tank's capacity.
The configuration should accurately track the water levels in both tanks based on the flow sensor data and the state of the full sensors."
binary_sensor:
###########################
# Tank Level Sensors
###########################
- platform: gpio
pin:
number: 01 # Replace with the actual pin for fresh water tank full sensor
mode: INPUT_PULLUP
name: "Fresh Water Tank Full"
id: fresh_water_tank_full
- platform: gpio
pin:
number: 03 # Replace with the actual pin for waste water tank full sensor
mode: INPUT_PULLUP
name: "Waste Water Tank Full"
id: waste_water_tank_full
sensor:
###########################
# Flow Sensor Pulse Counter
###########################
- platform: pulse_counter
pin:
number: 15
mode:
input: true
pullup: true
name: "Flow"
id: flow
unit_of_measurement: 'L/min'
accuracy_decimals: 2
update_interval: 1s
icon: "mdi:water"
filters:
# https://www.amazon.co.uk/dp/B07DVD4SKJ?ref=ppx_yo2ov_dt_b_fed_asin_title
- lambda: return (x/450);
- platform: integration
name: "Flow in m3"
unit_of_measurement: 'm³'
id: flow_m3
accuracy_decimals: 2
sensor: flow
time_unit: min
icon: "mdi:water"
filters:
- multiply: 0.001 # convert Liter to m³
- platform: integration
name: "Flow in Liter"
id: flow_liter
unit_of_measurement: 'L'
accuracy_decimals: 2
sensor: flow
time_unit: min
icon: "mdi:water"
###########################
# Fresh Water Tank Level
###########################
- platform: template
name: "Fresh Water Tank Level"
id: fresh_water_tank_level
unit_of_measurement: 'L'
accuracy_decimals: 0
icon: "mdi:water-tank"
lambda: |-
static float fresh_water_level = 0.0; // Start with the tank empty
// Set level to full if the full sensor is triggered
if (id(fresh_water_tank_full).state) {
fresh_water_level = 91.0;
} else {
fresh_water_level += (id(flow).state * 60.0) / 1000.0; // Add flow in L/min converted to L/s
if (fresh_water_level >91.0) {
fresh_water_level = 91.0; // Cap at tank capacity
}
}
return fresh_water_level;
###########################
# Waste Water Tank Level
###########################
- platform: template
name: "Waste Water Tank Level"
id: waste_water_tank_level
unit_of_measurement: 'L'
accuracy_decimals: 0
icon: "mdi:water-tank-outline"
lambda: |-
static float waste_water_level = 0.0; // Start with the tank empty
// Set level to full only when the full sensor is triggered
if (id(waste_water_tank_full).state) {
waste_water_level = 66.0;
} else if (waste_water_level >= 45.0) { // Alternatively, set to full when estimated level reaches capacity
waste_water_level = 66.0;
} else {
waste_water_level += (id(flow).state * 60.0) / 1000.0; // Add flow in L/min converted to L/s
}
return waste_water_level;