Water Tank Level and Water Volume with ESPHome

I thought you were talking about the pressure sensor!?
Of course i’ve read that documentation, but again I am using a 1118, and not much documentation. I was told they were the same …but they are not… i found my way though.

i think that i would get better results if I could get more info about the actual sensor, the pressure sensor!

;’)

Yes it would be good if you have the documentation of your sensor, but it is not necessary. You can instead test what voltages you get at various depths.
My reference to documentation was for your question on the gain factor :wink:

so what else would you need appart from the voltage measures that i already provided then, you lost me a little…

/fab

Well basically if I understand correctly in your case the max voltage you will be reading is 0.730v.
So based on the documentation I think you should set a gain factor of 1.024

ok cool, but from voltage how do I get to the desired volume or percentage: I know I’m that bad in maths…

This code will get you a sensor which shows the centimeters:

  - platform: template
    name: "CM"
    id: watertank_cm
    icon: 'mdi:water-well'
    unit_of_measurement: 'cm'
    lambda: |-
        return id(watertank_voltage).state;
    update_interval: 1s #the delta filter will ensure it only sends values when something changes. 
    filters:
      - calibrate_linear:
          # Measured value of X volt maps to y cm
          - 0.464 -> 0
          - 0.994 -> 55.2
          - 1.424 -> 102.0
          - 1.818 -> 144.0
      - delta : 0.001 #only send the result if the difference with the last sent result is higher than this

This code will give you a percentage of how full your tank is:

- platform: template
    name: "usable %"
    id: watertank_percent
    icon: 'mdi:water-well'
    unit_of_measurement: '%'
    lambda: |-
        return id(watertank_cm).state / 165.0 * 100; 
      #divide by max water level height to get a percentage
    update_interval: 1s #the delta filter will ensure it only sends values when something changes. 
    filters:
      - delta : 0.001 #only send the result if the difference with the last sent result is higher than this

This code will give you the liters:

  - platform: template
    name: "usable liters"
    id: watertank_liter
    icon: 'mdi:water-well'
    unit_of_measurement: 'l'
    lambda: |-
        return id(watertank_cm).state / 100 * 3.14159265 * 1.13751599 * 1.13751599 * 1000.0;
      #height (meters) times pi times radius (meters) squared times 1000 gives liters. This works if your water tank is a cilinder shape. Otherwise you have to use different calculations.
    update_interval: 1s #the delta filter will ensure it only sends values when something changes. 
    filters:
      - delta : 0.001 #only send the result if the difference with the last sent result is higher than this
1 Like

where did you get the documentation, i didn’t get any with my sensor

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