Water Tank Level and Water Volume with ESPHome

I just googled for it but the info in ESPHome also writes about it ADS1115 Sensor — ESPHome

still getting timed out all the time, i get no readings at all, even when i copied your conf.
I can’t be that unlucky to have bought 3 faulty sensors in a row… it must be something else. i’ll paste my esphome log and my config, maybe you’ll spot something I dont see.
thank you

esphome yaml config

esphome:
  name: ultrasonic_v2
  platform: ESP8266
  board: esp12e

wifi:
  ssid: "Netgear_dd"
  password: "kuhliughliugliugliug"

  manual_ip:
    static_ip: 192.168.1.142
    gateway: 192.168.1.1
    subnet: 255.255.255.0
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Ultrasonic Fallback Hotspot"
    password: "zn1Rae47TCt9"

captive_portal:

web_server:
  port: 80

# Enable logging
logger:


# Enable Home Assistant API
api:
  password: "iugoiugliugliug"

ota:
  password: ";iughlih;oij'opk"
  
sensor: 

  - platform: uptime
    name: "irrigation System Uptime"
    
  - platform: wifi_signal
    name: "WiFi Signal Sensor"
    update_interval: 60s
    
  - platform: ultrasonic
    trigger_pin: GPIO 1
    echo_pin: GPIO 3
    name: 'us water distance'
    id: dist2water
    unit_of_measurement: 'm'
    accuracy_decimals: 3
    update_interval: 1s
    pulse_time: 10us
    timeout: 2.0m
    filters:
      - filter_out: nan
      
  - platform: ultrasonic
    trigger_pin: GPIO 1
    echo_pin: GPIO 3
    name: "us water percentage"
    unit_of_measurement: '%'
    accuracy_decimals: 3
    update_interval: 2s
    pulse_time: 30us
    timeout: 4.0m
    icon: mdi:water-percent
    filters:
      - lambda: return ((((x*100)-26)-(66-26))/(66-26))*-100;
      - filter_out: nan
      - sliding_window_moving_average:
          window_size: 10 #creates a moving average of the last 10 values
          send_every: 1 #sends the moving average at every measurement (but only if it passes the delta filter below)) 
          send_first_at: 1 #after startup immediately start sending the result rather than wait for the first 10 measurements
      - delta : 0.5
      
  - platform: ultrasonic
    trigger_pin: GPIO 1
    echo_pin: GPIO 3
    name: "us water Volume"
    unit_of_measurement: 'l'
    icon: mdi:cup-water
    accuracy_decimals: 2
    update_interval: 5s
    pulse_time: 20us
    timeout: 6.0m
    filters:
      - lambda: return ((((x*100)-26)-(66-26))/(66-26))*-70;
      - filter_out: nan  
      
  - platform: pulse_counter
    pin: 02
    name: "Pulse Counter"
    update_interval: 2s
    filters:
      - lambda: return x / 450.0;
    unit_of_measurement: 'L/min'

  - platform: "pulse_counter"
    name: "flowrate potager"
    id: rsi_potager
    pin: 02
    update_interval: 2s
    filters:
    - lambda: return (x / 7.5);
    unit_of_measurement: "L/min"
  - platform: pulse_counter
    pin: 02
    name: "Pulse Counter"

esphome log from that node

INFO Reading configuration /config/esphome/ultrasonic.yaml...
INFO Generating C++ source...
INFO Compiling app...
INFO Running:  platformio run -d /config/esphome/ultrasonic_v2
Processing ultrasonic_v2 (board: esp12e; framework: arduino; platform: platformio/[email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES: 
 - framework-arduinoespressif8266 3.20704.0 (2.7.4) 
 - tool-esptool 1.413.0 (4.13) 
 - tool-esptoolpy 1.20800.0 (2.8.0) 
 - toolchain-xtensa 2.40802.200502 (4.8.2)
Library Manager: Installing Update
Library Manager: Already installed, built-in library
Dependency Graph
|-- <ESPAsyncTCP-esphome> 1.2.3
|   |-- <ESP8266WiFi> 1.0
|-- <ESPAsyncWebServer-esphome> 1.2.7
|   |-- <ESPAsyncTCP-esphome> 1.2.3
|   |   |-- <ESP8266WiFi> 1.0
|   |-- <Hash> 1.0
|   |-- <ESP8266WiFi> 1.0
|   |-- <ArduinoJson-esphomelib> 5.13.3
|-- <ESP8266WiFi> 1.0
|-- <ESP8266mDNS> 1.2
|   |-- <ESP8266WiFi> 1.0
|-- <ArduinoJson-esphomelib> 5.13.3
|-- <DNSServer> 1.1.1
|   |-- <ESP8266WiFi> 1.0
Retrieving maximum program size /data/ultrasonic_v2/.pioenvs/ultrasonic_v2/firmware.elf
Checking size /data/ultrasonic_v2/.pioenvs/ultrasonic_v2/firmware.elf
RAM:   [=====     ]  46.5% (used 38116 bytes from 81920 bytes)
Flash: [====      ]  41.3% (used 431468 bytes from 1044464 bytes)
========================= [SUCCESS] Took 13.83 seconds =========================
INFO Successfully compiled program.
INFO Connecting to 192.168.1.142
INFO Uploading /data/ultrasonic_v2/.pioenvs/ultrasonic_v2/firmware.bin (435616 bytes)
Uploading: [============================================================] 100% Done...

INFO Waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from 192.168.1.142 using esphome API
INFO Connecting to 192.168.1.142:6053 (192.168.1.142)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error connecting to 192.168.1.142: timed out). Re-Trying in 1 seconds
INFO Connecting to 192.168.1.142:6053 (192.168.1.142)
INFO Successfully connected to 192.168.1.142
[05:58:15][I][app:105]: ESPHome version 1.18.0 compiled on Jun  6 2021, 04:14:45
[05:58:15][C][wifi:443]: WiFi:
[05:58:15][C][wifi:303]:   SSID: [redacted]
[05:58:15][C][wifi:304]:   IP Address: 192.168.1.142
[05:58:15][C][wifi:306]:   BSSID: [redacted]
[05:58:15][C][wifi:307]:   Hostname: 'ultrasonic_v2'
[05:58:15][C][wifi:311]:   Signal strength: -58 dB ▂▄▆█
[05:58:15][C][wifi:315]:   Channel: 6
[05:58:15][C][wifi:316]:   Subnet: 255.255.255.0
[05:58:15][C][wifi:317]:   Gateway: 192.168.1.1
[05:58:15][C][wifi:318]:   DNS1: (IP unset)
[05:58:15][C][wifi:319]:   DNS2: (IP unset)
[05:58:15][C][uptime.sensor:030]: Uptime Sensor 'irrigation System Uptime'
[05:58:15][C][uptime.sensor:030]:   Unit of Measurement: 's'
[05:58:15][C][uptime.sensor:030]:   Accuracy Decimals: 0
[05:58:15][C][uptime.sensor:030]:   Icon: 'mdi:timer-outline'
[05:58:15][C][logger:189]: Logger:
[05:58:15][C][logger:190]:   Level: DEBUG
[05:58:15][C][logger:191]:   Log Baud Rate: 115200
[05:58:15][C][logger:192]:   Hardware UART: UART0
[05:58:15][C][ultrasonic.sensor:035]: Ultrasonic Sensor 'ultrasonic water distance'
[05:58:15][C][ultrasonic.sensor:035]:   Unit of Measurement: 'm'
[05:58:15][C][ultrasonic.sensor:035]:   Accuracy Decimals: 3
[05:58:15][C][ultrasonic.sensor:035]:   Icon: 'mdi:arrow-expand-vertical'
[05:58:15][C][ultrasonic.sensor:036]:   Echo Pin: GPIO3 (Mode: INPUT)
[05:58:15][C][ultrasonic.sensor:037]:   Trigger Pin: GPIO1 (Mode: OUTPUT)
[05:58:15][C][ultrasonic.sensor:038]:   Pulse time: 20 µs
[05:58:15][C][ultrasonic.sensor:039]:   Timeout: 11661 µs
[05:58:15][C][ultrasonic.sensor:040]:   Update Interval: 5.0s
[05:58:15][C][ultrasonic.sensor:035]: Ultrasonic Sensor 'Ultrasonic Sensor Level'
[05:58:15][C][ultrasonic.sensor:035]:   Unit of Measurement: '%'
[05:58:15][C][ultrasonic.sensor:035]:   Accuracy Decimals: 3
[05:58:15][C][ultrasonic.sensor:035]:   Icon: 'mdi:water-percent'
[05:58:15][C][ultrasonic.sensor:036]:   Echo Pin: GPIO3 (Mode: INPUT)
[05:58:15][C][ultrasonic.sensor:037]:   Trigger Pin: GPIO1 (Mode: OUTPUT)
[05:58:15][C][ultrasonic.sensor:038]:   Pulse time: 20 µs
[05:58:15][C][ultrasonic.sensor:039]:   Timeout: 11661 µs
[05:58:15][C][ultrasonic.sensor:040]:   Update Interval: 5.0s
[05:58:15][D][pulse_counter:159]: 'flowrate potager': Retrieved counter: 0.00 pulses/min
[05:58:15][D][sensor:099]: 'flowrate potager': Sending state 0.00000 L/min with 2 decimals of accuracy
[05:58:15][C][ultrasonic.sensor:035]: Ultrasonic Sensor 'Ultrasonic Sensor Volume'
[05:58:15][C][ultrasonic.sensor:035]:   Unit of Measurement: 'l'
[05:58:15][C][ultrasonic.sensor:035]:   Accuracy Decimals: 2
[05:58:15][C][ultrasonic.sensor:035]:   Icon: 'mdi:cup-water'
[05:58:15][C][ultrasonic.sensor:036]:   Echo Pin: GPIO3 (Mode: INPUT)
[05:58:15][C][ultrasonic.sensor:037]:   Trigger Pin: GPIO1 (Mode: OUTPUT)
[05:58:15][C][ultrasonic.sensor:038]:   Pulse time: 20 µs
[05:58:15][C][ultrasonic.sensor:039]:   Timeout: 11661 µs
[05:58:15][C][ultrasonic.sensor:040]:   Update Interval: 5.0s
[05:58:15][C][pulse_counter:147]: Pulse Counter 'Pulse Counter'
[05:58:15][C][pulse_counter:147]:   Unit of Measurement: 'L/min'
[05:58:15][C][pulse_counter:147]:   Accuracy Decimals: 2
[05:58:15][C][pulse_counter:147]:   Icon: 'mdi:pulse'
[05:58:15][C][pulse_counter:148]:   Pin: GPIO2 (Mode: INPUT)
[05:58:15][C][pulse_counter:149]:   Rising Edge: INCREMENT
[05:58:15][C][pulse_counter:150]:   Falling Edge: DISABLE
[05:58:15][C][pulse_counter:151]:   Filtering pulses shorter than 13 µs
[05:58:15][C][pulse_counter:152]:   Update Interval: 2.0s
[05:58:15][C][pulse_counter:147]: Pulse Counter 'flowrate potager'
[05:58:15][C][pulse_counter:147]:   Unit of Measurement: 'L/min'
[05:58:15][C][pulse_counter:147]:   Accuracy Decimals: 2
[05:58:15][C][pulse_counter:147]:   Icon: 'mdi:pulse'
[05:58:15][C][pulse_counter:148]:   Pin: GPIO2 (Mode: INPUT)
[05:58:15][C][pulse_counter:149]:   Rising Edge: INCREMENT
[05:58:15][C][pulse_counter:150]:   Falling Edge: DISABLE
[05:58:15][C][pulse_counter:151]:   Filtering pulses shorter than 13 µs
[05:58:15][C][pulse_counter:152]:   Update Interval: 2.0s
[05:58:15][C][pulse_counter:147]: Pulse Counter 'Pulse Counter'
[05:58:15][C][pulse_counter:147]:   Unit of Measurement: 'pulses/min'
[05:58:15][C][pulse_counter:147]:   Accuracy Decimals: 2
[05:58:15][C][pulse_counter:147]:   Icon: 'mdi:pulse'
[05:58:15][C][pulse_counter:148]:   Pin: GPIO2 (Mode: INPUT)
[05:58:15][C][pulse_counter:149]:   Rising Edge: INCREMENT
[05:58:15][C][pulse_counter:150]:   Falling Edge: DISABLE
[05:58:15][C][pulse_counter:151]:   Filtering pulses shorter than 13 µs
[05:58:15][C][pulse_counter:152]:   Update Interval: 60.0s
[05:58:15][C][captive_portal:169]: Captive Portal:
[05:58:15][C][web_server:136]: Web Server:
[05:58:15][C][web_server:137]:   Address: 192.168.1.142:80
[05:58:15][C][ota:029]: Over-The-Air Updates:
[05:58:15][C][ota:030]:   Address: 192.168.1.142:8266
[05:58:15][C][ota:032]:   Using Password.
[05:58:15][D][ultrasonic.sensor:026]: 'Ultrasonic Sensor Volume' - Distance measurement timed out!
[05:58:15][C][api:095]: API Server:
[05:58:15][C][api:096]:   Address: 192.168.1.142:6053
[05:58:16][C][wifi_signal.sensor:009]: WiFi Signal 'WiFi Signal Sensor'
[05:58:16][C][wifi_signal.sensor:009]:   Device Class: 'signal_strength'
[05:58:16][C][wifi_signal.sensor:009]:   Unit of Measurement: 'dBm'
[05:58:16][C][wifi_signal.sensor:009]:   Accuracy Decimals: 0
[05:58:16][D][pulse_counter:159]: 'Pulse Counter': Retrieved counter: 0.00 pulses/min
[05:58:16][D][sensor:099]: 'Pulse Counter': Sending state 0.00000 L/min with 2 decimals of accuracy
[05:58:17][D][pulse_counter:159]: 'flowrate potager': Retrieved counter: 0.00 pulses/min
[05:58:17][D][sensor:099]: 'flowrate potager': Sending state 0.00000 L/min with 2 decimals of accuracy
[05:58:18][D][pulse_counter:159]: 'Pulse Counter': Retrieved counter: 0.00 pulses/min
[05:58:18][D][sensor:099]: 'Pulse Counter': Sending state 0.00000 L/min with 2 decimals of accuracy
[05:58:19][D][ultrasonic.sensor:026]: 'ultrasonic water distance' - Distance measurement timed out!
[05:58:19][D][pulse_counter:159]: 'flowrate potager': Retrieved counter: 0.00 pulses/min
[05:58:19][D][sensor:099]: 'flowrate potager': Sending state 0.00000 L/min with 2 decimals of accuracy
[05:58:19][D][ultrasonic.sensor:026]: 'Ultrasonic Sensor Level' - Distance measurement timed out!
[05:58:20][D][pulse_counter:159]: 'Pulse Counter': Retrieved counter: 0.00 pulses/min
[05:58:20][D][sensor:099]: 'Pulse Counter': Sending state 0.00000 L/min with 2 decimals of accuracy
[05:58:20][D][ultrasonic.sensor:026]: 'Ultrasonic Sensor Volume' - Distance measurement timed out!
[05:58:21][D][pulse_counter:159]: 'flowrate potager': Retrieved counter: 0.00 pulses/min
[05:58:21][D][sensor:099]: 'flowrate potager': Sending state 0.00000 L/min with 2 decimals of accuracy
[05:58:22][D][pulse_counter:159]: 'Pulse Counter': Retrieved counter: 0.00 pulses/min
[05:58:22][D][sensor:099]: 'Pulse Counter': Sending state 0.00000 L/min with 2 decimals of accuracy
[05:58:23][D][pulse_counter:159]: 'flowrate potager': Retrieved counter: 0.00 pulses/min
[05:58:23][D][sensor:099]: 'flowrate potager': Sending state 0.00000 L/min with 2 decimals of accuracy
[05:58:24][D][ultrasonic.sensor:026]: 'ultrasonic water distance' - Distance measurement timed out!
[05:58:24][D][pulse_counter:159]: 'Pulse Counter': Retrieved counter: 0.00 pulses/min
[05:58:24][D][sensor:099]: 'Pulse Counter': Sending state 0.00000 L/min with 2 decimals of accuracy
[05:58:24][D][ultrasonic.sensor:026]: 'Ultrasonic Sensor Level' - Distance measurement timed out!
[05:58:25][D][pulse_counter:159]: 'flowrate potager': Retrieved counter: 0.00 pulses/min

For the Ultrasonic sensor i’m guessing that this is my problem: “Filtering pulses shorter than 13 µs”
for the flowrate sensor and the pressure sensor, they were working earlier but it just stopped, maybe i should just keep one “- platform:” for each… anyways, one problem at a time.

anyone notice something wrong in there, cuz it aint working, and it was before, i am starting to freak out!

2 Likes

Oh yeah I know i’ve gotten all the info I need for this one but not the 1118, I am using the 1115 with the pressure sensor

Yes I’m also using the 1115

I wonder why my numbers fluctuate this much?
Screen Shot 2021-06-06 at 11.58.42 AM
Screen Shot 2021-06-06 at 5.18.01 AM
that was all day and pump was turned on twice only!

any help is obviously welcomed!

how did you obtain this info, I want to know how you ended up with these numbers, i am lost a little bit as ti where does this info come from? I would like to be able to get it myself to understand how to get it etc…

I realise there’s two simultaneous discussions in this thread.
#1 The ADS1115 + pressure sensor without documentation at all to get volts to then get volume etc…
#2 The JSN SR04T - 2.0 to actually get the same information.
which one should I keep here and which one should I start a different thread?

Hello, Did you solve the problem, time out…

you forgot in the code timeout: 2.5m the max is 4.0m (eter)

No i never got it working proprely, i mean its measuring voltage, but i cant figure out the way to accurately get then volume from it.

what do you mean:
i forgot 2.4 the max is 4??

you noticed an error in my code?

I’m just about to build something similar.

Let me see if I got it right:

2 Likes

Hello, i’ve tried same configuration and have same problem of distance Time Out. I only have one ultrasonic sensor, si the problem could be the sensor itself. I might give a try at HC-SR04 sensor but as i will use or for water level purpose outsider of the house water resistant might be mandatory

For those following this thread - try the solutions offered at the following thread.
ESPHome water level sensor

I switched to HC-SR04 sensor, and it’s working flawlessly. The problem was the sensor. So i’ll go with the non-water resistant one for now and will see how much time it will work.

1 Like

Hi @silb , can you share your config

Regards

Morning

Is it possible for some to take a look at my setup I can’t get it working.

I have a esp32 board and jsn sr04t connected to GPIO 17 and 16 i’m getting reading back from the sensor but it saying that my water butt (x2) is full

Water Tank Level 102 %
Water Tank Volume 429 l

TD is 91cm
EX is 20cm
Total liters 210 per water butt (I have 2 connected together)

My code is below, I have also tried to replace the sensor with another jsn sr04t but got the same results.

any help would be much appreciated.

binary_sensor:
  - platform: gpio
    pin: GPIO2
    name: "Water Pump Button"    
    on_press:
      then:
        - switch.toggle: waterpump
        
switch:
  - platform: gpio
    pin: GPIO27
    name: "Water Pump"
    id: waterpump
    restore_mode: RESTORE_DEFAULT_OFF
    
    
text_sensor:
  - platform: version
    name: "${device_name} ESPHome Version"
  - platform: wifi_info
    ip_address:
      name: "${device_name} ip"
    ssid:
      name: "${device_name} ssid"
  - platform: homeassistant
    id: pumprunning
    entity_id: switch.vandsten
    internal: true
    
sensor:  
  - platform: wifi_signal
    name: '${device_name} WiFi Signal'
    update_interval: 60s
    accuracy_decimals: 0
  - platform: uptime
    name: '${device_name} Uptime'
    unit_of_measurement: days
    update_interval: 300s
    accuracy_decimals: 1
    filters:
      - multiply: 0.000011574
      
  - platform: ultrasonic
    trigger_pin: GPIO17
    echo_pin: GPIO16
    name: "Water Tank Level"
    unit_of_measurement: "%"
    accuracy_decimals: 0
    update_interval: 30s
    filters:
      - lambda: return ((((x*100)-20)-(91-20))/(91-20))*-100;
      - filter_out: nan
      
  - platform: ultrasonic
    trigger_pin: GPIO17
    echo_pin: GPIO16
    update_interval: 30s
    name: "Water Tank Volume"
    unit_of_measurement: "l"
    accuracy_decimals: 0
    filters:
      - lambda: return ((((x*100)-20)-(91-20))/(91-20))*-420;
      - filter_out: nan

Hey guys,

Was thinking of implementing something similar with ESP-home. Re the weatherproof sensor that has been used, I am wondering if this is the same sort of thing and/or would it work with esp-home?

https://www.dfrobot.com/product-1503.html

Looks very similar…

1 Like

That’s the one

1 Like

Great thanks.

Can’t say I’ve found this successful. Sensor seems to under report distance. Sensor reads 0.23m where the actual distance is 0.5m. Randomly reports 0.23m when the actual distance is 1.8m. Adjusting the potentiometer doesn’t seem to have any effect.

I swapped the pins to GPIO’s 1 & 3 as per the original post. Seems much more stable now.

Checking the logs, there is one thing I’m curious about. I get a time outs from ultrasonic.sensor:026 while I receive correct reports from ultrasonic.sensor:030. Not sure why I have two sensors when there is only one specified in the config. Here’s a log extract.

[10:37:12][D][ultrasonic.sensor:026]: 'Tank Level' - Distance measurement timed out!
[10:37:17][D][ultrasonic.sensor:030]: 'Tank Level' - Got distance: 1.78 m
[10:37:17][D][sensor:131]: 'Tank Level': Sending state 1.77708 m with 1 decimals of accuracy
[10:37:22][D][ultrasonic.sensor:026]: 'Tank Level' - Distance measurement timed out!
[10:37:27][D][ultrasonic.sensor:030]: 'Tank Level' - Got distance: 1.78 m
[10:37:27][D][sensor:131]: 'Tank Level': Sending state 1.78103 m with 1 decimals of accuracy
[10:37:32][D][ultrasonic.sensor:030]: 'Tank Level' - Got distance: 1.78 m

Can anyone shed some light on this?

Still reports 0.23m randomly for some reason though…


Thanks.

Hello Omar, maybe my question is stupid, but I will ask it. Is the code in question for the ESPhome platform?

Thank you and congratulations for making this post available, as the sensor I bought from TUYA did not meet my needs.