Skip to content

Instantly share code, notes, and snippets.

@gregmac
Last active June 23, 2022 01:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregmac/e0d4e678efb4b835edb319bab81c4aa4 to your computer and use it in GitHub Desktop.
Save gregmac/e0d4e678efb4b835edb319bab81c4aa4 to your computer and use it in GitHub Desktop.
esphome ESP32 Water Level Sensor

Sump pit water level sensor

This is an ESPHome configuration for an ESP32 that monitors a sump pump pit, using the ESP32 capacitive touch sensors, with a level being reported to Home Assistant.

ESP32 Wiring

The ESP32 is mounted on a piece of PVC pipe, with wires extending down to different lengths. I used a length of old ethernet cable I had sitting around.

There's also a wire at the bottom connected to the ground pin, and this gives more reliable touch sensor values. The USB32 is powered from USB.

Pin Touch Color Depth
GPIO32 touch9 white/blue 45cm
GPIO33 touch8 blue 40cm
GPIO27 touch7 white/blue 35cm
GPIO14 touch6 green 30cm
GPIO12 touch5 white/green 25cm
GPIO13 touch4 brown 20cm
GPIO15 touch3 white/brown 15cm
GPIO4 touch0 orange 10cm
GND white/orange
substitutions:
name: sump_pit
display_name: Basement Sump Pit
touch_threshold: "750"
esphome:
name: $name
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
password: "xxxxxxxxxxxxxxxx"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "$name"
password: "xxxxxxxxx"
captive_portal:
status_led:
pin: GPIO2
esp32_touch:
setup_mode: false
binary_sensor:
- platform: esp32_touch
id: touch0
pin: GPIO4
threshold: $touch_threshold
on_state:
then:
- component.update: level_numeric
# GPIO0 (touch1) isn't available
# GPIO2 (touch2) is LED
- platform: esp32_touch
id: touch3
pin: GPIO15
threshold: $touch_threshold
on_state:
then:
- component.update: level_numeric
- platform: esp32_touch
id: touch4
pin: GPIO13
threshold: $touch_threshold
on_state:
then:
- component.update: level_numeric
- platform: esp32_touch
id: touch5
pin: GPIO12
threshold: $touch_threshold
on_state:
then:
- component.update: level_numeric
- platform: esp32_touch
id: touch6
pin: GPIO14
threshold: $touch_threshold
on_state:
then:
- component.update: level_numeric
- platform: esp32_touch
id: touch7
pin: GPIO27
threshold: $touch_threshold
on_state:
then:
- component.update: level_numeric
- platform: esp32_touch
id: touch8
pin: GPIO33
threshold: $touch_threshold
on_state:
then:
- component.update: level_numeric
- platform: esp32_touch
id: touch9
pin: GPIO32
threshold: $touch_threshold
on_state:
then:
- component.update: level_numeric
sensor:
- platform: template
name: "$name Level"
id: level_numeric
unit_of_measurement: cm
lambda: |-
if (id(touch9).state) { return 45; }
if (id(touch8).state) { return 40; }
if (id(touch7).state) { return 35; }
if (id(touch6).state) { return 30; }
if (id(touch5).state) { return 25; }
if (id(touch4).state) { return 20; }
if (id(touch3).state) { return 15; }
if (id(touch0).state) { return 10; }
return 0;
- platform: wifi_signal
name: "$name WiFi Signal Sensor"
update_interval: 60s
text_sensor:
- platform: wifi_info
ip_address:
name: "$name IP Address"
- platform: version
name: "$name ESPHome Version"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment