Securing a Rainwater Tank with a LiDAR Sensor in Home Assistant
Updated on September 24, 2026: aligned with Part 3 of the rainwater tank series. The automations now switch the pump directly via its entity ID and keep it safely off if the sensor fails.
A Pump That Doesn't Know When to Stop
A garden pump without dry-run protection is a ticking time bomb. If it runs without water, the shaft seal overheats within seconds. The bearing follows next. Best case, an expensive repair; worst case, a total loss and a dried-out flower bed.
The seemingly simple solution is a basic float switch. That works until the float gets stuck, the switch corrodes, or you simply forget that the rainwater tank is only five percent full after a dry August.
Even the pressure-based dry-run protection built into many domestic water systems only reacts once the pressure in the line collapses, that is, when the pump is already drawing air. A level sensor switches off earlier, while there is still water in the tank.
An automatic pump control system based on a level sensor sounds straightforward at first: install the sensor, bring the readings into Home Assistant, define thresholds, done. In practice, however, it is not the automation that determines the reliability of the system, but the quality and suitability of the sensor technology used.
● Detail one: Cheap ultrasonic sensors lose measurement accuracy in humid environments. After one to two years of operation in a rainwater tank, condensation damage, shifted resonance frequencies, and declining reflection sensitivity appear. On top of that there is a basic physical problem: ultrasonic sensors measure the speed of sound, which is temperature-dependent. An underground rainwater tank swings between 5 °C in winter and 15 °C in summer. Without temperature compensation, systematic measurement errors of several percentage points result. Dry-run protection based on such values is unreliable.
● Detail two: Many affordable sensors communicate through the manufacturer's cloud server. If the cloud service goes down, Home Assistant reports `unavailable`. A naive automation then does nothing. The pump keeps running.
● Detail three: A threshold without hysteresis makes the pump switch on and off rapidly when the water surface is disturbed. That is mechanical stress that wears out the pump faster than a single dry-run incident.
This guide shows how to solve this properly: with a LiDAR sensor that communicates locally over MQTT, with an automation that explicitly treats sensor failure as an error state, and with a hysteresis logic that prevents pump cycling. A reliable water level measurement is the prerequisite for all of this. You will find all the options in our overview: Measuring and monitoring the fill level of your rainwater tank
Hardware & Parts List (BOM)
|
Item |
Component |
Purpose / Note |
|
1 |
Senvolon Level Sensor LD Wi-Fi |
LiDAR precision, temperature-independent, local MQTT. |
|
2 |
optional: |
Required for buried concrete rainwater tanks to ensure stable reception. |
|
3 |
Wi-Fi switch actuator (e.g., Shelly) |
Switches the pump based on the sensor readings. |
|
4 |
Home Assistant Hub |
The control unit (Raspberry Pi, HA Green, or similar). |
|
5 |
Spirit level |
Essential for mounting the sensor exactly level. |
The Technical Implementation
Prefer watching videos to reading? This YouTube video explains steps 1 through 3.
Level sensor installation video
Step 1: Mounting the Sensor
Before touching any software, the mounting needs to be right. Mistakes here are hard to debug later, and a sensor mounted at an angle produces systematic measurement errors that cannot be calibrated away.
● Prepare the mounting point: Use an angle bracket or a crossbar that sits securely in the shaft access. The sensor must hang level and straight above the water surface. Check it with a spirit level. Even a slight tilt can distort the measurement. The sensor then measures a longer distance than actually needed, creating a persistent measurement error.
● Minimum distance to the water surface: 10 cm absolute minimum. For clear rainwater, plan for at least 20 cm. Clear water transmits light partially instead of fully reflecting it, which makes multiple reflections more likely. Mounting too close means you will not get valid readings. The sensor head outside the housing can be rotated 180° (loosen two screws, reattach on the other side) if the installation situation requires it.
● Wi-Fi check before final mounting: Before permanently mounting the sensor, establish the connection and check the RSSI value in the sensor's web interface. Below -70 dBm, dropped connections become likely. Retrofitting an antenna afterward is a hassle. So measure first, then seal it up.
● Beam cone check before final mounting: The ToF sensor does not emit a pinpoint beam. The beam cone widens with distance: at 1 m it is 6 cm in diameter, at 2 m already 12 cm, and at 6 m, 36 cm. Anything that extends into this cone, pipes, floats, fill hoses, submersible lines, gets measured too and distorts the result. Check the line of sight before final mounting and consistently remove obstacles from the cone.
● Underground tank with a concrete or steel lid: A lid like that significantly attenuates Wi-Fi signals. The RP-SMA antenna bundle is not a gimmick for this scenario. Run the antenna cable up through the tank access and mount the antenna outside.
Step 2: Connecting the Sensor to Your Home Network
After powering on, the sensor opens its own access point.
- Connect to the Wi-Fi network "Level Sensor-[ID]" (password: "12345678"). Disable mobile data on your smartphone beforehand.
- Open http://192.168.4.1/wifi in your browser.
- Select your SSID, enter your home network password, assign a hostname (e.g., "tank"), and save.
- The sensor connects to your home network. The assigned IP address is shown in the bottom left after a successful connection.
- Open the sensor's web interface: http://[IP address]. No app download, no platform registration.
Fallback: If the sensor loses its Wi-Fi connection, it automatically rebuilds its own access point and is always reachable at 192.168.4.1. The sensor never disappears without a way to diagnose it.

Figure 1
Step 3: Configuring the Tank Parameters in the Web Interface
All the sensor's core properties are configured through the browser-based frontend. This is the primary way to configure it. Open http://[IP address] in your browser, then select Tank:
● Geometry: Choose the matching shape (rectangular, vertical cylinder, horizontal cylinder, sphere). For custom container shapes, a tank calibration table or a free-form formula engine is available.
● Distance to the surface: Distance from the sensor to the water surface at full capacity, in cm. For clear water, enter at least 20. Measure this value with a folding rule, do not estimate it.
● Distance to the bottom: Distance from the sensor to the tank bottom, in cm.
● Minimum: Minimum alarm threshold, e.g., 10 for 10%. This is the dry-run protection threshold.
● HYST min: Hysteresis in percentage points, e.g., 5. The alarm only clears once the fill level has risen back to 15%. Prevents flapping when the level is right at the threshold.
Then go to Configuration > MQTT:
● Broker IP: IP address of the Home Assistant server
● Port: 1883
● Username: e.g., mqtt_user
● Password: matching
● Sensor Name: tank (determines all MQTT topics)
Save. The sensor then connects to the broker.
Step 4: Installing the Mosquitto MQTT Broker in Home Assistant, if Not Already Present
- Go to Settings > Add-ons > Add-on Store.
- Search for "Mosquitto Broker", click Install, and then click Start.
- Enable "Start on boot".
- Create a dedicated MQTT user: Settings > People > Users > Add User.
- Name and username: mqtt_user
- Assign a secure password and enable "Local only".
Once setup is complete, the level sensor appears in the overview under "Devices & Services". There you will immediately see the current readings. Especially helpful is the "Alert" entity: it automatically derives its status from the MIN and HYST_MIN parameters you defined. Detailed instructions for the integration, including manual configuration, are available here: Integrating a level sensor into Home Assistant via MQTT.

Figure 2
Step 5: Automation: Turning Off the Pump When Dry-Run Risk Is Detected
The core of the automation is the "Alert" entity, which calculates its state based on the MIN and HYST_MIN values you configured. As soon as this entity reports the status "MIN", the system immediately switches off the pump and sends a notification to your smartphone as well as to the Home Assistant dashboard.
alias: Rainwater tank almost empty
description: >
Turns off the garden pump when the rainwater tank's fill level drops below the
configured threshold or the sensor is unreachable.
Prevents dry-running.
triggers:
- trigger: state
entity_id:
- sensor.level_sensor_alert
to:
- MIN
- unavailable
- unknown
conditions: []
actions:
- variables:
meldung: >
{% if is_state('sensor.level_sensor_alert', 'MIN') %}Rainwater tank at
{{ states('sensor.level_sensor_level') | int(0) }} %.{% else %}Level sensor
unreachable.{% endif %} Pump was automatically switched off.
- action: switch.turn_off
target:
entity_id: switch.gartenpumpe
- action: persistent_notification.create
data:
title: ⚠️ Dry-run protection triggered
message: "{{ meldung }}"
notification_id: dry_run_protection
- action: notify.mobile_app_ihr_smartphone
data:
title: ⚠️ Dry-run protection triggered
message: "{{ meldung }}"
mode: single
switch.gartenpumpe: replace with the entity ID of your smart plug (Developer tools → States → filter for switch.), notify.mobile_app_ihr_smartphone: replace with your notify service.

Figure 3
Step 6: Automation for Reactivating the Pump
To resume operation after a dry-run shutdown, the system again uses the "Alert" entity as the central control element. The logic here is based on the MIN and HYST_MIN parameters you set.
The "MIN" status remains active until the fill level exceeds the threshold defined by HYST_MIN. This hysteresis ensures that the pump is not switched on and off prematurely or in too-short intervals due to minor wave movement on the water surface, which protects the hardware.
alias: Rainwater tank pump can be switched on again
description: >
Switches the pump back on and reports it when the rainwater tank's fill level
rises back above the configured threshold. If the sensor fails, the pump
stays off.
triggers:
- trigger: state
entity_id:
- sensor.level_sensor_alert
conditions:
- condition: template
value_template: >
{{ states('sensor.level_sensor_alert')
not in ['MIN', 'MAX', 'unavailable', 'unknown'] }}
actions:
- action: switch.turn_on
target:
entity_id: switch.gartenpumpe
- action: persistent_notification.create
data:
title: ✅ Dry-run protection lifted
message: >
Rainwater tank back at {{ states('sensor.level_sensor_level') | int(0) }} %.
Pump was automatically switched on.
notification_id: dry_run_protection
- action: notify.mobile_app_ihr_smartphone
data:
title: ✅ Dry-run protection lifted
message: >
Rainwater tank back at {{ states('sensor.level_sensor_level') | int(0) }} %.
Pump was automatically switched on.
mode: single
switch.gartenpumpe: replace with the entity ID of your smart plug (Developer tools → States → filter for switch.), notify.mobile_app_ihr_smartphone: replace with your notify service.
If you prefer more precise control, the automation can be adjusted so that the pump does not start up on its own but only triggers a notification instead. The irrigation can then be reactivated manually and conveniently via the dashboard introduced in the next section.
Step 7: Dashboard
This dashboard provides a central control unit: it shows not only the current fill level and pump status, including the ability to control it, but also integrates the upcoming weather forecast as well as relevant Wi-Fi connection parameters.
views:
- type: sections
max_columns: 4
title: Rainwater Tank
path: rainwater-tank
icon: mdi:watering-can
sections:
- type: grid
cards:
- type: heading
icon: mdi:car-coolant-level
heading: Fill Level
heading_style: title
grid_options:
columns: 12
rows: 1
- type: gauge
entity: sensor.level_sensor_level
name: Fill Level
needle: true
segments:
- from: 0
color: '#EA4335'
- from: 10
color: yellow
- from: 15
color: '#34A853'
- from: 85
color: yellow
- from: 90
color: '#EA4335'
unit: '%'
- show_name: true
show_icon: true
type: button
icon: mdi:pump
show_state: true
name: Water pump
icon_height: 50px
entity: switch.gartenpumpe
- type: tile
entity: sensor.level_sensor_fluid
grid_options:
rows: 1
- type: vertical-stack
cards:
- type: conditional
conditions:
- condition: state
entity: sensor.level_sensor_alert
state: MIN
card:
type: tile
entity: sensor.level_sensor_alert
name: 'Alarm status:'
icon: mdi:water-minus
color: red
- type: conditional
conditions:
- condition: state
entity: sensor.level_sensor_alert
state: MAX
card:
type: tile
entity: sensor.level_sensor_alert
name: 'Alarm status:'
icon: mdi:water-plus
color: red
- type: conditional
conditions:
- condition: state
entity: sensor.level_sensor_alert
state: ''
card:
type: tile
entity: sensor.level_sensor_alert
name: 'Alarm status: OK'
icon: mdi:water-check
color: green
grid_options:
columns: 6
rows: auto
- type: history-graph
entities:
- entity: sensor.level_sensor_level
logarithmic_scale: false
- type: heading
icon: mdi:weather-lightning-rainy
heading: Weather forecast
heading_style: title
grid_options:
columns: 12
rows: 1
- show_current: false
show_forecast: true
type: weather-forecast
entity: weather.forecast_home
forecast_type: daily
forecast_slots: 5
secondary_info_attribute: precipitation_unit
round_temperature: true
name: Weather forecast
- type: heading
icon: mdi:wifi
heading_style: title
grid_options:
columns: 12
rows: 1
heading: Wi-Fi Connection
- type: tile
entity: sensor.level_sensor_ip
- type: tile
entity: sensor.level_sensor_rssi
cards: []

Figure 4
Physical Limits and Pitfalls
● Minimum distance: This is a hard physical limit. Below 10 cm from the water surface, the sensor does not deliver valid readings. For clear rainwater, 20 cm is the safe value.
● Beam cone diameter: Grows with depth. At 2 m distance, the cone diameter is 12 cm; at 6 m, it is 36 cm. Pipes, floats, overflow valves, and submersible lines that extend into this cone get measured too. Plan the sensor position accordingly.
● Level alignment: Mounting at an angle lengthens the light path and changes the reflection angle, resulting in systematic measurement errors. The firmware calibration table can only mitigate this, not eliminate it.
● Not for flammable liquids: Not for use with heating oil, diesel, or gasoline.
● For unpressurized tanks only: Pressure vessels, pressurized hot water tanks, and pneumatic tanks are not a valid use case.
Troubleshooting: The Most Common Symptoms
|
Symptom |
Likely Cause |
Fix |
|
Sensor shows unavailable in HA |
Wi-Fi connection interrupted or RSSI too weak |
Check the RSSI in the sensor's web interface. Below -70 dBm: retrofit an external antenna. The fallback AP Level Sensor appears when the Wi-Fi connection is lost. |
|
Readings jump by ±10 cm |
Object in the beam cone, choppy water surface |
Flashlight test: check the line of sight. Increase the median window in the web interface. Increase READ_INTERVAL. |
|
Automation does not switch off the pump |
Entity IDs do not match |
Developer Tools > States: verify the correct entity ID of the outlet and enter it in both automations. For testing, start the automation under Settings > Automations & scenes via “Run”. |
|
Pump switches on and off rapidly |
Hysteresis not configured |
MINI 10 and HYST_MIN 5 on the sensor. The reactivation in step 6 only switches the pump back on once the MIN alarm has cleared. |
|
HA does not detect the sensor after MQTT setup |
MQTT Discovery disabled |
Check Settings > Devices & Services > MQTT > Configure > is Discovery enabled? |
|
Sensor permanently shows maximum distance |
Beam cone hits the tank wall instead of the water surface |
Center the sensor, remove obstacles from the beam cone. |
|
Entity stays at unknown after startup |
The rolling median needs several samples to converge |
Wait 2 to 3 minutes. This is normal on first startup. |
Why Local MQTT Is Not a Nice-to-Have Here
The LWT mechanism (Last Will & Testament) is the technical basis for the sensor watchdog in the automation. If the sensor goes offline, it leaves a predefined offline message with the broker. Home Assistant detects this immediately via the availability_topic in the sensor definitions. With cloud-mediated systems, this signal is often delayed or not available at all. The Senvolon LD Wi-Fi publishes directly to the local broker. There is no external dependency and no routing delay. Anyone who wants worldwide access to the readings can use remote.senvolon.de as an opt-in. Anyone who stays fully local does not lose any sensor feature by doing so.
Conclusion
This setup is not a hobby project with an expiration date. A Senvolon level sensor outlasts ultrasonic sensors in humid environments, is temperature-independent, and does not rely on sound as its medium. Combined with a local broker, automation logic with hysteresis, and an explicit fail-safe for sensor failure, the result is dry-run protection that works unattended. Anyone who mounts it carefully, checks the Wi-Fi RSSI before final mounting, and sets up the tank parameters properly once ends up with protection that works in the background and needs no further maintenance.
Further Reading
● Senvolon Level Sensor LD Wi-Fi in the shop
● Product documentation & user manual (linked in the shop)
● Questions, experiences, alternative configurations? Just get in touch directly with the Senvolon Support.