Ignore read of temperature if

No. Like you did with your JSONPATH, you first have to say what kind of transformation to use. In this case, JS. Right idea though.

1 Like

ok i fith i known now :
stateTopic=“home/OpenMQTTGateway/PilighttoMQTT”,transformationPattern=“JSONPATH:$.message.temperature ∩ JS:temp.js"]

so i have a file transform\temp.js:
(function(i) {
var val = parseFloat(i);
if (val >= 100 || val <= -60 )
{ return ‘UNDEF’; }
else
{ return val; }
})(input)
and channel :
Type number : digoo_temp [ stateTopic=“home/OpenMQTTGateway2/PilighttoMQTT”,transformationPattern=“JSONPATH:$.message.temperature ∩ JS:temp.js”]

and still sometimes i can see temperature -67 :frowning:

Do you ever see UNDEF? What do your logs say about it?

val looks suspiciously like a keyword to me, don’t know if it is or if it matters.

Its my first time just use a script from 2nd post. But i think script isn’t used like it should be on lof file i found : transformation service JS for patten temp.js not found. I think the space is a problem just dont know it should be temperature ∩JS:temp.js or temperature∩JS:temp.js i have to try

See

id did it before and check again it’s installed, but at log file i see two spaces like " service JS"

Take the spaces out of there.

1 Like

i did when i seen it at log file just nithing happend now no errors but if thermomether sends :
{“message”:{“id”:0,“temperature”:-67.77,“humidity”:0.00,“battery”:1,“channel”:1},“protocol”:“tfa”,“length”:“0”,“value”:“0”,“repeats”:2,“status”:2} i still get it on OH
i have to learn more to fix it
good message is :
{“message”:{“id”:124,“channel”:2,“battery”:1,“temperature”:16.9,“humidity”:96},“protocol”:“nexus”,“length”:“124”,“value”:“124”,“repeats”:2,“status”:2}

so i see the id is different too meaby i will find a way to use it because im to new in this.

We can test your script and logic in a rule

val rawjson = '{"message":{"id":0,"temperature":-67.77,"humidity":0.00,"battery":1,"channel":1},"protocol":"tfa","length":"0","value":"0","repeats":2,"status":2}'
val intermediate = transform("JSONPATH", "$.message.temperature", rawjson)
logInfo("test", "from JSON " + intermediate)
val chained = transform("JS", "temp.js", intermediate)
logInfo("test", "from JS " + chained)

and get expected results

2021-06-26 21:53:25.840 [INFO ] [.eclipse.smarthome.model.script.test] - from JSON -67.77
2021-06-26 21:53:25.871 [INFO ] [.eclipse.smarthome.model.script.test] - from JS UNDEF

The only other thing that has to happen is the MQTT binding to pass UNDEF through the number type channel. Maybe it doesn’t,but it used to.

Makes more sense than random values, a report from some different device with a missing sensor.

You can select messages by ID, but use a different technique. Forget the JS altogether, use a REGEX transformation to select messages with the wanted ID (and discard messages without), then chain on your JSONPATH to select the data value you want.

1 Like

i don’t remember when i read so many things :wink:
so if i understand something like that should be fine :
stateTopic=“home/OpenMQTTGateway2/PilighttoMQTT”,tranformationPattern=“REGEX:(.124)∩JSONPATH:$.message.temperature”

if string have “124” then it should read temperature ?

Well,more like
REGEX:(.*124.*)
if you follow the example.
And that will match “124” anywhere in the message. I’d use
REGEX:(.*:124.*)
to match including the colon character : … but that is a special character here and so we must ‘escape’ it
REGEX:(.*\\:124.*)

1 Like

i think i broke something :frowning:
[WARN ] [ab.binding.mqtt.generic.ChannelState] - Incoming payload ‘{“message”:{“id”:124,“channel”:2,“battery”:1,“temperature”:16.1,“humidity”:96},“protocol”:“nexus”,“length”:“124”,“va
lue”:“124”,“repeats”:2,“status”:2}’ not supported by type ‘NumberValue’
now it ignore all

i set it like that :
Type number : digoo_temp [ stateTopic=“home/OpenMQTTGateway2/PilighttoMQTT”,tranformationPattern=“REGEX:(.\:124.)∩JSONPATH:$.message.temperature”]

REGEX transformation too is an installable addon.

The asterix in my example are functional, not decorative.

You may or may not have used double backslash \\ for escape, we cannot tell when you don’t use code fences.

1 Like

regex was installed, sorry for asterix i copied all to notepad and dont know why it wasnt there :frowning: i think its too late i remove regex from thing and log still says its not a number. thx for help ill check it tomorrow

ok i checked it even reboot OH no errors in log file etc but today onece i seen -67 value :frowning:
thing is :
Type number : digoo_temp [ stateTopic=“home/OpenMQTTGateway2/PilighttoMQTT”,transformationPattern=“REGEX:(.\:124.)∩JSONPATH:$.message.temperature”]

Please use code fences. It’s the </> thingy above the box you type in. Then we can see what you see.

It’s not clear; your WARN has magically gone away? It’s not unusual for edits of xxx.things files to not take effect until you restart the binding.

It’s not clear if you’ve seen the -67 value or where you’ve seen it since your last edit/reboot. If you are getting MQTT messages with the ID and with the -67, then you’ll have to chain on the JS as well to filter them out.

i think warn was because i first add line regex and then install transformation.
Message was on mqtt and then iteam change value from 23 to -67.77 so looks like REGEX on my thing wasnt used :frowning: the id of message on mqtt was like before “0” not “124”
I even use visual studio not notepad to edit file.

The REGEX either makes a match and passes the whole message along to JSONPATH, or there is no match and nothing is passed.
The match in this case is to :124, so that can match with "id":124 or "elephant":124876, but not "banana124":367124

You might want to look closely, or perhaps even share with us, the message that you think slipped through.
You might want to check if your Item is linked to any other channels as well.

1 Like

Hi, thx againt it works :smiley: just once then i had -67 value meaby some lag of system etc. Since few days it’s ok

1 Like