Washing Machine Template

Hey all,
So I know plety of blueprints and FAQ’s exist to automate your washing machine but they all seem overly complicated. I want a single template called “washing machine status” that has 3 states" running, idle, or change so I can send notifys until it goes to idle. I want it to use 2 sensors, one for power and one for the appliance door. Here is what I have so far in my template.yaml:

sensor:
  - name: "Washing Machine Status"
    state: >
      {% if states('sensor.washer_power')|float > 1 %}
        running
      {% elif state_attr('sensor.Washing_Machine_Status', 'device_last_run') > state_attr('sensor.Washing_Machine_Status', 'device_last_open') %}
        change
      {% else %}
        idle
      {% endif %}
    attributes:
      device_last_run: >
        {{ now() if is_state('sensor.washing_machine_status', 'running') }}
      device_last_open: >
        {{ as_local(states.binary_sensor.zha_switch_1.last_changed )}}

Everything seems to be working except the device_last_run attribute goes to null after it finishes thus negating the change state. Basically, I just want a template to tell me when I need to change my clothes in as few lines as possible. Thanks for lokking at my code, you guys are awsome!

The easy solution would be to set up an automation which triggers when sensor.washer_power goes below a certain value, and sets an input_datetime to the current time. Then you can amend your template sensor’s attribute to use the value of the input_datetime when the sensor state is not running.

There might be a more elegant way of doing it than that, I’m not sure.

1 Like

This is what I use.