Water Tank Level and Water Volume with ESPHome

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.

Did you get the timeout issue resolved? By default the pulse time used for Ultrasonic sensors is 10usec whereas these sensors need 20usec (from the spec sheets). I changed this parameter plus the timeout parameter (default is 2.0m), but I was getting erroneous readings with the HC-SR04 above 1.80m.

Full details here ESPHome water level sensor - #190 by Britespark.

No timeout errors since I made these changes months ago. Still to resolve in code the random readings I get when it’s actually raining (so the water surface is rippled) which really mess up the charts (negative levels and percentages creep in), and temperature stabilisation (tank level inflates a few percent through the day as it gets warmer).

Thanks, I didn’t know about the pulse time though it is in the docs I didn’t think to try it. I’ll give that try. Thanks for that. My tank is way smaller that 1.8m.

Hey, that seems to be working now. Thanks a lot.

No drama - glad to help.

1 Like

would you mind sharing your code because i’m getting exactly the same problems as you, me it’s 0.25m… kinda stuck on that number almost…

thanks

Remember de JSN-SR04T has a minimum measuring range which is about 20cm

BTW, here’s my code:

sensor:
  - platform: ultrasonic
    trigger_pin: D6
    echo_pin: D5
    name: 'Nivel cisterna'
    unit_of_measurement: 'm'
    accuracy_decimals: 2
    update_interval: 10s
    pulse_time: 20us
    timeout: 2.0m
    filters:
      - filter_out: nan