Sensor template state

Good morning,
I have a sensor template set up in my sensor.yaml file for the power state on my washing machine. Probably 95% of the time it works just fine.

  - name: "Washing Machine"
    state: >
      {% if states("sensor.washer_switch_0_power")|float == 0  %}
        Off
      {% elif states("sensor.washer_switch_0_power")|float <= 2.2 %}
        Standby
      {% else %}
        Washing
      {% endif %}
    icon: >
      {% if states("sensor.washer_switch_0_power") == "off"  %}
      mdi:washing-machine-alert
      {% elif states("sensor.washer_switch_0_power")|float <= 2.2  %}
      mdi:washing-machine-off
      {% else %}
      mdi:washing-machine
      {% endif %}

The problem I’m having, is that sometimes on certain wash cycles, it will go below that 2.2 value for a few seconds. It also will trigger above that threshold if the washer was off, and I accidentally hit the selector knob while transferring a load or something. Is there a way to add a time factor in here, so it has to be below 2.2 for more than a minute or something like that?

Only in a Trigger-based Template Sensor because it employs triggers and a certain triggers (State, Numeric State) support the for option.

Food for Thought

The following post explains what I did. Scroll a few posts further in the topic and you’ll find a second post containing the associated Template Sensor.

@Taras,
Very cool. I’ll have to play around with mine and see if I can get some sort of corresponding power values for the different cycles. It’s something I had thought about doing, but the important thing has always been if it’s running or done, and report it on the card.

Edit:
I was reading through your explanation. Do you fill values get thrown off at all by the water temp? In theory it shouldn’t (one tap for warm, one tap for cold, both taps for warm, etc), but was curious if you noticed anything different and if you had to adjust your values accordingly when setting it up.

Honestly, I stopped using it.

All it took was to set a different wash program (Delicate, Heavy Duty, etc) and the power consumption and duration of the phases would be altered and that would derail tracking the washing phases. In addition, pausing any phase would also change the timing.

I no longer had any interest to characterize the power consumption of all the different wash programs plus the novelty of being informed that the wash was done had worn off so I abandoned it entirely.

Is the delay_off variable set to 5-10 mins not sufficient for this purpose?

Template - Home Assistant (home-assistant.io)

(I haven’t figured out how to format this nicely like Taras has. See binary_sensor configuration section)

I would see what the power consumption in standby after completing a cycle is and set the threshold at that value. Then only if it is below the threshold for X minutes will the binary sensor turn off.

I use this on a binary_sensor.guests_connected entity which looks for guest WiFi devices. I use delay_off set to 15 mins to keep the sensor on even when iPhones power saving features turn WiFi off for a few minutes. It works perfectly for me and never turns off guest mode guests are long gone. It looks like this in my config, change the state as required for your use case:

- binary_sensor:
  - name: "Guests Connected YAML"
    icon: "mdi:human-greeting-proximity"
    state: >
      {{ states.device_tracker 
      | selectattr('entity_id', 'match', 'device_tracker.amplifi.*') 
      | selectattr('entity_id','match','device_tracker.amplifi_192_168_*')
      | selectattr('state', 'eq', 'home') 
      | list 
      | count }}
    delay_off: 0:15:00

EDIT: I suppose this won’t work if you insist on knowing the exact second the washing is finished, but I can’t imagine the washing machine or dishwasher is ever so critical that you can’t wait an extra 10 minutes for the notification, but to each their own.

I was wondering how you got past that. I had looked at trying to do this a while back and couldn’t come up with any sort of pattern that was recognizable across different cycles.

I used a similar approach with my dishwasher, and that does work, but I’m simply recognizing off, wash, dry, and clean cycles. The washing machine eluded me. I’d be happy to eliminate the false reporting.

Not insisting, no. I just want to eliminate false alerts when the power drops below a level for a short duration. Even a 1 minute delay should eliminate those false positives.

In that case, definitely try out the delay_off setting and experiment with the delay required to avoid false positives. You will have to migrate the sensor to a YAML definition though as this setting is not available in GUI yet to my knowledge. Good luck!