A Home Assistant template binary sensor with delay_on starts as unknown, so a from: « off » trigger misses the first appliance cycle

I wanted a phone notification when the tumble dryer starts and when it finishes, driven only by the power reading of the smart plug it sits on. The obvious automation, triggered by from: "off" to to: "on", would have stayed silent for the first cycle after I deployed it. Right after the reload, the sensor was not off. It was unknown.

TL;DR: a template binary_sensor with delay_on / delay_off comes back as unknown after a reload or restart, and stays there until its condition changes. Trigger on not_from: unavailable with to: "on" instead of from: "off". Separately, a heat-pump dryer draws a flat ~400–465 W until it stops, so its power curve cannot tell you how much time is left. Estimate that from the average length of past cycles.

The setup

The dryer is plugged into a Zigbee smart plug with energy metering (a Tuya TS011F, exposed to Home Assistant through Zigbee2MQTT). The plug reports power about once a minute. Home Assistant derives a « running » sensor from that number. Two automations then send a notification to two phones, one on the transition to running and one on the transition back. A template binary sensor is an on/off entity whose state is a Jinja expression; delay_on and delay_off make it change state only once the expression has held its new value for that long.

The power profile

Before choosing thresholds, I logged one full cycle minute by minute (figure). The machine turned out to be a heat-pump dryer, which behaves nothing like the resistive dryers in most « is the dryer done » tutorials:

  • 2 W in standby, 17 W for a minute after the door/program is set;
  • a jump to 386 W, then a slow climb to 465 W over 80 minutes;
  • isolated dips to 330–400 W, one sample each;
  • a hard stop: 369 W, then 19 W, then 2 W. No anti-crease tumbling phase, no tail.

Total: 80 minutes, 0.57 kWh.

Power drawn by a heat-pump tumble dryer over one 80-minute cycle: near 0 W, a step to about 386 W, a slow rise to 465 W with single-sample dips, then a sharp drop to 2 W; a dashed 100 W threshold and shaded 1-minute and 3-minute debounce windows mark when the running sensor turns on and off

So a single 100 W threshold separates the two states cleanly. delay_on: 1 min ignores the short 17 W blip and any spike, and delay_off: 3 min gives margin over a dropped sample. A cooler phase near the end would have needed a much longer delay_off; this machine has none.

What I expected

template:
  - binary_sensor:
      - name: Dryer running
        unique_id: dryer_running
        device_class: running
        state: "{{ states('sensor.dryer_plug_power') | float(0) > 100 }}"
        delay_on: "00:01:00"
        delay_off: "00:03:00"

And a start automation with from: "off" / to: "on". The dryer was idle, so I assumed the sensor read off.

What actually happens

After template.reload (and after a Home Assistant restart), I read the states back through the REST API:

binary_sensor.dryer_running  unknown

The plug was reporting 2 W, so the expression evaluated to false. But the entity did not publish off. My reading is that delay_off only times an on→off change, and there was none to time, so the sensor sat on unknown. It only leaves unknown when the expression changes. The first time it does is when the dryer starts, and then the transition is unknown → on. A from: "off" trigger does not match it.

In practice that means you miss exactly one start, the first one after every restart. That is easy to blame on the notification service.

The fix

automation:
  - id: dryer_started
    alias: Dryer started
    trigger:
      - platform: state
        entity_id: binary_sensor.dryer_running
        not_from: unavailable   # catches off->on and unknown->on
        to: "on"
    action:
      - variables:
          # the sensor turns on 1 min after the real start (delay_on)
          start: "{{ now().timestamp() - 60 }}"
      - service: input_datetime.set_datetime
        target:
          entity_id: input_datetime.dryer_start
        data:
          timestamp: "{{ start }}"
      - service: notify.mobile_app_phone_a
        data:
          title: Dryer
          message: "Started at {{ start | timestamp_custom('%H:%M') }}"

The end automation can keep from: "on" / to: "off", since by then the sensor has a real state. Subtract 180 s from now() to get the actual stop time, because delay_off reports it three minutes late. I excluded unavailable rather than unknown. That way a plug that drops off the Zigbee network and comes back while the dryer runs doesn’t send a second « started » message.

With this trigger, the first real cycle after the reload fired the start notification as unknown → on. The end notification came 3 minutes after the stop.

Remaining time without a progress signal

The curve has no feature that says « 70 % done »: the power keeps rising until the dryer stops, for a reason I didn’t investigate. So I estimate the remaining time from history. An input_number stores the average cycle length. It is seeded with the measured 80 min, and the end automation folds each new cycle into it, avg = round((avg + minutes) / 2), only when the cycle lasted at least 20 minutes so that a door opened by mistake doesn’t count. The « remaining » template sensor is then max(avg − minutes since start, 0), and the start notification includes start + avg as the expected end time. It’s an average, not a prediction: a different program or a bigger load will be off.

Leave out initial: on that input_number. With it, every restart resets the learned average to the seed value.

What I did not test

  • Only one cycle, one program, one dryer model. A resistive dryer or a program with an anti-crease phase needs a different delay_off, and a resistive dryer probably has a usable end-of-cycle signature that this one lacks.
  • Whether a template sensor without delay_off also starts as unknown. I only observed the delayed variant.
  • Plugs that report less often than once a minute. With 5-minute reports, a 1-minute delay_on buys you nothing.

Related: the Log Book’s other Home Assistant note, on 32-bit Raspberry Pi installs that can never update their add-ons.

Facts

context: Home Assistant automation notifying when an appliance starts/stops, from a metering smart plug
problem: template binary_sensor with delay_on/delay_off is "unknown" after reload/restart; a from "off" trigger misses the first start
solution: trigger with not_from unavailable + to "on"; offset timestamps by the delays; estimate remaining time from a running average of past cycle lengths
verified_on: 2026-10-28
applies_to: Home Assistant 2026.10 template binary_sensor with delay_off; heat-pump tumble dryer (flat 385-465 W, hard stop, 80 min, 0.57 kWh)
does_not_apply_to: template sensors without delays (not tested); dryers with an anti-crease or cool-down phase

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Retour en haut