Automation only trigger when numeric state changes from a value above 5 to below 1?

I am using smart energy meters with Tasmota on my dishwasher and washing machine to track if they are finished.
So if on of them goes below 1W power consumption, for 5 minutes I will get a notification that it finished.

The problem is, this worked flawlessly until around February. Since then HA started send random notifications that the dishwasher or washing machine finished even though they were never turned on. For the washing machine this happens way more often than for the dishwasher.

So my guess is, that Tasmota sometimes reports random values above 1W which causes HA to think that the value changed below 1W. Though I might be wrong because these changes are not visible in the history.

My question is, can I somehow change the trigger to only fire when the value goes from above 5W to below 1W?

It would be helpful if you share the automation as well as the trace from a time it was triggered improperly.

You’re describing a threshold sensor, it’s a type of helper you can add. You can set an upper limit of 3 and then a hysteresis of 2. It will turn on when it goes above upper+hysteresis and off when it goes below upper-hysteresis. Then just trigger when that sensor goes from on to off.

To do it in an automation without the threshold sensor would be more complicated. You’d need to do one of the following:

  1. have two triggers, one for over 5w and one for under 1w. When it goes over 5w then set an input boolean on. When it goes under 1w and the boolean is on the send a notification and turn the boolean off
  2. trigger for over 5w and then use a wait for trigger action to wait until it goes below 1w and send the notification.

I should note that if you choose option #2 then you will not get a notification if you restart HA or change any automation while the laundry is running as the automation will stop mid execution (during the wait). #1 and the threshold sensor don’t have this issue. I would recommend threshold personally since you need to add a helper either way but up to you.

4 Likes

I just looked at the last trace and it actually jumped from “unavailable” to “0.0 W” which explains why it has been triggered.

So I guess the solution would be to use a numeric state trigger with a value template that simply filters out dropouts where the state is unavailable and return 0.0 instead.

Alright, changing my trigger from device triggers to a numeric state trigger like this

platform: numeric_state
entity_id: sensor.washing_machine_energy_power
for:
  hours: 0
  minutes: 2
  seconds: 0
below: '1'
value_template: >-
  {{ states('sensor.washing_machine_energy_power') if
  (states('sensor.washing_machine_energy_power') | is_number) else 0 }}

should do the trick now. If not I will try out the threshold sensor like @CentralCommand suggested, thanks!