MQTT binding - setting "Undefined" as new state for an item

I have an Arduino board connected by MQTT to my OpenHAB 1.8 installation.
The Arduino board receives some sensor data like the temperature of a 433MHz temperatur sender.
All is working well, but now one of my 433MHz sensors stopped working so the arduino didnt’ receive any new temperature from the sensor. Because the item didn’t change the state, the OpenHAB item keeps the last temperature showing which is not correct.

For that case I want to sent “Uninitialized” from Arduino to OpenHAB for a sensor which has not get an update for the last e.g. 10 Minutes. In OpenHAB I want to see “-” as temperature, like the value was not initialized.

I tried to send the value “Uninitialized” as state to the OpenHAB item, but I get the error
"[WARN ] [] - given new state is NULL, couldn't post update for 'ARDUINO_01_03_TEMP'"

The item is defines as

Number  ARDUINO_01_03_TEMP  "03 Temp [%.1f °C]"   {mqtt="<[phc:/phc/FromArduino/BOARD/01/SENSOR/03/01/TEMP:state:REGEX((.*))]"}

For testing I have sent the MQTT message with
mosquitto_pub" -h rpi2 -t /phc/FromArduino/BOARD/01/SENSOR/03/01/TEMP -m Uninitialized
mosquitto_pub" -h rpi2 -t /phc/FromArduino/BOARD/01/SENSOR/03/01/TEMP -m -

How is it possible to set the state/value of an OpenHAB item to “Uninitialized” with MQTT?

Thanks Andreas

If you use the string UNDEF or NULL in your MQTT message, it ought to match the corresponding UnDefType constant in the TypeParser while it tries to find a suitable State with which to update your Number item. I recommend UNDEF since it matches semantically what you are trying to do.

The strings Uninitialized and Undefined are “output-only” strings in openHAB 1 that have been removed in Eclipse SmartHome.

Thanks for the quick response.

It works…
If I send “UNDEF” the state is set to “Undefined”, if I send “NULL” it is set to “Uninitialized”.

1 Like