Howto rules where a value may be NaN/NULL?

I’m using a power value of a Zwave plug that perfectly works. however, if this item is unplugged and Openhab resets/initializes with “–” the rule of course does not work anymore…

if (HomeOffice_Power.state > 200) .....

Does a simple (HomeOffice_Power.state == NULL) work?..if an item has never received any value and in the UI i can see a “–”.


There are two null states that an Item can have as a state. I assume the Zwave binding is using them correctly in which case:

State Meaning
NULL The Item has never received a state since openHAB loaded the Item, uninitialized
UNDEF The binding has no way to determine the state of the device, unknown

You can check for both of these states (and you should in almost every Rule)

if(HomeOffice_Power.state intanceof UnDefType)

In Python that would be

if isinstance(items["HomeOffice_Power"], UnDeftype:

The Sitemap will render NULL and UNDEF with -. Look at events.log, or query for the state of the Item using the Karaf console or the REST API to see exactly what the state is.

ssh -p 8101 openhab@localhost 'smarthome:status HomeOffice_Power`
1 Like

Thanks a lot for the feedback.

According to Restful API its a NULL.
So i would check ==NULL and instanceof UnDefType ???

Thanks Norbert

You don’t need to check the type. It’s either equal NULL or equal UNDEF, both are valid states for any Item type.

Checking for the type is a quick way to test for both NULL and UNDEF in one statement.

if(MyItem.state instanceof UnDefType)

is the same as

if(MyItem.state == NULL || MyItem.state == UNDEF)

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.