How to ignore wrong readings from sensors?

My z-wave temperature sensors sometimes gives the measurements that I believe are wrong. For example this one:

I really don’t remember running my fusion reactor this week…
Do you have any idea how to get rid of those random reads from history, so my diagrams looks anything useful? and if possible ignore them at all in thing/point update.

There are lots of options. Assuming OH 4:

  1. Use the include/exclude filters in your persistence config to ignore values outside a given range: Persistence | openHAB

  2. Add a transform Profile on the link with a Script transform to ignore values that are too big of a difference from the last reading. Using JS it would look something like the following:

(function(data) {
  const parsed = parseFloat(data);
  const lastState = cache.private('last', () => data);
  const parsedLastState = parseFloat(lastState);
  const delta = Math.abs(lastState - parsed);
  return (delta > 5) ? lastState : data;
  1. Exclude the Item from the persistence config entirely and implement a rule with the same logic as the transform above. Only persist the Item’s state if the delta is less than a threshold by calling .persist on the Item. This approach will not work with rrd4j as your persistence database.

I’ve chosen #2.
There’re 2 things missing in your code:

  1. const lastState = cache.private.get(‘last’, () => data);
  2. where’s no cache.private.put(...) anywhere.

The only thing I don’t like is that I need to create a separate copy of this rule for every sensor, but it’s acceptable.

I have no idea how i lived without knowing how to use those transformations for so long :smiley:

No you don’t. We can work around that.

The function doesn’t actually have anything hard coded that makes it so we cannot reuse it.

If defined in the UI under Settings → Transformations you define it once and refer to it by UID in the transform settings. If you choose to use a .js file, you refer to the file name instead.

If you have different thresholds, you can pass that in as an argument. See Transformations | openHAB

I’m assuming that each profile gets a different instance of the transformation. If that’s not the case you can pass in a unique id as an argument as well.

For example, if you have a .js file it would be something like filter.js?threshold=5&id=livingroomTemp and the function would become something like

(function(data) {
  const parsed = parseFloat(data);
  const lastState = cache.private.get(id, () => data);
  const parsedLastState = parseFloat(lastState);
  const delta = Math.abs(lastState - parsed);
  if(delta > parseFloat(threshold)) {
    return data;
  else {
    return lastState;

Still I have no idea how to do this…
Programming is easy, setup is hard.
Here’s a screenshot that would tell you what I’m doing wrong. Keeping it in link looks so easy, but not very configurable. (I forgot: yes, I’m using OH 4)

You should be able to edit this but that was something fixed. Are you running (I think that’s the latest). IIRC this was back ported.

If not, you’ll have to upgrade to 4.1 M1 or snapshots to get the ability to typ/edit the transform, not just select it.

I will wait for stable release and look for it then.