Water Tank Level and Water Volume with ESPHome

Thanks to @ walberjunior and everybody else that helped me to deal with this challenge.
History6– Home Assistant(1)
This is the result! I did some rectification into the formula (as 1 liter is equal to 10x10x10cm) and added one more sensor that is showing the percentage of the tank that is filled with water. Probably later, I’ll add one more sensor showing the percentage of the useful capacity, as there is a part of the tank that never is filled up and another that is never emptied due to precautions.

Here is my “sensors.yaml”, the “AJ_SR04M_Sensor.h” is unchanged as above post and I’m posting this hoping that somebody else will find it useful. I’ll come back in due time, when I’ll try to fit a LCD screen showing locally the measurements.

esphome:
  name: esp32-sensors
  friendly_name: ESP32-sensors
  includes:
    - AJ_SR04M_Sensor.h
 
esp32:
  board: esp32dev
  framework:
    type: arduino

dallas:
  - pin: GPIO22
uart:
  id: uart_bus
  tx_pin: GPIO32
  rx_pin: GPIO33
  baud_rate: 9600
  stop_bits: 1
  rx_buffer_size: 4

sensor:
  - platform: custom
    lambda: |-
      auto my_sensor = new AJ_SR04M_Sensor(id(uart_bus));
      App.register_component(my_sensor);
      return {my_sensor};
    sensors:
     unit_of_measurement: cm
     accuracy_decimals: 1
     name: "Tk Ullages"
#experiment
  - platform: custom
    lambda: |-
      auto my_sensor = new AJ_SR04M_Sensor(id(uart_bus));
      App.register_component(my_sensor);
      return {my_sensor};
    sensors:
      unit_of_measurement: Ltrs
      accuracy_decimals: 1
      name: "Tk Quantity"
      filters:
      - lambda: return ((235*143*(229 - x))/1000);
  - platform: custom
    lambda: |-
      auto my_sensor = new AJ_SR04M_Sensor(id(uart_bus));
      App.register_component(my_sensor);
      return {my_sensor};
    sensors:
      unit_of_measurement: pct%
      accuracy_decimals: 1
      name: "Tk space pct"
      filters:
      - lambda: return ((((235*143*(229 - x))/1000)/7695.5)*100);
#up to here

  - platform: dallas
    address: 0xea0722b0dcbabc28
    name: "Boiler 1" 
  - platform: dallas
    address: 0xd30822b0f48ffd28
    name: "Boiler 2"
  - platform: dallas
    address: 0xa90722b0e5ac1328
    name: "Boiler 3"

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

ota:
  password: "xxxxxxxxxxxxxxxxxxxxxxxxxx"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

captive_portal:

web_server:
  port: 80

globals:
  - id: last_state
    type: float
    restore_value: no
    initial_value: '0.0'    
2 Likes