[SOLVED] Rules to read data from the rain sensor

I need Your help. I have a problem with reading data from a rain sensor.
I have a problem with two things. Both are linked with refreshing. The first is Rain Indicator - that still show rain even there is no rain for a long time. The second is rainfall meter (for example from last hour) - even when not raining for a week, until next rain we see how much rain drop in hour when last time we have a rain.

I created the following items:

Number Oregon_RainRate “Intensity of rain [%.2f mm/h]” (Rain) { rfxcom="<63744:RainRate" }

Number Sila_Opadu “Now: [SCALE(sila_opadu.scale):%s]” (Rain) { rfxcom="<63744:RainRate" }
String Status_Opadu “- and rain: [%s]” (Rain)

Number Oregon_RainTotal_h “Rainfall Hour [%.2f mm]” (Rain)
Number Oregon_RainTotal_D “Rainfall Day: [%.2f mm]” (Rain)
Number Oregon_RainTotal_W “Rainfall Week: [%.2f mm]” (Rain)

Number Oregon_RainTotal “Total rainfall [%.2f mm]” (Rain) { rfxcom="<63744:RainTotal" }

Number Oregon_RainRate_Delta “Delta(5min.) [%.2f mm/h]” (Rain)

and sitemap:

Text item=Sila_Opadu visibility=[Oregon_RainRate>0.01]
Text item=Status_Opadu visibility=[Oregon_RainRate>0.01]

Text item=Oregon_RainRate visibility=[Oregon_RainRate>0.01]

Text item=Oregon_RainTotal_h visibility=[Oregon_RainTotal_D>0.01]
Text item=Oregon_RainTotal_D visibility=[Oregon_RainTotal_D>0.01]
Text item=Oregon_RainTotal_W visibility=[Oregon_RainTotal_W>0.01]

and rules:

rule “Delta- last 5 minutes”

when
Item Oregon_RainRate changed
then

var rainrate = Oregon_RainRate.deltaSince(now.minusMinutes(5))
postUpdate(Oregon_RainRate_Delta, rainrate)

end

//------------------------------------------------------------------------------------------------

rule “RainIndicator”

when

Item Oregon_RainRate changed

then
if (Oregon_RainRate.deltaSince(now.minusMinutes(5)) > 0){
Status_Opadu.postUpdate(“growing”)
}
if (Oregon_RainRate.deltaSince(now.minusMinutes(5)) < 0){
Status_Opadu.postUpdate(“stops”)
}
if (Oregon_RainRate.deltaSince(now.minusMinutes(5)) == 0){
Status_Opadu.postUpdate(“no change”)
}

end

//-----------------------------------------------------------------------------------------------------

rule “Rainfall Hour”

when
Item Oregon_RainTotal changed
then

var rain4 = Oregon_RainTotal.deltaSince(now.minusHours(1))
postUpdate(Oregon_RainTotal_h, rain4)

end

//--------------------------------------------------------------------------------------------------

rule “Rainfall Day”

when
Item Oregon_RainTotal changed
then

var rain7 = Oregon_RainTotal.deltaSince(now.minusDays(1))
postUpdate(Oregon_RainTotal_D, rain7)

end

//----------------------------------------------------------------------------------------------------

rule “Rainfall Week”

when
Item Oregon_RainTotal changed
then

var rain8 = Oregon_RainTotal.deltaSince(now.minusWeeks(1))
postUpdate(Oregon_RainTotal_W, rain8)

end

//------------------------------------------------------------------------------------------------------

Try adding a timer. I suspect what is happening is that your rain meter doesn’t report anything when the rain actually stops so your rules don’t actually calculate the last bit of information until the next time it rain.Set the timer to go off in now.plusMinutes(5) and every time you receive an update on Oregon_RainTotal reschedule the timer for now.plusMinutes(5) again. When the rain stops and the RainTotal stops reporting the timer will go off and you can do the last calculation and change the Rain Indicator to show it has stopped raining.

Thank You for reply.
It is exactly, as you write: when rain stops, then data from sensor frozen until next rain. My weather station doing calculations itself. I try do the same - but with moderate luck.
I am beginner in OpenHab, plus I’ve never before had contact with any programming and my English is poor - hard work :smile:
I understand Yours explain, but I don’t have idea how do that :frowning:
As You can see, my rules are very simple. I need more learn .
Adam
Sorry for my English

Below is a quick attempt to rewrite your rules. I combined rules that could be combined and added a timer that goes off after five minutes without an update. I just typed this in so there may be syntax errors. You cna play with the times if 5 minutes is too short or too long.

var Timer rainRateTimer = null
var Timer rainTotalTimer = null

rule "Rain Rate Updated"
when
    Item Oregon_RainRate changed
then
    var delta = Oregon_RainRate.deltaSince(now.minusMinutes(5))

    // Post delta
    Oregon_RainRate_Delta.postUpdate(delta)

    // Post Rain Indicator
    if(delta > 0) Status_Opadu.postUpdate("growing")
   else if(delta < 0) Status_Opadu.postUpdate("stops")
   else Status_Opadu.postUpdate("no change")


    // Set timer
    if(rainRateTimer == null) {
        rainRateTimer.createTimer(now.plusMinutes(5), [|
            Oregon_RainRate.deltaSince(now.minusMinutes(5))
            Status_Opadu.postUpdate("no rain")
            rainRateTimer = null
        ]
    } else {
        rainRateTimer.reschedule(now.plusMinutes(5)
    }       
end


rule "Rain Total Changed"
when
    Item Oregon_RainTotal changed
then
    // Post totals update
    Oregon_RainTotal_H.postUpdate(Oregon_RainTotal.deltaSince(now.minusHours(1))
    Oregon_RainTotal_D.postUpdate(Oregon_RainTotal.deltaSince(now.minusDays(1))
    Oregon_RainTotal_W.postUpdate(Oregon_RainTotal.deltaSince(now.minusWeeks(1))

    // Set timer
    if(rainTotalTimer == null) {
        rainTotalTimer = createTimer(now.plusMinutes(5), [|
            Oregon_RainTotal_H.postUpdate(Oregon_RainTotal.deltaSince(now.minusHours(1))
            Oregon_RainTotal_D.postUpdate(Oregon_RainTotal.deltaSince(now.minusDays(1))
            Oregon_RainTotal_W.postUpdate(Oregon_RainTotal.deltaSince(now.minusWeeks(1))
            rainTotalTimer = null        
        ]
    }
    else {
        rainTotalTimer.reschedule(now.plusMinutes(5))
    }
end

Thanks for your support. You are Great :slight_smile:

I found some minor errors in syntax, witch I correct (I hope :smile: ).
Now, “rain indicator” works like a dream, but “rainfall meters” for periods not - they look they does not reset the counter after defined time.

For example: when the rain does not fall since 2 hours, “rainfall meter for 1hour” still shows precipitation from the last hour when was rain - it should show “-” or “0” or whatever. That’s not good, because if does not rain ,for example, a month all “rainfall meters” will not show the truth to next rain.

Thank You for your help

Adam

OK, what we really need to do is to be constantly recalculating the rain totals even when there is no rain. T that way when the rain stops the totals gradually go down to zero as time passes.

Probably the easiest thing to do in your case is to replace your totals rule with a cron trigger that goes off every minute and recalculates the rain totals, regardless of whether there are any updates.

So replace the “Rain Total Changed” rule to the following

rule "Calculate Rain Totals"
when
    Time cron "* 0/1 * * * ?"
then
    Oregon_RainTotal_H.postUpdate(Oregon_RainTotal.deltaSince(now.minusHours(1))
    Oregon_RainTotal_D.postUpdate(Oregon_RainTotal.deltaSince(now.minusDays(1))
    Oregon_RainTotal_W.postUpdate(Oregon_RainTotal.deltaSince(now.minusWeeks(1))
end

You can eliminate the rainTotalTimer as you no longer need it…

Now it’s working perfect! I dont need hour-precision (it was only for testing). Day-precision is enough. It is base to my environment and budget friendly irrigation system. i really appreciate Your help. Thank You.
Problem is solved,

Hi

I am trying to use this in OH2, with rfxcom 2.0 so my items is in things
i copyed the code in rules and items, and named the rainsensor the same as this template.
But a can´t get this working.
My rainrate mm/h is not sends nothing to the item, i dont know why.

Rules:

var Timer rainRateTimer = null

rule "Rain Rate Updated"
when
    Item Oregon_RainTotal changed
then
    var delta = Oregon_RainRate.deltaSince(now.minusMinutes(5))

    // Post delta
    Oregon_RainRate_Delta.postUpdate(delta)

    // Post Rain Indicator
    if(delta > 0) Status_Opadu.postUpdate("growing")
   else if(delta < 0) Status_Opadu.postUpdate("Stops")
   else Status_Opadu.postUpdate("no change")


    // Set timer
    if(rainRateTimer == null) {
        rainRateTimer.createTimer(now.plusMinutes(5), [|
            Oregon_RainRate.deltaSince(now.minusMinutes(5))
            Status_Opadu.postUpdate("no rain")
            rainRateTimer = null
        ]
    } else {
        rainRateTimer.reschedule(now.plusMinutes(5)
    }       
end


rule "Rain Total Changed"
when
    Time cron "* 0/1 * * * ?"
then
    // Post totals update
    Oregon_RainTotal_H.postUpdate(Oregon_RainTotal.deltaSince(now.minusHours(1))
    Oregon_RainTotal_D.postUpdate(Oregon_RainTotal.deltaSince(now.minusDays(1))
    Oregon_RainTotal_W.postUpdate(Oregon_RainTotal.deltaSince(now.minusWeeks(1))

end

)
)

Items:;

Number Oregon_RainRate "Intensity of rain [%.2f mm/h]" (Rain) //sensor mm/h

Number Sila_Opadu "Now: [SCALE(sila_opadu.scale):%s]" (Rain) //sensor mm/h
String Status_Opadu "- and rain: [%s]" (Rain)

Number Oregon_RainTotal_H "Rainfall Hour [%.2f mm]" (Rain)
Number Oregon_RainTotal_D "Rainfall Day: [%.2f mm]" (Rain)
Number Oregon_RainTotal_W "Rainfall Week: [%.2f mm]" (Rain)

Number Oregon_RainTotal "Total rainfall [%.2f mm]" (Rain) //sensor mm total

Number Oregon_RainRate_Delta "Delta(5min.) [%.2f mm/h]" (Rain)

I also installed the Scale Transformation

I can't help You. I'm still in OH1. froolk

Hi folks,

I am using a rain sensor and would like the system to send out an email if the sensor rain rate has changed to more than 100 in 30minutes.

Unfortunately, if I add
Item zwave_device_35415c38_node101_sensor_rainrate changed from 0 to >100.0.

The error log shows: Configuration model ‘rainsensor.rules’ has errors, therefore ignoring it: [8,72]: no viable alternative at input ‘>’

The rule looks like this:

rule "Critical Rain dropped"
 when
	 Item zwave_device_35415c38_node101_sensor_rainrate changed from 0 to 100.0
 then

sendMail("XXX@pomail.net", "***ALARM Regensensor >100l geregnet!***", "***ALARM Regensensor >100 Liter geregnet!***")
	  
End

Can you please advise, what I need to change? I am not sure, if I really need to add a timer here as the rain sensor will - in case the rain stops - automatically update the number from, e.g. 120 to 80.

Thanks,
db

In the future avoid posting a new problem to an existing thread, particularly if that thread is marked as solved.

I recommend reviewing the Beginer’s Guide, the first few sections of the User’s Guide and the Rules documentation.

I also recommend using ESH Designer or the openHAB VSCODE plugin.

This is syntatically incorrect. OH does not support triggers like this. You cannot have comparisons like > in a rule trigger.