Water Level Sensor (pressure)

Has anyone built a wireless fluid level sensor using one of these pressure type sensors? https://www.amazon.com.au/Detecting-Automatic-Irrigation-Aquariums-Agriculture/dp/B09294XQ5C

It’s a 4-20mA sensor. If you search Google for “4-20ma to 0-3.3v converter” you will find many results. They’re about $12 AUD.

The 0-3.3V signal can be fed directly to the ADC of most ESP boards running ESPHome. Very few ESP boards have 0-1V in, but do check this before purchasing.

You can use the calibrate linear filter to convert 0-3.3V to 0-5m

In fact I would recommend measuring the actual level at a few different levels over the full range and noting the voltage produced. Then use that in the linear calibration filter. Because the ESP ADC is non-linear at the low and high ends. Also the current to voltage converter boards may have some non-linearity.

1 Like

a local Australian supplier has this: https://core-electronics.com.au/gravity-analog-current-to-voltage-converter-for-4-20ma-application.html

I am wanting to integrate with Home Assistant. I’ll check out the ESP boards, i was thinking of an Arduino Nano but that might be overkill. I need a WiFi or Bluetooth signal than can handle 30m distance.

ADC typically describes the Analog in of a esp which is actually only 0-1V. Most of the boards featuring a esp typically have a voltage divider in place an allow a range of 0-3.3V to measure, this pin is then most of the time called/labeled A0

Yep that’s a good 4-20mA interface board for either Arduino or ESP.

Keep in mind the HA Arduino integration has to be connected via USB. So if the level you want to measure is distant from your HA server you will have to do something like publish MQTT over wifi.

ESPHome integrates much easier with Home Assistant over wifi. But if you are happy developing your own sketches then it’s certainly possible.

USB is not feasible over the distance. I think ESPHome would be cheaper anyhow. Just haven’t looked into it to be honest.

1 Like

It’s very simple.

You define all the parts in yaml and it takes care of compiling and uploading. There’s example code for all the components in the ESPHome docs. Check out the Analogue to Digital sensor that you will be using. You’ll start by defining a file that contains something like this:

well_level.yaml

esphome:
  name: Well Level # give it a short but descriptve name
  platform: ESP8266 # depends on the ESP board type you buy
  board: d1_mini  # depends on the ESP board type you buy

wifi:
  ssid: 'Your SSID'
  password: !secret wifi_password # esphome supports it's own secrets file
  manual_ip:
    static_ip: 10.1.1.84 # it is recommended to set a static IP but you don't have to
    gateway: 10.1.1.1
    subnet: 255.255.255.0

api:
  password: !secret api_password # this is all you need to connect to home assistant the password is optional but recommended

logger: # helpful for debugging

ota:
  password: !secret esp_pwd # Over the air updating, the password is optional but recommended

binary_sensor:
  - platform: status
    name: "Well Level Status" # an optional connected/not connected sensor for monitoring in home assistant

sensor:
  - platform: wifi_signal
    name: "Well Level WiFi Signal" # an optional wifi RSSI sensor for monitoring in home 
    update_interval: 15s
    filters:
      - sliding_window_moving_average:
          window_size: 15
          send_every: 15
          send_first_at: 1

  - platform: adc # your level sensor definition
    pin: A0
    name: "Well Level"
    update_interval: 60s
    unit_of_measurement: 'm'
    filters:
      - calibrate_linear:
          # Map from sensor volts to true value in meters
          - 0.0 -> 0.0
          - 3 -> 5

Install the ESPHome addon.

Place that file in the /config/esphome folder

Run the addon, and open the webpage to program an ESP board with this file via USB (after that you can use OTA).

Go to Configuration / Integrations in home assistant and you should see that it has discovered your new sensors. Add it. Done.

2 Likes

ordered the Gravity board and a SparkFun ESP32.

esphome:
  name: Well Level
  platform: ESP32
  board: esp32thing # or esp32thing_plus if you ordered the plus model.
1 Like

one concern i have is the distance the ESP32 Thing’s onboard WiFi can cope with. It’s no a big distance (40m) but once i mount it in a weather poof case and mount it outside of a brick home… …I am thinking I will possibly need an external antenna of some sorts.

Many ESP boards come with external antenna options (usually called “pro” versions).

e.g. This is a high quality board at a reasonable price:

If you take a laptop or Android cellphone out there running wifi survey software you should get some idea of the signal strength. You want around -70dBm at worst for short packets of IoT data. https://www.metageek.com/training/resources/wifi-signal-strength-basics.html

1 Like

The other questions i have unanswered are: how to power the sensor. I plan on using a 500mAh LiPo Battery to power the board. I’d also like to know if i could fit a second gravity board and sensor, or if i need to replicate the entire architecture to accommodate the second tank. it’ll only be a meter of two away.

Then your sensor is going to have to be asleep the majority of the time. Assuming a deep sleep current of 10uA, an active time of 10 seconds, waking four times an hour and consuming an average of 200mA while awake, your battery would last a week. Not accounting for voltage regulator losses.

Have a play with this calculator: IOT Battery Life Calculator

The ESP8266 has only one ADC, so only one analogue sensor per board. The ESP32 has eighteen ADCs. So theoretically you could connect up to 18 of these sensors to one board.

1 Like

Hi,
Just finished installing 4 pressure sensors (3 water reservoirs and 1 Diesel tank) with Shelly Uni as described here (it has English captions). managed to display the default data in HA but still confused and couldn’t convert the data into cubic meters as described in my call for help here.
I totally recommend the equipment and method, but still need to implement in HA.

cool stuff Rami. same sensor as i’m using. my project has stalled. moving house this week and the gravity cards were delayed months.

@RASBR
Hi Rami.
Did you ever get the sensor data into HA?
Watched the Shelly Uni youtube video also, and this one connected the dots.

Hi @Realpsudo
Sorry for the delayed reply. I am still learning about being more active on the forums.
Yes I managed to get sensor data to HA as follows:

  • Using Shelly integration for the Shelly UNI
  • Applying what I saw in the videos I mentioned earlier
  • Using the PNGs in the cards (previous post)

All code below:

Includes (Sensors):

# -----------------------------------------
#      Irrigation Tank Sensors
# -----------------------------------------

- name: "Irrigation Tank Capacity"
  unit_of_measurement: "mÂł"
  state: >
    {% set irrigation_height = states('input_number.irrigation_tank_h') | float %}
    {% set irrigation_width =  states('input_number.irrigation_tank_w') | float %}
    {% set irrigation_length = states('input_number.irrigation_tank_l') | float %}
    {{ (irrigation_height * irrigation_width * irrigation_length) | round (2) }}

- name: "Irrigation Tank Current Volume"
  unit_of_measurement: "mÂł"
  state: >
    {% if is_state('sensor.irrigation_tank_adc', 'unknown') or is_state('sensor.irrigation_tank_adc', 'unavailable') %}
      {% set irrigation_adc = 0 | float %}
    {% else %}
      {% set irrigation_adc = states('sensor.irrigation_tank_adc') | float %}
    {% endif %}
    {% set irrigation_v_per_cm = states('input_number.irrigation_tank_volt_per_cm') | float %}
    {% set irrigation_width =  states('input_number.irrigation_tank_w') | float %}
    {% set irrigation_length = states('input_number.irrigation_tank_l') | float %}
    {{ ((irrigation_adc / irrigation_v_per_cm / 100) * irrigation_width * irrigation_length) | round (2) }}

- name: "Irrigation Tank Current Height"
  unit_of_measurement: "m"
  state: >
    {% if is_state('sensor.irrigation_tank_adc', 'unknown') or is_state('sensor.irrigation_tank_adc', 'unavailable') %}
      {% set irrigation_adc = 0 | float %}
    {% else %}
      {% set irrigation_adc = states('sensor.irrigation_tank_adc') | float %}
    {% endif %}
    {% set irrigation_v_per_cm = states('input_number.irrigation_tank_volt_per_cm') | float %}

    {{ (irrigation_adc / irrigation_v_per_cm / 100) | round (2) }}

- name: "Irrigation Tank Level Percent"
  unit_of_measurement: "%"
  state: >
    {% set irrigation_current = states('sensor.irrigation_tank_current_volume') | float %}
    {% set irrigation_cap = states('sensor.irrigation_tank_capacity') | float %}
    {{ (irrigation_current / irrigation_cap * 100) | round (2) }}

- name: "Irrigation Tank Level number"
  unit_of_measurement: ""
  state: >
    {% set irrigation_level = states('sensor.irrigation_tank_level_percent') | float %}
    {% if 90 <= irrigation_level %} {{ 5 }}
    {% elif 70 <= irrigation_level < 90 %} {{ 4 }}
    {% elif 50 <= irrigation_level < 70 %} {{ 3 }}
    {% elif 20 <= irrigation_level < 50 %} {{ 2 }}
    {% else %} {{ 1 }}
    {% endif %}

Dashboard Card:

IrrigationTank Data

type: custom:stack-in-card
keep:
  background: true
  border_radius: true
  box_shadow: false
mode: vertical
cards:
  - type: vertical-stack
    cards:
      - type: custom:button-card
        name: Irrigation Tank
        styles:
          name:
            - text-transform: uppercase
            - letter-spacing: 0.5em
            - font-familly: cursive
            - justify-self: start
            - padding: 0px 5px
      - type: horizontal-stack
        cards:
          - type: custom:button-card
            entity: sensor.irrigation_tank_level_number
            show_entity_picture: true
            show_name: false
            size: 25%
            styles:
              card:
                - height: 150px
                - width: 90px
                - border-radius: 20px
              entity_picture:
                - justify-self: start
                - width: 65px
                - border-radius: 5px
            state:
              - value: 5
                operator: '=='
                entity_picture: /local/my-icons/water 5.png
                styles:
                  entity_picture:
                    - '-webkit-box-shadow': 0 0 0.95rem 0.2rem rgb(5, 113, 185)
                    - box-shadow: 0 0 0.95rem 0.2rem rgb(5, 113, 185)
                    - transition: all 2s ease
              - value: 4
                operator: '=='
                entity_picture: /local/my-icons/water 4.png
                styles:
                  entity_picture:
                    - '-webkit-box-shadow': 0 0 0.95rem 0.2rem rgb(39, 127, 194)
                    - box-shadow: 0 0 0.95rem 0.2rem rgb(39, 127, 194)
                    - transition: all 2s ease
              - value: 3
                operator: '=='
                entity_picture: /local/my-icons/water 3.png
                styles:
                  entity_picture:
                    - '-webkit-box-shadow': 0 0 0.95rem 0.2rem rgb(85, 186, 71)
                    - box-shadow: 0 0 0.95rem 0.2rem rgb(85, 186, 71)
                    - transition: all 2s ease
              - value: 2
                operator: '=='
                entity_picture: /local/my-icons/water 2.png
                styles:
                  entity_picture:
                    - '-webkit-box-shadow': 0 0 0.95rem 0.2rem rgb(246,135,41)
                    - box-shadow: 0 0 0.95rem 0.2rem rgb(246,135,41)
                    - transition: all 2s ease
              - value: 1
                operator: '=='
                entity_picture: /local/my-icons/water 1.png
                styles:
                  entity_picture:
                    - '-webkit-box-shadow': 0 0 0.95rem 0.2rem rgb(237,28,35)
                    - box-shadow: 0 0 0.95rem 0.2rem rgb(237,28,35)
                    - transition: all 2s ease
                    - animation: blink 2s ease infinite
          - type: custom:button-card
            entity: sensor.irrigation_tank_current_volume
            name: current
            icon: hass:percent
            show_name: false
            show_state: true
            show_icon: false
            styles:
              state:
                - font-size: 30px
          - type: custom:button-card
            entity: sensor.irrigation_tank_level_percent
            name: current
            icon: hass:percent
            show_name: false
            show_state: true
            show_icon: false
            styles:
              state:
                - font-size: 30px
      - type: custom:text-divider-row
        text: Settings
      - type: glance
        show_icon: false
        entities:
          - entity: sensor.irrigation_tank_level_percent
            name: percent
          - entity: sensor.irrigation_tank_current_volume
            name: Now
          - entity: sensor.irrigation_tank_capacity
            name: Capacity
          - entity: sensor.irrigation_tank_level_number
            name: Level
      - type: glance
        show_icon: false
        entities:
          - entity: sensor.irrigation_tank_adc
            name: Now V
          - entity: input_number.irrigation_tank_volt_per_cm
            name: v/cm
          - entity: input_number.irrigation_tank_max_v
            name: max V
          - entity: sensor.irrigation_tank_current_height
            name: now H
          - entity: input_number.irrigation_tank_h
            name: height
          - entity: input_number.irrigation_tank_w
            name: width
          - entity: input_number.irrigation_tank_l
            name: length

I hope this helpful.
Best regards,
RS

1 Like