[SOLVED] Help needed for a Rule for preticipation forecasting

Hello, i need your help to finalize a rule for preticipation forecast. i want to trigger the item “Regenvorhersage_12” with a rule but i am struggling. In fact the item “Regenvorhersage_12” should be “ON” if there is a minimum level of preticipation in 3, 6, 9 or 12 hours and a minimum level of probability or if the summ of rain over the next 12 hours exceeds a certain treshold. It should only trigger if the item is not already on this state. Here is what i have so far:

``````val minPrecip = 1.0		// vorhergesagter minimaler Regen
val minProba  = 25		// Mindestwahrscheinlichkeit
val culRain   = 1.0		// Mindestmenge addiert

rule "Regen in den kommenden 12 Stunden"
when
Time cron "0 * * * * ?" // every minute
//		Time cron "0 0 * * * ?" // every hour
then
var rain = new Boolean("false")
var Number culm

if ((VorhergesagterRegen3hours.state >= minPrecip) && (Precip_Probability.state >= minProba))
{	rain = true
}
if ((VorhergesagterRegen06hours.state >= minPrecip) && (Precip_Probability.state >= minProba))
{	rain = true
}
if ((VorhergesagterRegen09hours.state >= minPrecip) && (Precip_Probability.state >= minProba))
{	rain = true
}
if ((Regenin12Stunden.state >= minPrecip) && (Precip_Probability.state >= minProba))
{	rain = true
}

culm = (VorhergesagterRegen3hours.state as Number) + (VorhergesagterRegen06hours.state as Number) + (VorhergesagterRegen09hours.state as Number) + (Regenin12Stunden.state as Number)
if (culm >= culRain) { rain = true
}

if (rain = true) {
if (Regenvorhersage_12.state == OFF) {
//			sendTelegram("Jan2", "innerhalb der kommenden 12 Stunden wird es regnen")
Regenvorhersage_12.sendCommand(ON)  }
}

if (rain = false)  {
if (Regenvorhersage_12.state == ON) {
//			sendTelegram("Jan2", "innerhalb der kommenden 12 Stunden wird KEIN Regen erwartet")
Regenvorhersage_12.sendCommand(OFF)  }
}

end
``````

Here is the the warning message from the log:

``````2019-05-03 09:56:01.751 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'Regen.rules', using it anyway:
The value of the local variable rain is not used
``````

If the item is “ON”, it goes OFF so there seems to be an issue with setting rain = true.

Thank you community for your advices here of what i am missing.

BR
Jan

That will always be true. You need == for if statements

As will this. The if statement will evaluate to true as its assigning false to rain

Thanks Crispin, i changed it, but still i believe the IF loops don´t put the var rain to true. There is no log entry and when i manually turn the item Regenvorhersage_12 to ON, it goes OFF after 1 minute when the rule runs. The variables should trigger to True at the moment ( next 3 h and culm )

``````val minPrecip = 0.3		// vorhergesagter minimaler Regen
val minProba  = 25		// Mindestwahrscheinlichkeit
val culRain   = 0.05 		// Mindestmenge addiert

rule "Regen in den kommenden 12 Stunden"
when
Time cron "0 * * * * ?" // every minute
//		Time cron "0 0 * * * ?" // every hour
then
var rain = new Boolean("false")
var Number culm

if ((VorhergesagterRegen3hours.state >= minPrecip) && (Precip_Probability.state >= minProba))
{	rain = true
}
if ((VorhergesagterRegen06hours.state >= minPrecip) && (Precip_Probability.state >= minProba))
{	rain = true
}
if ((VorhergesagterRegen09hours.state >= minPrecip) && (Precip_Probability.state >= minProba))
{	rain = true
}
if ((Regenin12Stunden.state >= minPrecip) && (Precip_Probability.state >= minProba))
{	rain = true
}

culm = (VorhergesagterRegen3hours.state as Number) + (VorhergesagterRegen06hours.state as Number) + (VorhergesagterRegen09hours.state as Number) + (Regenin12Stunden.state as Number)
if (culm >= culRain) { rain = true
}

if (rain == true) {
if (Regenvorhersage_12.state == OFF) {
//			sendTelegram("Jan2", "innerhalb der kommenden 12 Stunden wird es regnen")
Regenvorhersage_12.sendCommand(ON)  }
}

if (rain == false)  {
if (Regenvorhersage_12.state == ON) {
//			sendTelegram("Jan2", "innerhalb der kommenden 12 Stunden wird KEIN Regen erwartet")
Regenvorhersage_12.sendCommand(OFF)  }
}

end
``````

There are a lot of numeric comparisons with Item states in your rule. You generally need to convert the states to Number for effect.

if ( (someItem.state as Number) == target )

Beware also, if you use UoM you will need to deal with units.

Thanks rossko57,

here is the change, but no different behaviour. The IF loops still seem to be the issue.

what exactly do you mean with UoM and Units?

The item states are in mm

``````2019-05-03 14:10:22.266 [vent.ItemStateChangedEvent] - Regenin12Stunden changed from 0.0 mm to 1.188 mm
``````
``````val minPrecip = 0.05	// vorhergesagter minimaler Regen
val minProba  = 0		// Mindestwahrscheinlichkeit
val culRain   = 0.05	// Mindestmenge addiert

rule "Regen in den kommenden 12 Stunden"
when
Time cron "0 * * * * ?" // every minute
//		Time cron "0 0 * * * ?" // every hour
then
var rain = new Boolean("false")
var Number culm

if ((VorhergesagterRegen3hours.state as Number) >= minPrecip && (Precip_Probability.state as Number) >= minProba )
{	rain = true
}

if ((Regenin12Stunden.state.state as Number) >= minPrecip)
{	rain = true
}

if ((VorhergesagterRegen06hours.state as Number) >= minPrecip && (Precip_Probability.state as Number) >= minProba )
{	rain = true
}
if ((VorhergesagterRegen09hours.state as Number) >= minPrecip && (Precip_Probability.state as Number) >= minProba )
{	rain = true
}
if ((Regenin12Stunden.state as Number) >= minPrecip && (Precip_Probability.state as Number) >= minProba )
{	rain = true
}

culm = (VorhergesagterRegen3hours.state as Number) + (VorhergesagterRegen06hours.state as Number) + (VorhergesagterRegen09hours.state as Number) + (Regenin12Stunden.state as Number)
if (culm >= culRain) { rain = true
}

if (rain == true) {
if (Regenvorhersage_12.state == OFF) {
//			sendTelegram("Jan2", "innerhalb der kommenden 12 Stunden wird es regnen")
Regenvorhersage_12.sendCommand(ON)  }
}

else  {
if (Regenvorhersage_12.state == ON) {
//			sendTelegram("Jan2", "innerhalb der kommenden 12 Stunden wird KEIN Regen erwartet")
Regenvorhersage_12.sendCommand(OFF)  }
}

end
``````

Okay you have units, so comparing e.g. 2mm to 2 is ineffective.
You can either extract the state without the units, or compare it to something with units.

I am testing it but first look is that the link to the threat did the trick. Many thanks for your support rossko57. I let you know once i fully tested it. It is raining a lot today so good moments to test

Here is how i changed the rule and it seems working

``````val minPrecip = 1.00	// vorhergesagter minimaler Regen
val minProba  = 20		// Mindestwahrscheinlichkeit
val culRain   = 1.25	// Mindestmengen addiert

rule "Regen in den kommenden 12 Stunden"
when
//		Time cron "0 * * * * ?" // every minute
Time cron "0 0 * * * ?" // every hour
then
var rain = new Boolean("false")
var Number culm
culm = (VorhergesagterRegen3hours.state as Number).floatValue + (VorhergesagterRegen06hours.state as Number).floatValue + (VorhergesagterRegen09hours.state as Number).floatValue + (Regenin12Stunden.state as Number).floatValue

if ((VorhergesagterRegen3hours.state as Number).floatValue >= minPrecip && (Precip_Probability.state) >= minProba )
{	rain = true
logInfo("RainVolume","RainVolume in 3 hours: " + VorhergesagterRegen3hours)
}

//			if  ((Regenin12Stunden.state as Number).floatValue >= minPrecip )
//				{	rain = true
//					logInfo("RainVolume","RainVolume in 12 hours: " + Regenin12Stunden)
//				}

if ((VorhergesagterRegen06hours.state as Number).floatValue >= minPrecip && (Precip_Probability.state as Number) >= minProba )
{	rain = true
logInfo("RainVolume","RainVolume in 6 hours: " + VorhergesagterRegen06hours)
}
if ((VorhergesagterRegen09hours.state as Number).floatValue >= minPrecip && (Precip_Probability.state as Number) >= minProba )
{	rain = true
logInfo("RainVolume","RainVolume in 9 hours: " + VorhergesagterRegen09hours)
}
if ((Regenin12Stunden.state as Number).floatValue >= minPrecip && (Precip_Probability.state as Number) >= minProba )
{	rain = true
logInfo("RainVolume","RainVolume in 12 hours: " + Regenin12Stunden)

}

if (culm >= culRain) { rain = true
}

if (rain == true) {
if (Regenvorhersage_12.state == OFF) {
sendTelegram("Jan2", "innerhalb der kommenden 12 Stunden wird es regnen")
Regenvorhersage_12.sendCommand(ON)  }
}

else  {
if (Regenvorhersage_12.state == ON) {
sendTelegram("Jan2", "innerhalb der kommenden 12 Stunden wird KEIN Regen erwartet")
Regenvorhersage_12.sendCommand(OFF)  }
}

end
``````

Fine that your Rule is now working. One question from me: From where do you get the “Precip_Probability/Regenwahrscheinlichkeit”.? Are you using a free account from OWM or a paid one ?

cheers
Peter

I am using OWM and ForecastIO. At the Moment VorhergesagterRegen comes from OWM and Proba comes from ForecastIO. Still need to check the reliability of the data for my usecase.