Hello,
I’m using following rule to calculate the average of 1 item (of the last 24 hours).
The value is the current production of a solar system.
rule "Average se15000_Prod"
when
Item se15000_Prod received update
then
se15000_ProdAverage.postUpdate(se15000_Prod.averageSince(now.minusHours(24)))
end
I would like to do this now only during sunrise and sunset, and a reset of the day. In other words, I only want to see the average of the day. But of course, during night, this will be 0, so would be nice to exclude this…
Put the time of day in an item: Time_Of_Day with the value “NIGHT” after sunset and before sunrise
The you will need a proxy item:
Number se15000_Prod_Proxy
And your rule:
rule "Average se15000_Prod with Night"
when
Item se15000_Prod received update
then
if (Time_Of_Day.state != "NIGHT") {
se15000_Prod_Proxy.postUpdate(se_15000_Prod.state)
} else {
se15000_Prod_Proxy.postUpdate(0)
}
se15000_ProdAverage.postUpdate(se15000_Prod_Proxy.averageSince(now.minusHours(24)))
end
I don’t think this is exactly what OP is asking for. The zeros of night period will skew the average down. Maybe it would work if we don’t post anything when it’s NIGHT. This would also assume that we are using just an every update strategy and not everyMinute (i.e. no rrd4j).
I’m pretty sure the averageSince just retrieves all the values and averages them together without doing anything fancy with the amount of time or normalization or anything like that.
Yes, I didn’t think about the value being drawn down. So no updating the value and we’ll have to assume that the value gets updated on a more or less regular interval.
rule "Average se15000_Prod with Night"
when
Item se15000_Prod received update
then
if (Time_Of_Day.state != "NIGHT") {
se15000_Prod_Proxy.postUpdate(se_15000_Prod.state)
}
se15000_ProdAverage.postUpdate(se15000_Prod_Proxy.averageSince(now.minusHours(24)))
end
It will take all readings from the last 24 houres, starting from NOW. For example: when doing that request on Monday 10 am, it will take all reading from Sunday 10 am until Monday 9:59 am!