Esphome for x time

Is there a way to make a sensor that only returns a value if it has been in a state for x seconds? I can’t figure out how to do it in esphome.

Use case is I have an ultrasonic sensor that bounces its values around a bit and sometimes has incorrect readings where it will jump from 3 meters down to .5 meters then back up again.

Sounds like a task for a moving average filter

You can apply a variety of filters including debounce and moving window average to reduce the effects of bouncy inputs.