How to catch received values early (before item update)?

I have Neo Coolcam sensors which send from time to time wrong values:

Power Plugs send for their kWh values in rotatory good and bad values, like -21474641.41 instead of something close to 195.039993286 kWh.
So, some good values come in, then some bad (negative) numbers come in, some good, some bad… Absolutely regularly and repeatable.
They say it’s not their fault, it’s the hub I use, without asking what system I actually use…

Motion Sensors send temperature (and lumen) values too low, by a few degrees, down to zero. Very very seldom also a negative value.
Here’s the pattern the radio quality. Higher distance = higher chance to get a wrong value. I have twenty of them, most are fine, but 2 produce wrong messages more than others, regardless how far they are positioned.

Solution (not fully working):
In my (Python) rules I inspect the values and I set it back to the previous state if it’s bogus.
So in BasicUI the numeric values are always ok.

However, in the charts the large down-peaks are still visible and they ruin the view.

Attempts to fix
I tried this and that, but realized it’s probably hopeless because (it seems) there is no way to catch those values, because what I receive are sensor values, not commands, so I’m limited to when the rule triggers:
• To late:
@when(“Item ITEM_NAME received update”)
• Of course to late:
@when(“Item ITEM_NAME changed”)
• Does not trigger:
@when(“Item ITEM_NAME received command”)

I thought with autoupdate=“false” and the rule trigger “received update”, it should be possible, but the item updates, regardless of autoupdate=“false” in place.

Do I something wrong?
This is my item definition:

Number BD_Steckdose_Geraete_kWh       "BD Geräte kWh [%.2f]"                     (BD_Group, kWhGroup)                                              {channel="zwave:device:xxx:node23:meter_kwh", autoupdate="false"}

If autoupdate=“false” is not working, is there another way to catch sensor values early, before the item get’s updated?

Use an Item linked to the sensor Thing Channel to get the sensor value & another Item updated by a script to ignore the values you wish to ignore?

Bruce’s suggestion is one option. Another one is to manipulate the persisted data. Charts come from persistence. If you stop auto persisting the Items, you can then use a rule to update the Item and then manually persist (see the persist extension) the corrected values.

1 Like

Typical for OpenHAB is there is more than one way to do it. :smiley:

I don’t know what you expected that to do, but it certainly does NOT interfere in binding-to-Item updates, nor is it intended to. It’s about openHAB commands.

With some bindings, you can apply transformations in your Thing to massage data. But not with zwave binding.

profiles are more generic and can be applied to channels before the Item gets updated. It’s the kind of thing you want to do, but - the transform profile only works with String Items at the moment, probably useless for you.

There is an offset profile that works with Number types and is exactly intended to correct small errors e.g. +1.5. It will not cope with your nonsense numbers though.

1 Like

I would have to create about 100 dummy items just to display corrected values. I’m so glad I switched to Python because it allows me to use OH’s item meta data - no more helper/dummy/proxy items. :slight_smile:

I remember that there was an issue with charts not working if the persist strategy does not include “everyMinute”. My strategie looks so:
strategy = everyChange, everyMinute

So if I remove “everyChange” (an persist manually) it would likely work most of the time, maybe except if a bogus value comes right in when the “everyMinute” persist executes?

I was suggesting to remove these Items entirely from the .persist file. What do you have in yours?

I just tried to persist manually, but get the error

AttributeError: 'org.eclipse.smarthome.core.library.items.ContactIt' object has no attribute 'persist'

The code in my rule:

triggeringItemName = event.itemName
triggeringItem = ir.getItem(event.itemName)
triggeringItem.persist

I do not select any items in the .persist file, if you meant that.

Strategies {
everyMinute : "0 * * * * ?"
everyHour 	: "0 0 * * * ?"
everyDay	: "0 0 0 * * ?"
default = everyChange
}
Items {
* : strategy = everyChange, everyMinute
}

Side note, regarding the forum editor: The “code fence” button is gone?
image
How to mark text as code?

It is an action from PersistenceExtensions…

from core.actions import PersistenceExtensions

PersistenceExtensions.persist(triggeringItem)

Actually, the splat means you are persisting ALL Items. You could create a group and throw everything in it except for the Items you do not want to persist.

Forget the button… just put three ticks (```) on an empty line before and after your code or logs.

1 Like

The buttons - all of the various codestyles - are still there, but invisible. This is a bit more apparent when you have mouse-hover available.

1 Like

It works now. :slight_smile:

I went that way now, thank you. Persistence works as expected, but I still get some spikes in the charts - must be an error in the logic of my rule, which I will work out on sunday. Oh, it’s sunday. :wink:

Quite a workaround (adds complexity) just to handle bogus sensor values. Hopefully OH will have some day a trigger which catches incoming values before anything else is processed.

Thank you. Hopefully I don’t forget it when I post something in 3 months again. :grimacing: Must be an interface designed for Pro’s. Easy and obvious is bad practice. :wink: