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
logInfo( "------Regen 3-------", VorhergesagterRegen3hours )
}
if ((VorhergesagterRegen06hours.state >= minPrecip) && (Precip_Probability.state >= minProba))
{ rain = true
logInfo( "------Regen 6-------", VorhergesagterRegen06hours )
}
if ((VorhergesagterRegen09hours.state >= minPrecip) && (Precip_Probability.state >= minProba))
{ rain = true
logInfo( "------Regen 9-------", VorhergesagterRegen09hours )
}
if ((Regenin12Stunden.state >= minPrecip) && (Precip_Probability.state >= minProba))
{ rain = true
logInfo( "------Regen 12-------", Regenin12Stunden )
}
culm = (VorhergesagterRegen3hours.state as Number) + (VorhergesagterRegen06hours.state as Number) + (VorhergesagterRegen09hours.state as Number) + (Regenin12Stunden.state as Number)
if (culm >= culRain) { rain = true
logInfo( "------Regen culm-------", culm )
}
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.
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
logInfo( "------Regen 3-------", VorhergesagterRegen3hours )
}
if ((VorhergesagterRegen06hours.state >= minPrecip) && (Precip_Probability.state >= minProba))
{ rain = true
logInfo( "------Regen 6-------", VorhergesagterRegen06hours )
}
if ((VorhergesagterRegen09hours.state >= minPrecip) && (Precip_Probability.state >= minProba))
{ rain = true
logInfo( "------Regen 9-------", VorhergesagterRegen09hours )
}
if ((Regenin12Stunden.state >= minPrecip) && (Precip_Probability.state >= minProba))
{ rain = true
logInfo( "------Regen 12-------", Regenin12Stunden )
}
culm = (VorhergesagterRegen3hours.state as Number) + (VorhergesagterRegen06hours.state as Number) + (VorhergesagterRegen09hours.state as Number) + (Regenin12Stunden.state as Number)
if (culm >= culRain) { rain = true
logInfo( "------Regen culm-------", culm )
}
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
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.
See this thread
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
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 ?
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.