Several comparsions

I need a rule wih two comparsions running

What will be the best implementation?
Now have a not working one

if (weather_wind_deg > 200 && weather_wind_deg < 300) 
	{
	postUpdate(weather_toland, "Landing")
	}
if (weather_wind_deg > 40 && weather_wind_deg < 120) 
	{

	postUpdate(weather_toland, "Takeoff")
	}
else
	{
	postUpdate(weather_toland, "Alternative")
	}

What exactly is not working? Perhaps you need to compare the value with item state and not the item itself?

Thank you!

Do not know how i missed that line

Still with this rule i see the item first set to landing and than immediately to alternative. Should i rewrite all as elseif?

rule "Takeoff Landing"
when
Item weather_wind_deg received update
then
if (weather_wind_deg > 200 && weather_wind_deg < 300) 
	{
	postUpdate(weather_toland, "Landing")
	}
if (weather_wind_deg > 40 && weather_wind_deg < 120) 
	{
	postUpdate(weather_toland, "Takeoff")
	}
else
	{
	postUpdate(weather_toland, "Alternative")
	}
end
rule "Takeoff Landing"
when
Item weather_wind_deg received update
then
if (weather_wind_deg.state as DecimalType > 200 && weather_wind_deg.state as DecimalType < 300) 
	{
	postUpdate(weather_toland, "Landing")
	}
else if (weather_wind_deg.state as DecimalType > 40 && weather_wind_deg.state as DecimalType < 120) 
	{
	postUpdate(weather_toland, "Takeoff")
	}
else
	{
	postUpdate(weather_toland, "Alternative")
	}
end

As @rtvb mentioned, you need to compare the state, not the Item itself. Also, you need to cast the state to a DecimalType so the Rules knows that it is a number.

With this code i get the following

 Error during the execution of rule 'Takeoff Landing': An error occured during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.BooleanExtensions.operator_and(boolean,boolean) on instance: null

Are you sure that weather_wind_deg has a value and isn’t undefined?

Yes pretty sure.
Fixed by removing as decimal type. I guess i forgot to mention that i’m running OpenHab 2 so guess the behaviour is different

This is a copy from log. Lines go one after another.
In the items file i have

Number	weather_wind_deg		"Wind degree [%.0f °]"	(g_Weather)	{weather="locationId=forio, type=wind, property=degree"}

Here is the log

2016-06-22 21:30:36.301 [INFO ] [marthome.event.ItemStateChangedEvent] - weather_wind_deg changed from 297.00 to 299.00
2016-06-22 21:30:36.309 [ERROR] [.script.engine.ScriptExecutionThread] - Error during the execution of rule 'Takeoff Landing': An error occured during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.BooleanExtensions.operator_and(boolean,boolean) on instance: null

I don’t know what is wrong. It looks right.

You can try splitting up the conditions and not use the &&.

There is no need to split as rule is working. I guess that “as DecimalType” somehow doesn’t work. I will try to debug to best of my knowledge (which is little) and provide the results.
Thank you for helping out

I often see that type of error on math comparisons of item states when I first restart openHAB. In my case I think it’s because something hadn’t yet polled the items to get their initial states

This was after more than 8 hours of running. Weather items are polled every 2 minutes, so definetly not the case