How to get an empty string to an item?

Hi,
i have configured the holiday-example script and rule from the old openhab-wiki.

It works on my 2.3 snapshot version.

Only problem:

How can i clear the saved information in a string item?

Which one is the right to do this?

Here is a part of my holiday-script:

var String holidayName = null
...
else if (dayOfYear==parse(year+"-07-01").getDayOfYear) {
    holidayName = "Juli 1st" // 1. Juli
    holiday = false
}
if (holidayName!==null) {
    postUpdate(SpecialDay,holidayName)
}
if (holiday) {
    postUpdate(Holiday,ON)
}
else {
    postUpdate(Holiday,OFF)
	postUpdate(SpecialDay,holidayName)
}

So if today is not july 1st, i want to get an empty string. But on my sitemap there is displayed null.

And visibility != null doesn´t work…


Another question: what is the meaning of this

if (holiday) {
    postUpdate(Holiday,ON)

There is no = or something for the variable holiday behind it in the first line???

same as:

if(holiday==true)

if I understood your question correctly.

var String holidayName = ""
if (holidayName!=="")

Ok, thanks, i will try this.

Is the string-value “” and null and NULL the same in openhab 2.3?

I think this should be work.

var String holidayName = ""
...
else if (dayOfYear==parse(year+"-07-01").getDayOfYear) {
    holidayName = "Juli 1st" // 1. Juli
    holiday = false
}
if (holidayName!=="") {
    postUpdate(SpecialDay,holidayName)
}
if (holiday == true) {
    postUpdate(Holiday,ON)
}
else {
    postUpdate(Holiday,OFF)
	postUpdate(SpecialDay,holidayName)
}

Ok, now i get an empty place displayed in my sitemap.

But is this the same as a completely unfilled string-item?

Shouldn´t there be a “-” rather then nothing?

I think there is a difference if the string-value is empty or there is saved this --> “”.

I think “” is a String with no Content and @ null the string doesn’t exits.

If you want work with null, I think you can work with a mapping

map file

NULL=-

I found out why i get “null” displayed in the sitemap: I already have a transformation and there was null=null

So it displayed the transformation “null”, not an empty string.

I removed null=null and now i get a warning that there is no target value inside the transofrmation file. Is there a way to remove trhis warning or is this just a warning and in this case i can not change anything?

I also made a logging, now i get this:

2018-01-03 11:50:29.166 [INFO ] [rthome.model.script.Feiertags-Script] - Berechnung Feiertage: SpecialDay (Type=StringItem, State=null, Label=Tagesbezeichnung, Category=null)

This seems to look ok.

But the sitemap shows the line with an empty value-place, the visibility-command is not working:

Text item=SpecialDay visibility=[SpecialDay != null]

Now i changed all to “” and made a transformation only with = in one line.

Now there is no ore warning and it seems, that it is working like i want it.

Log-File changed from State=null to State=

Is the visibility-command looking for the original value or for the transformed value in a string?

Because visibility != null wasn´t working… Or is this not working with null at all?

null != NULL

null is an uninitialized (or initialized to null) var while NULL is an uninitialized item. I think for visibility you should use

visibility=[SpecialDay != NULL, SpecialDay != ""]

Oh, was this fixed or changed? Some time ago i wanted to do exactly the same, --> visibility with two expressions, and that was not possible. I had to make this with a virtual item between.

Can i now use 2 expressions for visibility?


In my script the variable gets the value null at startup. At the end my item is updated with the value of the variable.

So when the variable was null at the beginning and is still null, the item will get the value NULL? This will be changed automatically?

Argh… You’re right, false boolean algebra…