In a previous blog post https://www.archy.net/waterlevelespha/ I was explaining how to monitor an IBC water reserve using ultra sound sensor and ESP32.
Since I used this solution, I had several drawback with the HC-SR04 component:
- It's not waterproof
- The measured value varies too much, the margin of error is too high even when averaging over several closely spaced measurements
Reading all around the internet what I could use to have precise measured data from the IBC water reserve I found that the JSN SR04T would probably do the trick.
This component is using ultra sound as well and have a separate controller with a very long and convenient cable until the sensor.
Still using an ESP8266 mini D1 :
Wiring
Connecting the ESP to the sensor by soldering files this way :
Using ESPHome in Home Assistant
There are several possibilities to generate code to upload it on a ESP(wemos). I chose to use ESPHome in Home Assistant which is simple :
Go to the ESPHome add-on in Home Assistant and create your Secrets if it has not been done yet
Secret Creation
Now it's time to define the secrets in ESPHome by clickinbg on secrets in the upper right corner
Fill with you personnal wifi information :
4. Code
Now the code to send the this new device needs to be written to be able to measure the level of water left in the IBC water tank
Let's click on the bottom right corner on + New Device :
Give it a name
Chose the device type
Then click on Install
As I plugged this ESP on my Home Assistant I chose the following
Chose the correct port to intiate the communication
and when it's done, we can proceed to the upload of the code by clicking on Edit of this new ESP device
You can paste the following code as it is :
esphome:
name: water_tank_level_sensor
platform: ESP8266
board: d1_mini
# WiFi connection, replace these with values for your WiFi.
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable logging
logger:
# Enable Home Assistant API
api:
# Enable over-the-air updates.
ota:
# Enable Web server.
web_server:
port: 80
# Sync time with Home Assistant.
time:
- platform: homeassistant
id: homeassistant_time
sensor:
# Wifi signal sensor.
- platform: wifi_signal
name: garden_watertank_wifi
update_interval: 300s
unit_of_measurement: '%'
filters:
- lambda: |-
if (x <= -100) {
return 0;
} else {
if (x >= -50) {
return 100;
} else {
return 2 * (x + 100);
}
}
- platform: ultrasonic
trigger_pin: D1
echo_pin: D2
name: "Water Tank Level"
unit_of_measurement: "%"
accuracy_decimals: 0
update_interval: 300s
filters:
- lambda: return ((((x*100)-4)-(100-4))/(100-4))*-100;
- filter_out: nan
- platform: ultrasonic
trigger_pin: D1
echo_pin: D2
update_interval: 300s
name: "Water Tank Volume"
unit_of_measurement: "l"
accuracy_decimals: 0
filters:
- lambda: return ((((x*100)-4)-(100-4))/(100-4))*-1000;
- filter_out: nan
The formula is based on a 100x100 cube water IBC reserve, which contain when full 1000L of water. The measure is taken every 300s (5 mins) and the result is way more precise than with the previous component.
It ranges only around 20 litters in difference
In Home Assistant it gives :
The installation looks like this now :
I 3D printed a piece to maintain the JSN SR04T, you can find it here :