Skip to content
PN Scripts

Development

Know when the washing machine has finished, from a smart plug's power reading

  • PN Scripts
  • 9 min read

A smart plug that measures power can tell you when the washing machine has finished, so the washing does not sit in the drum until it smells. The machine draws power while it runs and almost none when it is done; the details are where home automations go wrong. A washing machine stops drawing power many times during one cycle, a dryer keeps tumbling for an hour after it has finished, and many plugs stop reporting when nothing changes. This guide explains the rules that work, with a small detector you can run, and the settings that matter for Shelly and Tasmota plugs.

#What the power curve of a wash looks like

A typical wash has four parts. First the heater warms the water, which draws around 2 kW for ten to twenty minutes. Then the drum turns back and forth for most of an hour, at a few hundred watts, with pauses of a minute or two in which the machine draws almost nothing. Rinsing and soaking add longer pauses. Spinning at the end draws a few hundred watts again. When the programme ends, the machine falls to one or two watts of standby, and a door light or a display may add a little on top.

A dishwasher looks similar, with one trap: many models dry the dishes with residual heat, so the last quarter of an hour draws only a few watts, the same as standby. A tumble dryer runs at high power until the clothes are dry, then often tumbles for a few seconds every few minutes for up to an hour to stop creases.

#Two thresholds and two waiting times

The reliable rule uses two levels and two times, not one number:

  • Start: the power stays above a start level (for a washing machine about 15 W) for a start time (about a minute). This ignores a door light or a display that wakes up for a few seconds.
  • End: the power stays below an end level (about 5 W) for an end time (about five minutes for a washing machine). This waiting time is what makes the rule work: it has to be longer than the longest pause inside a cycle.
  • Shortest cycle: a run shorter than about ten minutes is thrown away, so somebody switching the machine on to check a programme does not produce a "finished" message.

The gap between the start and end levels matters too. If one number is used for both, a machine idling around that number starts and ends a cycle every few seconds.

#A detector you can run

This is the whole rule in plain JavaScript. It takes readings as a time in seconds and a power in watts, and at the bottom replays a made-up wash with a door light, heating, twelve wash phases with two-minute rests, a four-minute soak, spinning and standby. It runs with Node.js as it is; in a Node-RED function node, keep the state in the node context instead of the closure.

// A finished-cycle detector for one appliance. Feed it (time in seconds, watts).
function makeDetector({ startW = 15, startS = 60, endW = 5, endS = 300, minCycleS = 600 } = {}) {
  let state = 'idle', since = null, startedAt = null, quietSince = null;
  return function reading(t, watts) {
    if (state === 'idle') {
      if (watts > startW) {
        since ??= t;
        if (t - since >= startS) { state = 'running'; startedAt = since; quietSince = null; return { event: 'started', at: since }; }
      } else since = null;
      return null;
    }
    // running
    if (watts < endW) {
      quietSince ??= t;
      if (t - quietSince >= endS) {
        state = 'idle'; since = null;
        const event = quietSince - startedAt >= minCycleS ? 'finished' : 'discarded';
        return { event, at: quietSince, minutes: Math.round((quietSince - startedAt) / 60) };
      }
    } else quietSince = null;
    return null;
  };
}

// A made-up wash, one reading every 10 seconds: a door light, heating, washing
// with 2-minute pauses while the drum rests, a 4-minute soak, spinning, then off.
const trace = [];
let t = 0;
const add = (watts, seconds) => { for (let s = 0; s < seconds; s += 10, t += 10) trace.push([t, watts]); };
add(1, 120); add(25, 20); add(1, 300);              // door light: 20 s, too short to start
add(2100, 900);                                    // heating the water
for (let i = 0; i < 12; i++) { add(180, 180); add(2, 120); }
add(180, 120); add(2, 240);                        // rinse, then a soak shorter than 5 minutes
add(450, 600);                                     // spin
add(1, 900);                                       // finished, door still closed

const detect = makeDetector();
for (const [time, watts] of trace) {
  const e = detect(time, watts);
  if (e) console.log(e);
}

It prints a start at 440 seconds, when the heater came on, and a finish at 5900 seconds, 91 minutes later. The door light was too short to start anything, and neither the rests nor the soak ended the cycle, because each was shorter than five minutes. Note two details. The reported end time is the start of the quiet part, but the message can only be sent five minutes later, when the quiet part has lasted long enough. And in an earlier version of this trace the soak came straight after a rest: together they were six minutes of quiet and the cycle "finished" before the spin. If your machine has long soaks, make the end time longer.

#Plugs that go quiet

The detector above only decides when a reading arrives. Many plugs report only when the power changes by some percentage, or once a minute at most, so after the machine stops there may be no reading at all for a long time, and the cycle never ends. A real automation needs its own clock that checks every few seconds whether the quiet time has passed, using the last known power. The opposite problem exists as well: plugs that average over five minutes or more blur the start and the end. For Tasmota, set TelePeriod to between 10 and 60 seconds; the allowed range is 10 to 3600. Shelly Gen2 plugs report apower, the last measured active power in watts, in their switch status.

#The dryer and the dishwasher

For the dryer, ignore short bursts: a run of power shorter than about 45 seconds after the main cycle does not count as activity, so the anti-crease tumbling does not hold the cycle open for an hour. Use a higher start level as well (around 60 W), because a dryer's electronics alone can draw more than a washing machine's.

For the dishwasher, make the end time long, around fifteen minutes, so the quiet drying phase is not reported as the end. The message then arrives about fifteen minutes after the pumps stop, which is usually what you want anyway: the dishes are dry.

#When will it be ready?

Once a few cycles have been recorded, the start message can say when the machine will finish. Keep the duration of the last ten or so cycles and use their median, separately per programme if you can tell programmes apart (for example by sending the programme name from a button or a dashboard). The median is better than the average because one interrupted or extra-long cycle does not move it much.

#Energy, cost and reminders

Energy is the sum of power times time, with each reading held until the next one, which is how plugs report. On a day and night tariff, charge each minute at the price of that minute; a cycle that starts at 21:30 is partly on the cheaper rate. Keep the totals to see what each programme really costs.

The notification that works best is not one message but a short series: "finished" when the cycle ends, and a reminder every half hour until somebody empties the machine. "Emptied" can come from a button, a door sensor or the start of the next cycle.

Finally, keep the state somewhere that survives a restart. In Node-RED the default context store is in memory; with the localfilesystem store configured in settings.js, a restart in the middle of a wash does not lose the cycle.

#A Node-RED node that does this

We made Zvanche, a Node-RED node that follows these rules for washing machines, dishwashers, tumble dryers and other appliances, with defaults for each. It has its own clock for plugs that go quiet, ignores the dryer's tumbling, learns the usual cycle length per programme and says when the machine will be ready, counts energy and cost with a price that can change during the day, and repeats a reminder until it is told the machine was emptied. Messages come as ready sentences in English or Bulgarian for Telegram, e-mail or Home Assistant. It needs Node-RED 3.0 or newer and was checked with automated tests on made-up but realistic traces and inside a real Node-RED runtime, not with a physical plug, so watch the first few cycles of your machine and adjust the levels if needed. It is listed as Coming soon.

#Frequently asked questions

Why does my automation say the wash finished in the middle of the cycle?

Because the end time is shorter than a pause inside the cycle. Washing machines rest the drum, drain and soak with almost no power; wait at least five minutes below the end level, longer for machines with long soaks.

Why is my dryer reported as finished an hour late?

The anti-crease tumbling after the end keeps the power above the end level for a few seconds every few minutes. Ignore runs shorter than about 45 seconds once the main cycle has ended.

Which smart plugs work for this?

Any plug that measures power and reports it at least every minute or on every change: Shelly, Tasmota and most Zigbee plugs with metering do. Check that the plug is rated for the appliance's current; a washing machine heater draws around 2 kW.

Can it tell which programme is running?

Not reliably from the power alone. Send the programme from a button or a dashboard when you start the machine, and the ready time can be learned per programme.

#Sources

Keep reading

Keep reading

Comments

Comments

Be the first to leave a comment.

Leave a comment

Next step

pnscripts.com/contact

Talk to the team

Ask about an article, or tell us about a project you want built. We reply within one business day.

Write to us

The PN Scripts family

Other PN Scripts sites

Hosting, games and the blog each have their own site, run by the same company.

  • pnscripts.com

    PN Scripts

    Software engineering

    Custom web, mobile, API and game development, plus our open-source products and plugins.

  • games.pnscripts.com

    Games

    Games and game servers

    The home for PN Scripts games: free browser games you can play right now, with game servers coming soon.

  • hosting.pnscripts.com

    Hosting

    Hosting and infrastructure

    Shared hosting, KVM VPS, dedicated servers and domains, from the same company that builds your project.

  • blog.pnscripts.com

    Blog

    Articles and field notes

    Practical articles on software development, hosting, open source and games, written by the people who build them.

    You are here