How to get home assistant to ignore invalid values for kwh?

I have some zwave sensors that report kwh but the problem is every now and then they report very high numbers that skews everything up. In this example the living room purifier showed kWh consumption at 5000 for a brief second so my utility meter that sums these values is now messed up. I created a template entity here:

- sensor:
  - name: "Living Room Purifier kWh Template"
    unique_id: living_room_purifier_template
    unit_of_measurement: "kWh"
    state_class: measurement
    state: >
      {% if states('sensor.living_room_purifier_electric_consumption_kwh') == 'unavailable' %}
        0
      {% elif states('sensor.living_room_purifier_electric_consumption_kwh') | float > 100 %}
        0
      {% else %}
        {{ states('sensor.living_room_purifier_electric_consumption_kwh') }}
      {% endif %}

that is supposed to not see values above 100 but this didnt seem to work

so now my utility meter that watches living_room_purifier_template is skewed

How can i avoid this? Im using zooz zwave sensors with latest firmware

Maybe you can use some filter. Either a moving average, a lowpass or range filter: Sensor filters