Z-Wave: How to filter implausible sensor values?

After I found the solution to filter implausible sensor values for my MQTT devices by using a JS transformation in a transformation pattern on the channel in my .things file (see https://community.openhab.org/t/mqtt-how-to-filter-implausible-values-on-channel/82833/3?u=vossivossi ) I wonder if I could also implement an equivalent solution for my Z-Wave sensors.
However my Z-Wave things are not managed via a .things file and I am not sure if the binding supports a transformation pattern on the channel (I could not find any reference to this in the docs). So my next idea was to try a JS transformation with a profile on an ItemChannelLink in my Z-Wave .items file. I was using the same JS coding as with MQTT but after I edited my .items file accordingly the values of the items were not updated anymore at all. I read in other posts here that there is a possible restriction with JS transformations for numeric items as they apparently always return a String type. But for the numeric MQTT thing channel the JS tranformation worked fine.
What I did is to append my item with the transformation profile:

Number  PO_SPEI_SN  "PO_SPEI_SN"  <energy>	(sumwatt_light_og, gshelly)  {channel="zwave:device:ZWOG:node93:meter_watts"[profile="transform:JS", function="filter_ltminus100_gt100.js"]}

The JS function looks like this:

(function(i) {
	var val = parseFloat(i);
	if (val >= 100 || val <= -100 )
		{ return 'UNDEF'; }
		{ return val; }

Any help or hints are highly appreciated!

Can’t help with JS but let me point you at my presentation I gave on using sensors for presence detection linked to here .
Point is, transformations work on a single value only. That way you cannot implement advanced validation/correction to combine multiple sensor’s data into one value to work on such as to use a median or quorum value. There’s some idea level pointers how to use rules or lambdas.

Transform profile only returns a string, and unfortunately that is currently not parsed for a Number Item.
Good idea, but the transform profile is lacking here and just won’t work with Number types yet.

Thank you very much for clarification. So the tranform profile on items behaves different than the transform pattern for channels, correct? That is really unfortunate. I this on purpose or just missing functionality?

Kind of. When the binding applies a transform to raw data before passing it to a channel, the binding’s author makes sure the output gets parsed into something appropriate for the channel type.

The profile currently doesn’t take account of target Item type.

It’s more a limitation of the framework applying the profile, than any difference in the actual transform.

This does crop up at regular intervals, I meant to raise an enhancement request for it before, done now.

1 Like