Main

Why Some Automations Need Delay and Others Need Debounce—And How to Tell

In smart-home reliability work, delay and debounce are two different timing controls that fix two different problems. Delay inserts a controlled pause before an action. Debounce filters out rapid, repeated, or unstable input transitions so only a stable state change gets accepted. For residential and small-office operators running local firmware, the distinction matters because the wrong choice produces false triggers, missed events, or logic that works only by accident. This article explains how to tell which one a given automation needs, and how to implement both without turning a simple rule into a fragile pile of timers.

Open electronics workbench with a microcontroller, jumper wires, and a multimeter during a timing test

This topic sits next to sensor calibration, local networking, and failure-mode analysis. It is also a natural follow-up to How to Audit the Small Systems That Quietly Run Your Week, because timing errors are one of the most common findings in an automation audit.

Delay and Debounce Are Not the Same Tool

A delay says: after a condition becomes true, wait a fixed interval, then act. A debounce says: do not accept a state change until the input has remained stable for a fixed interval. The difference is not just wording. Delay changes when an action happens. Debounce changes whether an input transition is considered real.

In a local automation controller, delay is usually implemented as a timer that starts on a rising or falling edge. Debounce is usually implemented as a filter that requires the input to hold its new state for a minimum period before the controller updates its logical state. Some platforms blur the two by offering a “debounce” setting that actually behaves like a delay, which is why operators should read the firmware source or test the behavior directly.

What Delay Fixes

Delay fixes sequencing problems. A common example is a bathroom fan that should run for a few minutes after the light turns off. The light-off event is real and stable. The fan does not need to start immediately; it needs to start after a defined interval. That is a delay.

Delay also fixes mechanical settling. A door contact may report closed before the deadbolt has fully seated. A 500 ms delay before arming a security routine gives the lock time to finish its travel. The input is not noisy; the physical world is simply slower than the electrical signal.

What Debounce Fixes

Debounce fixes unstable inputs. A float switch in a sump pit can chatter when water is turbulent. A PIR motion sensor can emit multiple short pulses as a person walks through its detection zones. A dry-contact button can bounce mechanically for tens of milliseconds. In each case, the controller sees several transitions where the operator intended one.

Debounce is also the correct tool when a sensor briefly drops out due to a loose wire, a marginal power supply, or a radio link that blips. If the input returns to its previous state within the debounce window, the controller ignores the excursion. If the input stays changed, the controller accepts the new state.

Close-up of a float switch and wiring inside a sump pit, showing a sensor prone to chatter

How to Tell Which One an Automation Needs

The diagnostic question is simple: Is the problem that the event is real but too early, or is the problem that the event is not reliably a single event?

If the event is real and the timing is wrong, use delay. If the event is unstable or repeated, use debounce. If both problems exist, use both—but apply them in the correct order. Debounce first, then delay. The debounce stabilizes the logical state. The delay then schedules the action relative to that stable state.

Test the Input Before Choosing

Before adding either control, log the raw input for a few days. Most local controllers can write state changes to a log file or MQTT topic. Look at the timestamps. If a door sensor shows three open/close cycles within 200 ms during a single physical opening, that is bounce. If a temperature sensor crosses a threshold and the boiler starts immediately, but the room overshoots because the radiator was still hot, that is a sequencing problem—delay may help, but so may hysteresis.

Hysteresis is a related concept that deserves its own treatment. It is not the same as debounce, although both reduce false triggers. Hysteresis uses two thresholds: one to turn on, another to turn off. Debounce uses time. A thermostat with a 0.5°C hysteresis band and a 30-second debounce is more stable than either control alone.

Implementation Patterns That Hold Up

In open-source firmware such as ESPHome, Tasmota, or custom Arduino sketches, the implementation details differ, but the patterns are consistent.

Debounce in ESPHome

ESPHome provides a delayed_on and delayed_off filter for binary sensors. A typical debounce for a door contact looks like this:

binary_sensor:
  - platform: gpio
    pin: D2
    name: "Front Door"
    filters:
      - delayed_on: 50ms
      - delayed_off: 50ms

This requires the input to remain on or off for 50 ms before the state is published. It filters contact bounce and brief electrical noise. For a float switch in moving water, 200–500 ms is often more appropriate. For a push button, 20–50 ms is usually enough.

Delay in ESPHome

Delay is typically handled in an automation rather than in the sensor filter. A bathroom fan that runs for 10 minutes after the light turns off can be written as:

automation:
  - trigger:
      - platform: state
        entity_id: binary_sensor.bathroom_light
        to: "off"
    action:
      - delay: 10min
      - switch.turn_on: fan

This is a delay, not a debounce. The light-off event is accepted immediately. The fan action is postponed.

Combining Both

A sump pump high-water alarm might need both. The float switch chatters when water sloshes. The alarm should not sound until the high-water condition has been stable for 10 seconds, and then it should wait another 5 seconds before sending a notification so that the pump has a chance to clear the water. The correct order is:

  1. Debounce the float switch for 10 seconds.
  2. Trigger the alarm automation on the debounced state.
  3. Delay the notification action by 5 seconds.

If the order is reversed, the delay starts on the first noisy edge, and the debounce never gets a chance to reject the false state.

Common Failure Modes

Delay and debounce each have characteristic failure modes. Recognizing them saves hours of log-watching.

Too Much Debounce

Excessive debounce makes a system feel unresponsive. A light switch with a 500 ms debounce will feel laggy. A security sensor with a 2-second debounce can miss a fast-moving intruder. The debounce window should be just long enough to reject the observed noise, not a round number chosen for comfort.

Too Little Debounce

Insufficient debounce produces duplicate events. A single button press that toggles a light twice is the classic symptom. A door sensor that logs three open events for one physical opening can trigger three separate automations, each of which may send a notification or increment a counter.

Delay Without a Cancel Condition

A delayed action should usually be cancellable. If a motion sensor turns on a light after a 30-second delay, and the person leaves the room during that delay, the light should not turn on. A well-formed automation includes a cancel condition or re-evaluates the trigger state before acting.

Debounce on the Wrong Side of the Logic

Debounce belongs on the input, not on the output. If a controller debounces the output of a relay, it may delay the physical action but still accept noisy input. The result is a system that acts on false triggers, just slightly later. The fix is to move the debounce to the sensor or input pin.

Choosing Timing Values

Start with measurements, not guesses. Log the raw input for at least a few days under normal operating conditions. For a door contact, measure the bounce duration with an oscilloscope or a high-resolution timer. For a float switch, watch the log during a pump cycle. For a motion sensor, count the pulses during a typical walk-through.

Then set the debounce window to roughly two to three times the longest observed noise duration. If the longest bounce is 30 ms, a 50–100 ms debounce is reasonable. If the longest chatter burst is 2 seconds, a 5-second debounce may be needed. The goal is to reject noise without rejecting real events.

Delay values are easier to reason about because they are tied to physical processes. A fan needs to run long enough to clear humidity. A lock needs enough time to complete its travel. A notification should wait long enough for a backup pump to do its job. Measure the process, then add a small safety margin.

Mechanical gears and timing components representing physical settling and sequencing in automation

Local Control and Failure-Mode Thinking

One advantage of local firmware is that timing behavior is inspectable. A cloud-dependent automation may hide its debounce and delay settings behind a vendor’s app, or change them without notice. A local controller exposes the actual configuration, and the operator can test it with a button, a jumper wire, or a scripted MQTT publish.

Failure-mode analysis asks what happens when the timing control is wrong in each direction. A debounce that is too short produces false positives. A debounce that is too long produces false negatives. A delay that is too short starts an action before the system is ready. A delay that is too long leaves a condition unaddressed. Each failure has a different cost, and the cost depends on the specific automation.

For a sump pump alarm, a false positive is annoying but survivable. A false negative is potentially catastrophic. That asymmetry argues for a longer debounce and a shorter delay. For a bathroom fan, a false positive wastes a little energy. A false negative leaves moisture in the room. The asymmetry is smaller, so the timing can be more relaxed.

Documenting Timing Decisions

A reliable system includes documentation. For each automation that uses delay or debounce, record:

  • The input and its observed noise characteristics.
  • The chosen debounce window and the reason for that value.
  • The chosen delay and the physical process it accommodates.
  • The failure mode if the timing is too short or too long.
  • The date of the last test and the result.

This documentation is not busywork. It is the difference between a system that can be maintained by someone else and a system that depends on the original builder’s memory. It also makes the next audit faster.

FAQ

What is the difference between delay and debounce in home automation?

Delay inserts a pause before an action after a condition is met. Debounce requires an input to remain stable for a set time before the controller accepts a state change. Delay fixes timing problems; debounce fixes noisy or unstable inputs.

How do I know if my sensor needs debounce?

Log the raw input and look for multiple transitions within a short period during what should be a single physical event. If a door contact reports several open/close cycles in under 100 ms, or a float switch chatters during pump operation, debounce is appropriate.

Can I use delay instead of debounce?

Not reliably. A delay postpones an action but still accepts the first noisy edge as a real event. If the input chatters, a delay may start on a false edge and act on a condition that never truly existed. Debounce should be applied first, then delay if sequencing is also needed.

What debounce time should I use for a push button?

Mechanical push buttons typically bounce for 10–50 ms. A debounce of 20–50 ms is usually sufficient. Test the specific button, because some inexpensive switches bounce longer. If the button feels unresponsive, reduce the window; if it double-triggers, increase it.

Does debounce affect battery-powered sensors?

Debounce itself does not significantly affect battery life, but it can change how often the sensor wakes or reports. A sensor that reports every noisy edge will drain its battery faster. A well-chosen debounce reduces unnecessary reports and can extend battery life.

Next Step: Audit Your Timing Controls

If you have not reviewed your automations’ timing settings recently, start with the ones that control water, locks, or security. Those are the highest-cost failure modes. Log the raw inputs, compare the observed noise to the configured debounce, and test each delay with a stopwatch. The audit method in How to Audit the Small Systems That Quietly Run Your Week provides a structured way to work through the list.

This article is part of a series on local automation reliability. Future pieces will cover hysteresis in threshold-based automations, watchdog timers for controllers that silently hang, and the difference between edge-triggered and level-triggered logic. If you have a timing problem that does not fit the patterns here, the failure is usually in the log data—collect more of it before changing any settings.