Issue with NULL state

Hello,
I’m getting an error when a sensor item (Netatmo_Indoor3_Humidity) is not available temporarily.

18:07:00.359 [ERROR] [untime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Update Group Temp/Humity': f != java.lang.String

The error is raised due to below code, which make sense to me as the item is NULL

Keller_Temp_Hum.postUpdate( Netatmo_Indoor3_Humidity.state.format("%d")  +"%")

I added below if condition, however this didn’t solve the problem, which is not clear to me.

		 if (Netatmo_Indoor3_Humidity.state == NULL)
	   	{
	   		Keller_Temp_Hum.postUpdate("Kein Sensor gefunden!") 		
	   	}
	   	else
	   	{
		   	Keller_Temp_Hum.postUpdate( Netatmo_Indoor3_Humidity.state.format("%d")  +"%")
	   	}

If I remove the “else” condition, the item is updated with the expected text, which proved that if condition does match and item is NULL.
However, once I add the “else” condition, the error appears again.
It seems the else condition is processed, even the If condition is true, which is strange.

I already tested the if condition with different formats.

if (Netatmo_Indoor3_Humidity.state == NULL)

and

if (Netatmo_Indoor3_Humidity.state === NULL)

Do I miss something else?

Many thanks for a hint :slight_smile:

Stefan

Seems I found the issue - strange however.
When I use UNDEF instead of NULL, then the condition is working now.
Just wondering when the state is NULL or UNDEF?
Maybe this has changed during the testing.

That won’t be happening unless you messed up the curly brackets somewhere. You can gain more info -

		 if (Netatmo_Indoor3_Humidity.state == NULL)
	   	{
	   		logInfo("test", "In the NULL branch")
	   		Keller_Temp_Hum.postUpdate("Kein Sensor gefunden!") 		
	   	} else {
	   		logInfo("test", "In the NORMAL branch")
		   	Keller_Temp_Hum.postUpdate( Netatmo_Indoor3_Humidity.state.format("%d")  +"%")
	   	}

This is most likely referring to a .format(xx) clause somewhere. Maybe that is the only one in this rule, or…?

You are right -the error is due to the

.format(xx)

I changed the condition as below and now it is working.

		   	if (Netatmo_Indoor3_Humidity.state == UNDEF || Netatmo_Indoor3_Humidity.state == NULL)
	   	{
	   		Keller_Temp_Hum.postUpdate("Kein Sensor gefunden!") 		
	   	}
	   	else
	   	{
		   	Keller_Temp_Hum.postUpdate( Netatmo_Indoor3_Temperature.state.format("%.1f") + "°C (" + Netatmo_Indoor3_Humidity.state.format("%d")  +"%)")
	   	}

However I’m still not clear when UNDEF or NULL is used.
As one hour ago the condition also matched with NULL. Now its matching with UNDEF only.
Seems the value is changing sometimes for unknown reason.

NULL: Uninitialized. The Item was created but there has been nothing (Rule, Binding, restoreOnStartup) that has given the Item a State yet. All Item when OH starts or when OH reloads the .items files, start out with NULL as the state.

UNDEF: Undefined. The Item has had a State but now the binding doesn’t know what state it is in. For example, some technologies can be queried for their current state. Others, like MQTT 2.x, will set an Item to UNDEF if it loses the connection to the MQTT broker.

An hour ago the Item was uninitialized. At some point the Item got a value from the Netatmo binding. Then the Netatmo binding determined that it lost the connection to the sensor so it set the Item to UNDEF.

1 Like