Status of item (String) is not updated

Hello
I’m trying to run a rule to know the wind direction with the data that come from openweather, but it does not change the item, I was wondering if you know why, here are my sitemap and items.

when
Item LocalWeatherAndForecast_Current_WindDirection changed
then

if(LocalWeatherAndForecast_Current_WindDirection.state > 0 || LocalWeatherAndForecast_Current_WindDirection.state < 49.9 ) {
	direc_viento.postUpdate(" N ")
	logInfo("TIEMPO", "DIRECCION CAMBIADA N")
}

if(LocalWeatherAndForecast_Current_WindDirection.state > 50 || LocalWeatherAndForecast_Current_WindDirection.state < 89.9 ) {
	direc_viento.postUpdate(" NE ")
	logInfo("TIEMPO", "DIRECCION CAMBIADA NE")
}
if(LocalWeatherAndForecast_Current_WindDirection.state > 90 || LocalWeatherAndForecast_Current_WindDirection.state < 129.9 ) {
	direc_viento.postUpdate(" E ")
	logInfo("TIEMPO", "DIRECCION CAMBIADA E")
}
    if(LocalWeatherAndForecast_Current_WindDirection.state > 130 || LocalWeatherAndForecast_Current_WindDirection.state < 179.9 ) {
	direc_viento.postUpdate(" SE ")
	logInfo("TIEMPO", "DIRECCION CAMBIADA SE")
}

if(LocalWeatherAndForecast_Current_WindDirection.state > 180 || LocalWeatherAndForecast_Current_WindDirection.state < 229.9 ) {
	direc_viento.postUpdate(" S ")
	logInfo("TIEMPO", "DIRECCION CAMBIADA S")
}
if(LocalWeatherAndForecast_Current_WindDirection.state > 230 || LocalWeatherAndForecast_Current_WindDirection.state < 269.9 ) {
	direc_viento.postUpdate(" SW ")
	logInfo("TIEMPO", "DIRECCION CAMBIADA SW")
}
if(LocalWeatherAndForecast_Current_WindDirection.state > 270 || LocalWeatherAndForecast_Current_WindDirection.state < 319.9 ) {
	direc_viento.postUpdate(" W ")
	logInfo("TIEMPO", "DIRECCION CAMBIADA W")
}
if(LocalWeatherAndForecast_Current_WindDirection.state > 320 || LocalWeatherAndForecast_Current_WindDirection.state < 360 ) {
	direc_viento.postUpdate(" OW ")
	logInfo("TIEMPO", "DIRECCION CAMBIADA OW")
}

end

ITEMS

String direc_viento "direccion del viento [%s] " >

greetings and I await your answers

Do any of the logInfo statements show in your log?

Additionally your conversion of directions is wrong!

I’ll bet LocalWeatherAndForecast_Current_WindDirection has UoM and is expressed in degrees. (a Number:Angle type)

You’d need to extract the number part only, or compare with angles.

thanks for the speed of response
nothing comes out in the log
Why is the conversion incorrect?

thanks for the speed of response
that item gives a number in degrees that’s why my conversion attempt

Yep, so you are comparing apples with oranges.
32 ° > 30

Try

if(LocalWeatherAndForecast_Current_WindDirection.state > 0 | "°" ....

to get both sides in degrees.

When using 8 steps (N, NE, E,SE, S, SW, W, NW) each step has 45 degrees, the one for N goes from 337,5 over 360 to 22,5.

There are no log entries because of the problem mentioned by @rossko57

I think I understand the fault, but when doing the rule to the system I would not give the same unit that puts only should act on the number, I do not know if I explained, and if not how I could fix it

Did you try the example as given by @rossko57?

If you mean “how do I get just the number part of a number with units”?

(MyItem.state as quantityType).intValue

thanks for the help @rossko57 but I do not know how to use it, I searched but I do not see how, you can give me a little light

Instead of

use
if ( (LocalWeatherAndForecast_Current_WindDirection.state as QuantityType<Number>).intValue > 0 || ...

I think to save typing I’d do it once.

var Number xx = (LocalWeatherAndForecast_Current_WindDirection.state as QuantityType<Number>).intValue
if ( xx > 0 || xx < 50 ) {

thank you very much, the first part if I understand it I think it would be like that

`rule “cambio de direccion”

when
Item LocalWeatherAndForecast_Current_WindDirection received update
then

if((LocalWeatherAndForecast_Current_WindDirection.state as QuantityType<Number>).intValue > 0 || (LocalWeatherAndForecast_Current_WindDirection.state as QuantityType<Number>).intValue < 49.9 ) {
	direc_viento.postUpdate(" N ")
	logInfo("TIEMPO", "DIRECCION CAMBIADA N")
}

if((LocalWeatherAndForecast_Current_WindDirection.state as QuantityType<Number>).intValue > 50 || (LocalWeatherAndForecast_Current_WindDirection.state as QuantityType<Number>).intValue < 89.9 ) {
	direc_viento.postUpdate(" NE ")
	logInfo("TIEMPO", "DIRECCION CAMBIADA NE")
}
if((LocalWeatherAndForecast_Current_WindDirection.state as QuantityType<Number>).intValue > 90 || (LocalWeatherAndForecast_Current_WindDirection.state as QuantityType<Number>).intValue < 129.9 ) {
	direc_viento.postUpdate(" E ")
	logInfo("TIEMPO", "DIRECCION CAMBIADA E")
}
    if((LocalWeatherAndForecast_Current_WindDirection.state as QuantityType<Number>).intValue > 130 || (LocalWeatherAndForecast_Current_WindDirection.state as QuantityType<Number>).intValue < 179.9 ) {
	direc_viento.postUpdate(" SE ")
	logInfo("TIEMPO", "DIRECCION CAMBIADA SE")
}

if((LocalWeatherAndForecast_Current_WindDirection.state as QuantityType<Number>).intValue > 180 || (LocalWeatherAndForecast_Current_WindDirection.state as QuantityType<Number>).intValue < 229.9 ) {
	direc_viento.postUpdate(" S ")
	logInfo("TIEMPO", "DIRECCION CAMBIADA S")
}
if((LocalWeatherAndForecast_Current_WindDirection.state as QuantityType<Number>).intValue > 230 || (LocalWeatherAndForecast_Current_WindDirection.state as QuantityType<Number>).intValue < 269.9 ) {
	direc_viento.postUpdate(" SW ")
	logInfo("TIEMPO", "DIRECCION CAMBIADA SW")
}
if((LocalWeatherAndForecast_Current_WindDirection.state as QuantityType<Number>).intValue > 270 || (LocalWeatherAndForecast_Current_WindDirection.state as QuantityType<Number>).intValue < 319.9 ) {
	direc_viento.postUpdate(" W ")
	logInfo("TIEMPO", "DIRECCION CAMBIADA W")
}
if((LocalWeatherAndForecast_Current_WindDirection.state as QuantityType<Number>).intValue > 320 || (LocalWeatherAndForecast_Current_WindDirection.state as QuantityType<Number>).intValue < 360 ) {
	direc_viento.postUpdate(" OW ")
	logInfo("TIEMPO", "DIRECCION CAMBIADA OW")
}

end

`
I’m sorry but the second part I do not understand

when the rule works we will start if the conversion of the degrees is correct @opus

For a solution look into that one.

hello the rule already works … but badly this is the log
2019-05-31 22:12:26.606 [INFO ] [clipse.smarthome.model.script.TIEMPO] - DIRECCION CAMBIADA N
2019-05-31 22:12:26.651 [INFO ] [clipse.smarthome.model.script.TIEMPO] - DIRECCION CAMBIADA NE
2019-05-31 22:12:26.695 [INFO ] [clipse.smarthome.model.script.TIEMPO] - DIRECCION CAMBIADA E
2019-05-31 22:12:26.753 [INFO ] [clipse.smarthome.model.script.TIEMPO] - DIRECCION CAMBIADA SE
2019-05-31 22:12:26.787 [INFO ] [clipse.smarthome.model.script.TIEMPO] - DIRECCION CAMBIADA S
2019-05-31 22:12:26.814 [INFO ] [clipse.smarthome.model.script.TIEMPO] - DIRECCION CAMBIADA SW
2019-05-31 22:12:26.839 [INFO ] [clipse.smarthome.model.script.TIEMPO] - DIRECCION CAMBIADA W
2019-05-31 22:12:26.867 [INFO ] [clipse.smarthome.model.script.TIEMPO] - DIRECCION CAMBIADA OW

he ignores the more and less, and I do not understand why.
thank you very much @opus then I will see how to modify the values

You haven’t asked for more and less, you wrote more or less. Try

if ( xx >= 0 && xx < 50 )

1 Like

thank you very much to the two already works perfectly with this doubt I have learned to handle the variables “and, or”