What payload is expected to “reset” the DateTime-item to NULL?
I tried:
empty payload
“null”
“NULL”
“-”
“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'.
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.
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…
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.