Average calculation not working in Rule

Hello,
I am trying to calculate the solar production average of the last 15 minutes. I read several examples with temperature, however I dont get it working with rules.

I have an Item which has the actual solar production with an htttp binding. That works fine. The data is stored in the internal RR4dJ Database.
In a rule I am trying to calculate the Average like this

var produktion = SolaranlageProduktion.state as Number
SolaranlageAverage.postUpdate(produktion.averageSince(now.minusMinute(15)))

Unfortunately I get the following error:

Script execution of rule with UID 'b28faa60d5' failed: var produktion = SolaranlageProduktion.state as Number
SolaranlageAverage.postUpdate(produktion.averageSince(now.minusMinute(15)))


   1. The method averageSince(Object) is undefined for the type Number; line 2, column 96, length 12
   2. The method minusMinute(int) is undefined for the type ZonedDateTime; line 2, column 113, length 11

I also tried

var produktion = SolaranlageProduktion
SolaranlageAverage.postUpdate(produktion.averageSince(now.minusMinute(15)))

then I get

1. The method minusMinute(int) is undefined for the type ZonedDateTime; line 2, column 97, length 11 2. Ambiguous feature call.
The extension methods
        postUpdate(Item, Number) in BusEvent and
        postUpdate(Item, State) in BusEvent
both match.; line 2, column 58, length 10

Can anyone help how to solve that issue?

  • Platform information:
    • OS: Docker containter
    • openHAB version: 3.1.0

So produktion is a Number variable.

Number variables do not have .averageSince() methods, only Items do.

Hence the report -

This one is self explanatory -

check spelling

1 Like

Thanks for the answer. However that does not solve the problem.

I tried:

var produktion = SolaranlageProduktion
SolaranlageAverage.postUpdate(produktion.averageSince(now().minusMinutes(15)))

which gives:

Script execution of rule with UID 'b28faa60d5' failed: var produktion = SolaranlageProduktion
SolaranlageAverage.postUpdate(produktion.averageSince(now( ___ ).minusMinutes(15)))


   Ambiguous feature call.
The extension methods
        postUpdate(Item, Number) in BusEvent and
        postUpdate(Item, State) in BusEvent
both match.; line 2, column 58, length 10

I fixed it.

It works like this

var produktion = SolaranlageProduktion
SolaranlageAverage.postUpdate(produktion.averageSince(now.minusMinutes(15))as Number)
1 Like