How do I include a trigger and condition in a template?

Hi Home Assistant Wizards,

A while ago I wrote an automation that notifies us when the laundry machine has finished. It has a trigger that begins the automation once the washer uses a lot of electricity for at least one minute, and is followed by a condition that fires after the washer stops using more-than-standby electricity for 15 seconds. The delays ensure the notification doesn’t accidentally fire when the machine pauses mid-cycle while it switches to spin mode, or whatever. So far it’s been very reliable.

alias: Laundry notification - washer finished
description: Send a notification when the washer has finished.
trigger:
  - platform: numeric_state
    entity_id: sensor.washer_switch_electric_consumption_w
    for:
      hours: 0
      minutes: 1
      seconds: 0
    above: 100
condition: []
action:
  - wait_for_trigger:
      - platform: numeric_state
        entity_id: sensor.washer_switch_electric_consumption_w
        for:
          hours: 0
          minutes: 0
          seconds: 15
        below: 5
  - service: notify.both_of_us
    data:
      title: Laundry
      message: The washer has finished.
    alias: Send notifications to both of us
mode: single

When the latest release (2023.9) dropped, it included a “template helper” type, which made me want to revisit this.

What I want is a “washer status” boolean state that shows “running” when the washer is triggered, and switching to “not running” when it’s finished. I would then trigger my notification based on the status of the boolean state changing from “running” to “not running”. It makes the most sense to me to define the rule once, then have the various dependencies based on the single instance of the state. That way if I change the rules, I only change them in one place.

So far, I have been able to set a state showing me when the washer is running based on whether or not it is using a lot of electricity, but it doesn’t have the trigger or conditions that the automation has. It flips on and off during a wash cycle.

This is what I have so far:

{% set washer_w = states('sensor.washer_switch_electric_consumption_w') | float %}
{% if washer_w > 100 %}
  result = on
{% else %}
  result = off
{% endif %}
result

Can someone tell me how to include the triggers and conditions in the template that mimic my for ... below trigger and for ... above condition? I’d also appreciate a pointer to any documentation (internal or external) that would explain how to implement HassIL in Jinja templates.

Thanks!