Issue with item state

Hello,

I have an issue with the item state when building a rule for the Battery for Netatmo.
The item type should be Number according to the documentation.
I tried already different approaches to convert (.floatValue of . intValue,) but I always get the error

Rule 'AkkuCheck': An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_doubleArrow(T,org.eclipse.xtext.xbase.lib.Procedures$Procedure1) on instance: null

When I just use below, without the “if then” statement

sendBroadcastNotification("Niedriger Akkustand - Sensor Keller!\n Kapazität: " + Netatmo_Indoor3_BatteryVP.state.toString + "%")	

then the Battery value is shown as 15.00, hence it is not NULL.

Can someone guide me what is wrong with the if/then command?

// Keller
	//
	if ((Netatmo_Indoor3_BatteryVP.state as DecimalType).floatValue < 30 && (Netatmo_Indoor3_BatteryVP.state as DecimalType).floatValue => 15)
	{
		sendBroadcastNotification("Niedriger Akkustand - Sensor Keller!\n Kapazität: " + Netatmo_Indoor3_BatteryVP.state.toString + "%")		
	}
	if ((Netatmo_Indoor3_BatteryVP.state as DecimalType).floatValue < 15)
	{
		sendBroadcastNotification("Kritischer Akkustand - Sensor Keller!\n Kapazität: " + Netatmo_Indoor3_BatteryVP.state.toString + "%")		
	}

Many thanks
Stefan

I changed the rule as below (instead of DecimalType I use Decimal)
(I also tried with intValue, floatValue)

	// Keller
	//
	if ((Netatmo_Indoor3_BatteryVP.state as Decimal).intValue < 30 && (Netatmo_Indoor3_BatteryVP.state as Decimal).intValue => 15)
	{
		sendBroadcastNotification("Niedriger Akkustand - Sensor Keller!\n Kapazität: " + Netatmo_Indoor3_BatteryVP.state.toString + "%")		
	}
	if ((Netatmo_Indoor3_BatteryVP.state as Decimal).intValue < 15)
	{
		sendBroadcastNotification("Kritischer Akkustand - Sensor Keller!\n Kapazität: " + Netatmo_Indoor3_BatteryVP.state.toString + "%")		
	}

and get now another error

Error during the execution of rule 'Luftentfeuchters LaufzeitTimer': Could not cast 14.00 to void; line 42, column 7, length 42

Rules DSL is a bit funny about numeric comparisons. Instead of all the decimal stuff, just use as Number.

if ( (Netatmo_Indoor3_BatteryVP.state as Number) < 15)

When I use this format, then I get below error (just tested)
(ignore the rule name - I use this for testing)

15:25:02.536 [ERROR] [untime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Luftentfeuchters LaufzeitTimer': An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_doubleArrow(T,org.eclipse.xtext.xbase.lib.Procedures$Procedure1) on instance: null
	// Keller
	//
	if ((Netatmo_Indoor3_BatteryVP.state as Number) < 30 && (Netatmo_Indoor3_BatteryVP.state as Number)  => 15)
	{
		sendBroadcastNotification("Niedriger Akkustand - Sensor Keller!\n Kapazität: " + Netatmo_Indoor3_BatteryVP.state.toString + "%")		
	}
	if ((Netatmo_Indoor3_BatteryVP.state as Number)  < 15)
	{
		sendBroadcastNotification("Kritischer Akkustand - Sensor Keller!\n Kapazität: " + Netatmo_Indoor3_BatteryVP.state.toString + "%")		
	}
		

Perhaps we could check what this Item type actually is?

Thats the definition in .item config file

Number Netatmo_Indoor3_BatteryVP          "BatteryVP [%.0f %%]"            <battery>          { channel = "netatmo:NAModule4:home:inside2:BatteryVP" }

Ah, it pays to scroll all the way to the right.
Not => but >=

The general advice about using Number types in rules where possible still holds.

As far as i know it should be DecimalType instead of Decimal

(Netatmo_Indoor3_BatteryVP.state as DecimalType).intValue

Many thanks for pointing this out - I didn’t see it, but its so obvious. :frowning:

Its working now :slight_smile: