Template Sensor Bounce Issue

I have a template sensor I use with a temperature sensor to set a variable indicating whether the dishwasher is running. The trouble I am having is that I get bounce on the sensor because I am testing whether the temperature is 85 or above and it will go 84.8, 84.9, 85.0, 85.1, 84.9, 85.0, etc. causing the sensor to be too sensitive. Is there any way in a template sensor to specify the condition has to be met for x minutes? I know it’s possible in other places but I can’t find anything about duration in a template sensor. The sensor code is below.

I thought about casting to an integer but it will still bounce between 84 and 85 then…

dishwasher_running:
        friendly_name: "Dishwasher Running"
        value_template: >-
          {{ states('sensor.wirelesstag_dishwasher_temperature')|float > 85}}

I think the Threshold Binary Sensor might help. E.g.:

binary_sensor:
  - platform: threshold
    entity_id: sensor.wirelesstag_dishwasher_temperature
    upper: 84.5
    hysteresis: 0.5

This sensor will be turned on when sensor.wirelesstag_dishwasher_temperature goes above 85 (i.e., 84.5 + 0.5), and will be turned off when sensor.wirelesstag_dishwasher_temperature goes below 84 (i.e., 84.5 - 0.5). When sensor.wirelesstag_dishwasher_temperature is between 84 and 85, inclusive, the state will not change.

1 Like

I really like that answer and have bookmarked it.
And it answers the OP’s need nicely
But to actually answer the question : -
You could use the delay_on option and specify a time (you choose a time suitable)
delay_on: “00:00:57”
That’s 57 seconds (let’s make it a Heinz moment). ; - ))))

Good point. And although delay_on answers the question more directly, I think delay_off might be more appropriate. :slight_smile:

Hell, you could use both. : -)
Or even all three !
They don’t cost per use do they ??? : - )))

Edit: Phil’s post below highlights the subtle differences in signal conditioning requirements given what ‘you’ want out of it.
As I said in my first post in this thread, hysteresis is the one that best fits the need. The thermal inertia of a dishwasher will mean you shouldn’t need a wide band either so 1° (0.5 either way) should also fit the bill.
Sorry if our verbal banter cast ANY doubt on the best way to proceed.

FWIW, the Threshold Binary Sensor with a non-zero hysteresis effectively acts as a Schmitt trigger, which is exactly what this application needs. Also, @RobFromLI, I wouldn’t necessarily describe the signal as “bouncing.” What you’re seeing is typically referred to as “noise.” A Schmitt trigger (in this case the Threshold Binary Sensor) is the typical way of dealing with noise in this type of application. The delay_off/delay_on parameters of the Template Binary Sensor would, in general, be more appropriate for filtering out “bouncing.”

Thank you so much for your help gentlemen! Sorry it took me a couple of days to get back to this thread. I have implemented both suggestions and will report back which one works better (or if both work well!) Unfortunately I have to wait now for someone to run some dishes to test it but in our house that should not take too long!

Well both techniques worked well, but I’m sticking with the delay on and delay off, just because. But great to know about both techniques, thanks again!