Ignore read of temperature if

hi, i have problem with reads of temp data. I use rf433 sensor sometimes it sends bad data -67C :confused: to read it i use JSONPATH:$.message.temperature is there a way to ignore data string if it sends -67 ? and just leave actual data ?

1 Like

i’m to new in this :frowning: so if i go to scripts and paste that on web panel, in my thing channel i have:
Type number : digoo_temp [ stateTopic=“home/OpenMQTTGateway/PilighttoMQTT”,transformationPattern=“JSONPATH:$.message.temperature”] i should add somewhere temp.js if i create one via web panel ?

You can’t create the javascript file via web panel. You need to make a traditional file and place it in your /transform folder.
You will need to install the JS javascript transformation add-on.
Then, because you happen to use MQTT binding, you can chain your new JS transform after your existing JSONPATH.

1 Like

thx so something like that : [ stateTopic=“home/OpenMQTTGateway/PilighttoMQTT”,transformationPattern=“JSONPATH:$.message.temperature∩temp.js"]

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