OH3 rule conditions AND | OR

That’s the rub though, null isn’t and Object. It’s its own special thing in JS and most other programming languages.

There is special handling for null or else the logger would be throwing exceptions all over the place.

I don’t quite understand that but in Java it’s the same as in JaveScript. null is a special type of primitive and not an Object and therefore does not have a toString().

By the time it gets to the Widget, it’s just text anyway, null, number, or otherwise.

I took it straight from the code in openhab-js. And this method has not changed as long as I’ve been using openhab-js.

In JS Scripting, .state has always been the String representation of the Item’s state. Towards the end of OH 3, numericState and quantityState were added which returns the state as a primitive JavaScript float or as a JavaScript Quantity.

Example Type Result
items.Temperature.state String "65 °F"
items.Temperature.quantityState Quantity 65 °F
items.Temperature.numericState float 65
items.Temperature.rawState org.openhab.library.types.State 65 °F

Note, I’m guessing at the full name of the Java State. And it will come over as a State but can be used as a QuantityType or a DecimalType. But you’ll have to convert it to a JS type to do much of anything with it in your rule.

Unless you go out of your way, in JS Scripting you are always working with JavaScript Objects. So the Item you get from Items.getItem() is a JavaScript Object. Unless it has raw in the name, it’s JavaScript.

ohh i forgot to include that in the screen the strange behaviour of javaScript with regards to typeof(null)
But stackoverflow also has it nicely:

undefined behaves like you described for null, but

typeof(null)

reutrns object… but

null instanceof Object

returns false, which makes somewhat sense an empty list ist somehow not an Object or is it.

There is reason I fkn hate all kind of scripting languages :-).

So for me I come to conclusion, Blockly does it right with setting null in that system. my querry somehow does what it should, even null != “Null”, so most probably the .state method returns nulland not “Null” if the state is questioned and the item is Null. A widget will Dispaly “Null” most prbably as it is cathed if an item is null…

By the way thank you with the list of state and what it returns… I have to closer figure out what exactly changed between OH3 and OH4 breaking my scripts regarding item.state with GrallJS that worked before in NashornJS.

The thing is I looked at all that code. It doesn’t return null, ever. Neither the Java Item class nor the openhab-js code has anything to convert NULL to null and that’s leaving UNDEF completely out of the discussion. All openhab-js does is convert the Java UnDefType.NULL object to the string "NULL". (same as it does for all Item state types).

If that way, then it get’s tricky with the blockly null… will investigate that when I finally found the unknown ID js from the other discussion… It drives me crazy :slight_smile: