Skip to content

This is a custom sensor for measuring the oil level of a heater's tank via an ultrasonic sensor and an ESP32 board.

Notifications You must be signed in to change notification settings

Frapais/ESPHome_Oil_Level_Monitor

Repository files navigation


ESPHome Oil Level Sensor

A custom ESPHome sensor for Home Assistant.

DescriptionHardware ComponentsHow To UseDownloadCreditsRelated

screenshot

Description

Hardware description

This sensor uses an ESP32 board that supports battery power/charging. The ESP32 also measures the battery voltage via an analog pin, through a voltage divider. The voltage divired is needed because the maximum voltage of the battery is 4.2V while the ADC of the ESP32 can measure only up to 1.1V. The oil level measurement is done with a waterproof ultrasonic sensor and its module pcb. However, you can probably use a regular ultrasonic sensor. The electronics were mounted inside a custom enclosure that was designed to screw on the lid of my oil tank.

How the measurement works

This sensor works using an Ultrasonic sensor, to measure the level of a liquid in a tank. In this particular case, the sensor is placed at the top of the tank, pointing down on the surface of the liquid. This way, we can measure the distance of the liquid from the top of the tank, and, knowing the dimensions of the tank, we can calculate its volume. Specifically, we measure the volume of the remaining liquid using the following formula: $$remainingVolume=maxVolume - measuredVolume$$

where maxVolume is calculated from the dimensions of the tank (Length, Width, Height), and measuredVolume is calculated using the following formula: $$measuredVolume = Length * Width * measuredDistance$$

Similarly, the consumed liquid can be calculated using the following formula: $$consumedVolume = measuredVolume - (maxVolume - initialVolume)$$ where initialVolume is the volume of the liquid when we start the consumption measurement

General code flow

  • ESP wakes up for 60 seconds
    • Connects to Home Assistant
    • Samples 17 times the oil surface distance and calculates an average
    • Samples the battery voltage and converts it to percentage
    • Calculates and updates the consumed oil volume and the remaining oil volume
  • Falls to deep sleep for 29 minutes

Hardware Components

  • ESP32 board with battery charging capability
  • Li-Ion battery
  • Waterproof Ultrasonic sensor
  • 2 resistors for measuring the battery voltage

How To Use

You need to have a Home Assistant server with ESPHome plugin working. If so, follow these steps:

  • Connect the hardware components according to the schematic
  • Download the YAML code for this sensor and make the required changes in the parameters according to your use-case
  • Create a new sensor in your ESPHome dashboard
  • Copy your customized YAML code to the sensor's YAML code
  • Download and 3D print the electronics enclosure, or design your own according to your needs.

Download

Credits

This software uses the following platforms:

Related

You can find similar code in the official Ultrasonic sensor implementation page of ESPHome Ultrasonic sensor

Support

Buy Me A Coffee

GitHub @frapais  ·  Instagram @worked_first_time

About

This is a custom sensor for measuring the oil level of a heater's tank via an ultrasonic sensor and an ESP32 board.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published