Sensor Filters: Lambda Delta/ Clamp

Hello. I need to filter out the sensor values which are over 1% of the previously reported value of that sensor. It is the inverse of the Delta Filter.

A Global Variable would achieve the same thing but I thought there might be a quick and easier way to do it?

PS. This is a large water tank; so I am absolutely sure this has been done before!!!
PPS. I think I am trying to create a percentage clamp

Global variable or template sensor could do it.
Another option could be saving last value as static variable

lambda: |-
  static int previous_value = 0;
  //your filter code here//
  previous_value = x;
1 Like