Ignoring empty MQTT Payload

Hi together,

I receive values from my watermeter using AI on the edge. In case there are invalid values, the MQTT sender sends empty values. This is correct behavior from my point of view. Nevertheless I receive the following warning. Any idea how to fix this to have a clean log?

2024-03-12 17:46:23.261 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '' from channel 'mqtt:topic:watermeter:Zaehlerstand' not supported by type 'NumberValue': null

Have to tried to use string item? I think that worked for me in the past.

The value is stored within a DB (influxDB), I assume a string is difficult for using the value.

Use REGEX to filter to make sure it is a number

You can use a REGEX transformation that only matches numbers.

REGEX:([\d]+)

If it’s anything else beyond one or more digits the message will be ignored without warning. If you need to support negative signs or decimals or units of course the REGEX needs to be more complicated.

@denominator beat me to it.

1 Like

Nevertheless the item would be a string instead of a number then!? This does not feel correct. What about calculation, DB storage etc.?

No, it will still eventually be converted to a Number just like it is now.

An MQTT message always is a String. It gets converted to a Number (assuming it’s a number Channel) just before it gets sent to the Item as a command or update.

I think you need to decide if storing a value in influxDB is more important than clearing the WARN. It seems to me if you are going to convert to a number for graphing purposes, then just send that number to mqtt in the first place. Another option is to filter out the Warn with regex. Just an observation.

I saw also this: [mqtt] Treat incoming empty string as NULL for most types by ccutrer · Pull Request #16307 · openhab/openhab-addons · GitHub
Might fix it anyhow with OH 4.2 in the future?

This is exactly what that PR is meant to address. Though note that in the context of this thread, many persistence addons (including InfluxDB) will simply ignore NULL values, and not record anything at all when an item goes to NULL (which would be the same as its current behavior in your case, if you have it set to persist on change).