Monitoring the salt level in water softeners or storage barrels is a practical use of IoT devices. This guide demonstrates how to configure an ESPHome-based salt level monitor using a Wemos D1 Mini and a VL53L0X distance sensor.
Project Overview
The ESPHome configuration provided is designed to:
- Monitor salt levels using the VL53L0X sensor.
- Provide real-time measurements via Wi-Fi.
- Offer an RGB status LED for visual feedback.
- Include a manual measurement trigger using a GPIO-connected button.
- Securely communicate with a smart home system through API encryption and OTA updates.
To see the full configuration, hop on my GitHub repository.
Hardware Requirements
- Wemos D1 Mini (ESP8266 board)
- VL53L0X Time-of-Flight Distance Sensor
- RGB LED (common cathode)
- Push button
- Resistors (for pull-up configuration)
- Breadboard and jumper wires
- Power source (e.g., USB cable or 5V power supply)
Configuration Details
Substitutions
substitutions:
name: salt-level
friendly_name: "Salt Level"
board: d1_mini
These placeholders make the configuration reusable and easy to adapt for different projects.
ESPHome Setup
esphome:
name: ${name}
friendly_name: ${friendly_name}
esp8266:
board: ${board}
The ESPHome and board configuration initializes the Wemos D1 Mini with the project name and friendly name.
Wi-Fi Configuration
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: ${friendly_name} Fallback AP
password: !secret salt_level_ap_password
The fallback AP ensures connectivity even if your main Wi-Fi credentials are unavailable.
Sensors and Updates
Distance Sensor (VL53L0X)
sensor:
- platform: vl53l0x
id: vl53l0x_sensor
name: Reading
update_interval: never
unit_of_measurement: "%"
accuracy_decimals: 0
filters:
- lambda: |-
ESP_LOGD("custom", "Value measured. x= %f", x);
const int BARREL_HEIGHT = 100;
const int GAP = 15;
if(isnan(x) || x > BARREL_HEIGHT + GAP) { return 0; }
else {
return ((BARREL_HEIGHT - x *100)/(BARREL_HEIGHT - GAP))*100;
}
This sensor calculates the percentage of salt remaining, factoring in barrel dimensions and measurement gaps.
Manual Trigger Button
binary_sensor:
- platform: gpio
pin:
number: D3
mode: INPUT_PULLUP
inverted: true
id: manual_measure_button
internal: true
on_press:
then:
- component.update: vl53l0x_sensor
- logger.log: Button pressed
A physical button allows users to manually trigger measurements, which can be handy for quick checks.
RGB LED Status
light:
- platform: rgb
id: status_led
red: led_red
green: led_green
blue: led_blue
The LED changes color to indicate various statuses:
- Green: Measurement successful.
- Red: Waiting for the next measurement.
Button and Restart Options
button:
- platform: template
name: Trigger Salt Measurement
on_press:
then:
- component.update: vl53l0x_sensor
- platform: restart
name: Restart ${friendly_name}
The template button triggers a new salt level measurement, while the restart button reboots the device.
Putting It All Together
Wiring Diagram
- VL53L0X:
- SDA to D2
- SCL to D1
- VCC to 3.3V
- GND to GND
- Button:
- One terminal to D3 (with a pull-up resistor)
- Other terminal to GND
- RGB LED:
- Red to D5
- Green to D6
- Blue to D7
Uploading the Code
- Install the ESPHome dashboard.
- Create a new device using the provided YAML configuration.
- Compile and upload the firmware to the Wemos D1 Mini via USB.
Benefits of This Configuration
- Customization: Flexible settings for various barrel sizes.
- Security: Encrypted API communication and OTA updates.
- Ease of Use: Manual trigger and RGB feedback.
- Expandability: Add more sensors or features as needed.
With this setup, you’ll always know your salt level at a glance, whether through the RGB indicator or integration with your smart home system. Happy building!