[SOLVED] JSON message with null values in numbers does not update item state


I have problems with json messages with NaN values in numbers. openHAB is simply ignoring them and not actualizing items.

I have a MQTT thing with a channel type Number configured with this jsonpath transform

This MQTT payload


will produce the following log

2020-02-17 16:48:06.312 [vent.ItemStateChangedEvent] - BadzimmerTemp changed from 26.6 °C to 2.0 °C

Humidity item is not updated, and no warning is thrown. I would spect a NULL to show in the item.

But this payload works


2020-02-17 16:51:01.779 [vent.ItemStateChangedEvent] - BadzimmerTemp changed from 26.6 °C to 2.0 °C
2020-02-17 16:51:01.779 [vent.ItemStateChangedEvent] - BadzimmerHum changed from 31.9 to 4

Is there an alternate transformation to convert null to NULL or NaN?

My setup is

openHAB version 2.5.1-2 (deb package)
Debian 10 on LXC container
Mosquitto 1.5.7-1+deb10u

MQTT binding binding-mqtt - 2.5.1

Thank you for your help

I wouldn’t.
Bindings should not set Item states to NULL
Bindings may at the author’s discretion set UNDEF in some circumstances.

Taking no action instead seems like a reasonable option to me.

Bear in mind that if the Humidity field was completely absent, null would be returned, and “do nothing” would be the most reasonable action to take there.

You could chain the transformations, passing the result from the JSONPATH to a JS transform with a conditional to convert “null” to UNDEF (see rossko57’s post for why you should not use NULL and NaN isn’t a valid state for a Number Item. Otherwise just pass the value on through. Or you could parse the JSON and convert the “null” all in the one JS transform.

NOTE: This will only work if you are processing these as updates, not commands. You cannot command an Item to UNDEF

Thank you very much.