Ignore read of temperature if

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