Skip to main content
Skip table of contents

Preventing Dry-Run Damage in a Home Water Pump System Using Shelly Pro 1PM JavaScript Automation

Centrifugal-pump-working.gif

This article describes how to preserve liquid pump from dry run by using Shelly Pro 1PM.

Introduction to Home Water Pump Systems

Many residential properties rely on independent water sources such as wells, boreholes, or small domestic dams. In such installations, an electric water pump is responsible for delivering water from the source to the household plumbing system or to a storage tank. These pumps are often expected to operate automatically and reliably, sometimes in remote or unattended conditions.

Unlike municipal water networks, private water sources are subject to natural variation. Seasonal droughts, evaporation, sediment accumulation, or increased consumption can significantly reduce available water levels. If a pump continues to operate when water is no longer available, a condition known as dry running occurs.

Dry running is one of the most damaging situations for centrifugal water pumps. Water inside the pump is essential not only as the transported medium, but also for:

  • Cooling the pump and motor

  • Lubricating mechanical seals and bearings

  • Creating hydraulic resistance that loads the impeller

When water is missing, internal components can overheat rapidly, seals may fail, and the pump can suffer permanent damage within a very short time. Because of this, reliable dry-run protection is a critical requirement in any home water pumping system.

This article presents a practical protection method based on electrical power measurement, implemented using a Shelly Pro 1PM and its built-in JavaScript automation engine.

Using Shelly Pro 1PM for Automatic Pump Protection Based on Power

In my particular installation, I use a 1.5 kW single-phase water pump powered through a Shelly Pro 1PM. The Shelly is mounted in the electrical panel and performs two essential roles:

  • Controls the pump power through its relay output

  • Measures the active power consumption of the pump in real time

This combination allows the Shelly to act both as a controller and as a protection device.


Wiring Overview

The electrical wiring is straightforward and follows standard safety practices:

  • The phase conductor of the pump is routed through the Shelly Pro 1PM relay output, so when the relay is ON, the pump receives power and runs.

  • A manual wall switch is connected to Input 1 of the Shelly Pro 1PM.

    • When the switch is toggled, it sends a control signal to the Shelly.

    • Based on this input, the Shelly can be configured (via the web interface or internal logic) to turn the relay ON or OFF.

  • The neutral (N) and protective earth (PE) conductors are wired directly to the pump according to local electrical regulations.

This wiring arrangement creates a flexible and safe system where:

  • The pump can be started and stopped manually using a physical switch.

  • The pump can be monitored and controlled remotely through the Shelly interface or a smart home system.

  • The pump can be automatically protected using logic based on active power measurement.


How the Power-Based Protection Works

The protection concept is simple and reliable:

  1. When the pump is ON, the Shelly continuously measures the active power (W) consumed by the motor.

  2. If the measured power drops below a predefined threshold considered too low for normal pumping, this indicates that the pump may be running dry or no longer moving water.

  3. To avoid false triggers caused by short disturbances, the system waits for a short verification period (a few seconds).

  4. If the power remains below the threshold after this delay, the Shelly:

    • Turns OFF the relay, immediately stopping the pump

    • Optionally records the event or triggers a notification, depending on the system configuration


Selecting the Power Threshold

The shutdown threshold must be chosen based on the real behavior of the pump.

For example:

  • A 1.5 kW pump at 230 V may consume:

    • 900–1400 W during normal operation (depending on pressure and flow)

    • 200–500 W during dry running or very low water conditions

Based on these values, a practical threshold could be:

  • 600 W as the minimum safe operating power

This leads to a clear decision rule:

  • Above 600 W → normal hydraulic operation

  • Below 600 W → suspected dry run, stop the pump

The exact value can be refined by observing real-time power measurements in the Shelly web interface or logs during normal and abnormal conditions.


Advantages of Power-Based Protection

Using power instead of current provides several benefits:

  • Active power directly reflects real mechanical work

  • Less sensitivity to voltage variation and reactive components

  • Clear separation between pumping and dry-run states

  • Simple and robust configuration

This makes power-based detection especially suitable for protecting domestic water pumps where reliability and simplicity are essential.

Example Shelly Script (JavaScript) for Dry-Run Protection

Below is a simple Shelly Script you can paste into the Scripts section of your Shelly Pro 1PM (Shelly Web UI → Scripts → Add script). It assumes:

  • Pump is controlled by Switch ID 0 (the main relay).

  • You use Input 1 just to manually turn the pump on/off (Shelly can mirror input to relay through standard settings or you can manage it in script as well).

  • We only care about protecting the pump based on low power.

You’ll need to adapt the numeric values (POWER_MIN_W, CHECK_INTERVAL_MS, LOW_POWER_DURATION_MS) to your actual pump.

JS
// ======================================================
// Shelly Pro 1PM – Pump control + dry-run protection
// Power-based detection (Watts)
// One input (Input 1), one relay output (Switch 0)

// =======================
// CONFIGURATION
// =======================
let SWITCH_ID = 0;                  // Relay output ID
let INPUT_ID = 0;                   // Input 1
let POWER_MIN_W = 600;              // Minimum safe power in Watts
let CHECK_INTERVAL_MS = 1000;       // Power check interval
let LOW_POWER_DURATION_MS = 5000;   // Low power duration before shutdown

// =======================
// INTERNAL STATE
// =======================
let lowPowerStart = 0;
let pumpLocked = false;

// Helper: current time in ms
function nowMs() {
  return (new Date()).getTime();
}

// =======================
// MANUAL SWITCH HANDLING
// =======================
Shelly.addEventHandler(function (event) {
  if (event.name !== "input") return;
  if (event.id !== INPUT_ID) return;

  if (event.info.event !== "toggle" &&
      event.info.event !== "single_push") return;

  if (pumpLocked) {
    print("Manual reset after dry-run. Unlocking pump.");
    pumpLocked = false;
  }

  print("Manual switch action detected. Toggling pump.");
  Shelly.call("Switch.Toggle", { id: SWITCH_ID });
});

// =======================
// POWER MONITORING LOOP
// =======================
Timer.set(CHECK_INTERVAL_MS, true, function () {

  Shelly.call("Switch.GetStatus", { id: SWITCH_ID }, function (res, err) {
    if (err) {
      print("Status error");
      return;
    }

    // Pump is OFF → reset monitoring
    if (!res.output) {
      lowPowerStart = 0;
      return;
    }

    let power = res.apower;
    print("Pump power:", power, "W");

    // Normal operation
    if (power >= POWER_MIN_W) {
      lowPowerStart = 0;
      return;
    }

    // Low power detected
    if (lowPowerStart === 0) {
      lowPowerStart = nowMs();
      print("Low power detected, starting timer...");
      return;
    }

    let elapsed = nowMs() - lowPowerStart;
    print("Low power ongoing, elapsed:", elapsed, "ms");

    // Dry-run condition confirmed
    if (elapsed >= LOW_POWER_DURATION_MS) {
      print("Dry-run detected (low power). Turning OFF pump.");

      Shelly.call("Switch.Set", { id: SWITCH_ID, on: false });
      pumpLocked = true;
      lowPowerStart = 0;

      print("Pump stopped due to low power protection.");
    }
  });
});

How to Use and Tune This Script

Install the Script

  1. Open the Shelly Pro 1PM web interface in your browser.

  2. Navigate to Scripts → Add script.

  3. Paste the JavaScript code from the previous section.

  4. Save and enable the script.

  5. Make sure Input 1 is configured as Detached in the Shelly settings.

Once enabled, the script will start monitoring the pump automatically whenever the relay is turned on.


Find Your Real Power Values

Before final tuning, it is important to observe how your specific pump behaves.

  1. Run the pump under normal water conditions.

  2. Observe the active power (W) shown in the Shelly device status or in the script logs.

  3. Note the stable minimum power value during normal operation.

If possible and safe to do so:

  • Briefly simulate low water or dry conditions

  • Observe how far the power value drops

  • Stop the test immediately to avoid pump damage

Set POWER_MIN_W to a value that lies comfortably between normal operation and dry running.

Example:

  • Normal operation: ~1000 W

  • Dry run: ~300–400 W

  • Chosen threshold: 600 W


Adjust Timing Parameters

The script uses time filtering to avoid false shutdowns.

  • CHECK_INTERVAL_MS = 1000
    → Power is checked once per second.

  • LOW_POWER_DURATION_MS = 5000
    → Power must stay below the threshold for 5 seconds before the pump is stopped.

If faster protection is required, you can reduce LOW_POWER_DURATION_MS.
Be aware that very short delays may cause false triggers during startup or brief cavitation events.


Manual Switch Behavior (Input 1)

The physical switch connected to Input 1 is used for normal pump operation:

  • Toggling the switch turns the pump ON or OFF

  • After a dry-run shutdown, the pump is locked

  • A manual switch toggle is required to unlock and restart the pump

This ensures that the pump does not automatically restart under unsafe conditions.


Operational Summary

  • The pump operates normally under sufficient water load

  • Power is continuously monitored while running

  • Sustained low power indicates loss of water

  • The script immediately shuts down the pump to prevent damage

  • Manual intervention is required before restarting

This approach provides robust protection, minimal false triggering, and full compatibility with manual control.

Schematic and Mounting Diagrams

2_dry_pump_current_-_schematic.png

Schematic diagram

1_dry_pump_current_-_diagram.png

Cabinet and peripherals

Conclusion

Dry running is one of the most destructive failure modes in domestic water pump systems. By observing active power consumption, it is possible to determine whether the pump is performing useful hydraulic work or running without water.

Using the Shelly Pro 1PM, this protection logic can be implemented locally, without additional sensors or external controllers. Combined with correct electrical wiring and proper mechanical installation, power-based protection provides a reliable, elegant, and cost-effective solution for home water systems.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.