Maximum wind speed?

I’ve just connected an anemometer to Openhab which is updated every 5 seconds and I wondered if there is a way of creating a rule that updates an item with the highest value in the last 5 minutes. As I’m using a Pi I’d like to avoid persisting anything onto the SD Card if possible, although I do have a couple of small RAM disks that can be used instead.
Has anyone done this before?
Does anyone have an idea how to do this?
Thanks
Kevin

Well, first of all - you certainly want to use a RAM disk (or USB stick, something else than the SD).

The easiest way of going about this would be to create a couple of items and a rule, something like this:

// items
Item A_Meter_Value
Item A_Value_Max

// rule
rule "A Value update"
    when
        Item A_Meter_Value updated
    then
        if (A_Meter_Value.state > A_Value_Max.state) {
            postUpdate(A_Value_Max, A_Meter_Value.state)
        }
end

To have the value reset every 5 minutes you could for example add a timer:

tResetA = createTimer(now.plusSeconds(300)) [|
        postUpdate(A_Max_Value, 0)
    ]

or run the job every 5 minutes via cron or another rule:

rule "Reset A value"
when
    Time cron "0 0/5 * * * ?"
then
    postUpdate(A_Max_Value, 0)
end

That has given me some ideas, I’ll try them and report back.

Here’s what I’ve come up with that seems to do the trick.2 Rules that update one item.

var Number Min0MaxWind = 0
var Number Min1MaxWind = 0
var Number Min2MaxWind = 0
var Number Min3MaxWind = 0
var Number Min4MaxWind = 0
var Number Min5MaxWind = 0
var Number FiveMinWind = 0

rule "calculate 1 minute wind average"
when Item LocalWindSpeed changed then
if (LocalWindSpeed.state > Min0MaxWind)
{	Min0MaxWind = LocalWindSpeed.state as DecimalType	}
end

rule "calculate 5 Min Gusts"
when Time cron "5 0/1 * * * ?" then 
{	Min5MaxWind = Min4MaxWind
	Min4MaxWind = Min3MaxWind
	Min3MaxWind = Min2MaxWind
	Min2MaxWind = Min1MaxWind
	Min1MaxWind = Min0MaxWind
	Min0MaxWind = 0
	if (Min1MaxWind > 0)
	{	FiveMinWind = Min1MaxWind	}
	if (Min2MaxWind > FiveMinWind)
 	{	FiveMinWind = Min2MaxWind	}
    if (Min3MaxWind > FiveMinWind)
	{   FiveMinWind = Min3MaxWind	}
	if (Min4MaxWind > FiveMinWind)
	{	FiveMinWind = Min4MaxWind	}
	if (Min5MaxWind > FiveMinWind)
	{	FiveMinWind = Min5MaxWind	}
	
postUpdate(FiveMinGust, (FiveMinWind))}
end

In your code, it looks like you are trying to compute FiveMinWind = Max(Min1MaxWind, Min2MaxWind, …, Min5MaxWind), but you need to change:

if (Min1MaxWind > 0) { FiveMinWind = Min1MaxWind }

to:

FiveMinWind = Min1MaxWind

Or, else, if Min1MaxWind = 0, then FiveMinWind will not be reset from the value of the previous minute.

Justin,
that’s interesting, thanks for the correction.
Its morphed into a 10 minute maximum calculation now as that makes more sense. I guess we don’t often get zero wind around here :smile: