I see a bunch of potential issues.
-
presenceLightAlteris a string variable? Or is that the name of your Item. If it’s the name of your Item you need to put it into quotes.ir.getItemtakes a String representing the Item’s name. -
This one isn’t a problem, but you don’t need to pull an Item to check it’s state. Just use the
itemsdict.items["presenceLightAlter"]will give you the state of the Item named “presenceLightAlter”. -
I’m unfamiliar with
StringValue()and I don’t see it mentioned anywhere in the openHAB classes. Do you meantoString()? -
NULLis an actual Item state and callingtoString()on an Item’s state that isNULLwill give you “NULL” as a String.UNDEFis another potential state your Item can be. If the Item exists, the only way that the string representation of the Item’s state would be an empty string is if it’s a String Item and you set the state to the empty string. If it’s never been initialized the string representation of the state will be “NULL”. If the binding determined it can’t know the state of the Item, the string representation of the state will be “UNDEF”.
Therefore, if you want to check that the Item’s state is not UNDEF, not NULL, and has a non-zero length string representation you would use
if isinstance(items["presenceLightAlter"], UnDefType) and items["presenceLightAlter"].toString().length() > 0:
Note that Items, states, and all of that are Java Objects so all the same Java stuff will apply. So in this case because the Item’s state is a Java Object it has a toString() method which returns a Java String which in turn has a length() method.
The Python len function should work as Jython is pretty good converting between Java stuff and Python stuff for the basic classes like String.