The item definition is:
DateTime ItemName “Time is [%1$tH:%1$tM]”
Question is, how do I reset it (i.e. back to null?) so the UI will show “-:-” as the time. To clarify, I don’t want to set it to “00:00” as that’s a valid time.
I don’t believe it is possible to set the state of an item to undefined. I think that UnDefType is only used as the default state when openHAB starts, but you can’t set it back to this state manually.
Bindings are permitted to post item updates to UnDefType.NULL at any point, so would it make sense to allow rule code to do the same? Maybe if you ignore the Designer’s complaint about importing org.openhab.core.types.UnDefType it would work?
No idea if the Designer will have a whinge or not, but this correctly resets the original Item to UnDefType.NULL:
import org.openhab.core.library.items.*
rule "test rule 2"
when
Time cron "0/5 * * * * ?"
then
var nullValue = new DateTimeItem("trashTalking").state
postUpdate(ZWaveZWLastUpdate, nullValue)
end
Hi,
I’ve been tryping to reset a datetime in jsr223 javascript using the method above. Unfortunately, I get an error that I cannot postUpdate null to a datetime item. Does anyone have an idea how to do it in a javascript?
Here’s my script:
var nullValue = new DateTime().state;
console.debug(nullValue)
postUpdate(‘RandomTimeItem’, nullValue);
and here’s the log output:
|undefined|
Error during evaluation of script ‘file:…js’: The argument ‘state’ must not be null.
Thanks
Update:
Well, I now use a standard rule for this
var nullValue = new DateTimeItem("soll leer sein").state
postUpdate(Teichpumpe_Zeit_An, nullValue)
but it would still be nice if this could somehow be added to the jsr so I can reduce the number of depedent rules.