MQTT "DateTime"-item: how to sent NULL

I have a DateTime item

  - id: sent1
    channelTypeUID: mqtt:datetime
    label: Gesendet
    description: null
    configuration:
      stateTopic: servers/Mowas/sent1

it is linked to a DateTime item:

What payload is expected to “reset” the DateTime-item to NULL?

I tried:

  1. empty payload
  2. “null”
  3. “NULL”
  4. “-”
  5. “UNDEF”

leads to an WARN like this (with different “message” in the same ):

2024-01-10 16:21:55.403 [WARN ] [transport.mqtt.internal.Subscription] - A subscriber of type 'class org.openhab.binding.mqtt.generic.ChannelState' failed to process message '' to topic 'servers/Mowas/sent1'.
2024-01-10 16:21:58.556 [WARN ] [transport.mqtt.internal.Subscription] - A subscriber of type 'class org.openhab.binding.mqtt.generic.ChannelState' failed to process message '6E756C6C' to topic 'servers/Mowas/sent1'.
2024-01-10 16:22:01.757 [WARN ] [transport.mqtt.internal.Subscription] - A subscriber of type 'class org.openhab.binding.mqtt.generic.ChannelState' failed to process message '4E554C4C' to topic 'servers/Mowas/sent1'.
2024-01-10 16:22:04.368 [WARN ] [transport.mqtt.internal.Subscription] - A subscriber of type 'class org.openhab.binding.mqtt.generic.ChannelState' failed to process message '2D' to topic 'servers/Mowas/sent1'.
2024-01-10 16:22:08.358 [WARN ] [transport.mqtt.internal.Subscription] - A subscriber of type 'class org.openhab.binding.mqtt.generic.ChannelState' failed to process message '554E444546' to topic 'servers/Mowas/sent1'.

is it even possible to “reset” a Datetime?

How? It’s not clear. Did you update the Item, command the Item, send an MQTT message?

Are you just trying to update the Item or are you trying to also have a message posted or both?

The datetime Channel is only going to support a message that can be parsed into a date time so any message that gets published to that topic is going to generate an error if it’s not parsable as a date time.

sorry, I forgot to mention: MQTT messages.

Use Case:

  • I’m converting some realy biiiig JSON in Node-Red into seperate MQTT-messages
  • I send them to OH
  • as they’re warning alerts (weather, hazards, fire, high water, …) they get -hopefully!- cancelled, if the situation clears, so I’d like to reset the “sent”-DateTime to NULL

I feared that. To silence my inner monk I guess I’ll have to write a rule, if an event was cancelled, the DateTime is also nullified…

That would probably be the easiest approach.

Another, and I think more complicated approach, would be to change the Channel Type to be a text Channel. But add a Script transformation that passes the string if it’s parsable and passes 'NULL' if not. In JS that would look something like this:

(function(input){
  if(input.length == 0) return 'NULL'; // time.toZDT() will treat empty string as `now`

  // if it parses, pass it through
  try {
    time.ZonedDateTime.parse(input);
    return input;
  } 
  // Failed to parse, return `NULL`
  catch(error) {
    return 'NULL';
  }

})(input)

This transform will ensure that what gets passed to the Item will be a proper DateTime. All other Strings become NULL.

1 Like

I’m not sure, if my inner Monk justifies that efforts… :wink: perhaps I’ll just sent 1.1.1970. :see_no_evil: