Esphome sonic sensor help

Hi, i have a running ultasonic sensor reading in %. but when values goes above then my values set it shows in -% like (-60%) ( in minus)
is their any way to set only when my sonic reading is <=80cm or >=25cm do the filers in percentage
or can we force set all values above above 80cm as 80cm.?

code im working on

 sensor:
  - platform: ultrasonic
    trigger_pin: GPIO5
    echo_pin: GPIO4
    id: my_sensor
    name: "Water-Level %"
    unit_of_measurement: "%"
    accuracy_decimals: 0
    update_interval: 10s
    filters:
      - lambda: return ((((x100)-25)-(80-25))/(80-25))-100;
      - filter_out: nan 

code info

  1. Tank Depth = TD al the way from the cover where the sensor is mounted to the bottom Sensor Value = x this is will stay the same as this is the reading from the sensor Excluded Distance = EX which is the distance I have on top from the sensor which is mounted to the cover to the highest level the water can reach
    return ((((x*100)-EX)-(TD-EX))/(TD-EX))*-100

what i want is, if sonic sensor takes reading of values 80+ it should force and set value as 80
say if its reading at 90cm it still should say as 80 cm
can we make somthing like this work?

on_value:
     then:
       - if:
          id(my_sensor).state > 80;  //  when sonic sensor reading is above 80cm 
        then:
         id(my_sensor).state = 80;    //  it should force set above 80cm values to 80 cm

@itsboo you could try this

  - platform: ultrasonic
    trigger_pin: GPIO5
    echo_pin: GPIO4
    id: my_sensor
    name: "Water-Level %"
    unit_of_measurement: "%"
    accuracy_decimals: 0
    update_interval: 10s
    filters:
    - lambda: |
        if (x < 25.0) return 0.0;
        else if (x > 80.0) return 80.0;
        else return (x);

not sure if you need calibration. If you do can you show me your logs at 25 & 80 or it will be somthing like this

    - calibrate_linear: 
          - 25.0 -> 0.0 
          - 80.0 -> 80.0

could make it 100%

    - calibrate_linear: 
          - 25.0 -> 0.0 
          - 80.0 -> 100.0

but then your lambda would be

    - lambda: |
        if (x < 25.0) return 0.0;
        else if (x > 100.0) return 100.0;
        else return (x);