How can I add a filter to an automation

So I would like to use an untrasonic sensor to detect if something is in front of it.
Any idea how to add a filter to an automation. I need the ultrasonic sensor to only trigger if it’s above a certain value for a specific time frame. It let’s me do that with binary sensors.

I think you also need to look at Sensors. This is where you can filter you sensor data to get what you need, using on_value: to trigger.

For example:

sensor:
  - platform: hx711
    name: "Fish food hopper"
    id: fish_food_hopper
    dout_pin: 27
    clk_pin: 26
    filters:
      - calibrate_linear:   
        - 406000 -> 0    
        - 3405000 -> 5000
      - sliding_window_moving_average:    
          window_size: 10    
          send_every: 3
    update_interval: 1.0s
    unit_of_measurement: gm
    accuracy_decimals: 0
    on_value:
      then:
        -  if:                                   # Hopper weight is within limits
            condition:
              sensor.in_range:
                id: fish_food_hopper
                above: 250.0
                below: 5000.0
            then:
              - binary_sensor.template.publish:
                  id: hopper_is_at_low_level
                  state: OFF
1 Like

It is not actually a filter needed here, it is a condition.