Average Calculation is not correct

  • Platform information:
    • Hardware: Raspberry PI 3B
    • openhabian: Version 2.3.
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version:
      Release = Raspbian GNU/Linux 9 (stretch)
      Kernel = Linux 4.14.34-v7+
      Platform = none
      Uptime = 10 day(s). 23:58:41
      CPU Usage = 60.88 % avg over 4 cpu(s) (4 core(s) x 1 socket(s))
      CPU Load = 1m: 2.80, 5m: 2.24, 15m: 1.27
      Memory = Free: 0.20GB (21%), Used: 0.75GB (79%), Total: 0.95GB
      Swap = Free: 0.03GB (34%), Used: 0.06GB (66%), Total: 0.09GB
      Root = Free: 11.30GB (81%), Used: 2.60GB (19%), Total: 14.53GB
      Updates = 13 apt updates available.
      Sessions = 2 sessions
      Processes = 154 running processes of 32768 maximum processes

I am using a rule to calculate the average temperature during the day.

rule "Durchschnittstemperatur heute"
when 
	Time cron "0 31 * * * ?" 
then
        postUpdate(WUG_TempAVGD, WUG_Temperature.averageSince(now.withTimeAtStartOfDay(), "jdbc"))
	logInfo("Rule: Durchschnittstemperatur heute", "Durchschnittstemperatur berechnet")
end	

My persisted temperature are:

2018-07-03 00:30:00.317|15.9
2018-07-03 01:30:00.098|13.5
2018-07-03 02:30:00.104|12.6
2018-07-03 03:30:00.079|11.7
2018-07-03 04:30:00.273|11.7
2018-07-03 05:30:00.098|11.7
2018-07-03 06:30:00.101|14.5
2018-07-03 07:30:00.176|18.7
2018-07-03 08:30:00.098|21.5
2018-07-03 09:30:00.088|25.8
2018-07-03 10:30:00.108|25.8
2018-07-03 11:30:00.078|25.8
2018-07-03 12:30:00.104|23.9
2018-07-03 13:30:00.137|28.6
2018-07-03 14:30:00.105|28.6
2018-07-03 15:30:00.165|28.6
2018-07-03 16:30:00.097|28.6
2018-07-03 17:30:00.297|27.7

The average shoud be around 20 - but the rules calculates ist to 17.xxx and changes it with every loop.

2018-07-03 17:31:48.182 [vent.ItemStateChangedEvent] - WUG_TempAVGD changed from 17.72498836185412 to 17.73085165427519

2018-07-03 17:33:51.525 [vent.ItemStateChangedEvent] - WUG_ForecastAvgWindSpeed changed from 8 to 9

2018-07-03 17:33:52.292 [vent.ItemStateChangedEvent] - WUG_Forecast2AvgWindDirection2 changed from 293 to 294

2018-07-03 17:36:26.810 [vent.ItemStateChangedEvent] - WUG_TempAVGD changed from 17.73085165427519 to 17.76464664935833

2018-07-03 17:47:32.230 [vent.ItemStateChangedEvent] - WUG_TempAVGD changed from 17.76464664935833 to 17.84327932798605

If I use only the last 4 values (now.minusMinutes(240)) - the average should be 28.4 but it is 25.4

2018-07-03 17:54:41.865 [vent.ItemStateChangedEvent] - WUG_TempAVGD changed from 17.84327932798605 to 25.33708910757429

What do I miss, what is wrong?
Thanks for your support
Georg

Do you have an other rule which changes WUG_TempAVGD as i miss the logInfo from the rule.

This topic (last post in particular) might be interesting: averageSince(now.minusMinutes) in rule not working

Here is the relevant part of the log Viewer.

2018-07-03 19:31:00.059 [vent.ItemStateChangedEvent] - WUG_TempAVGD changed from 24.88123626984909 to 24.60499205798911

==> /var/log/openhab2/openhab.log <==

2018-07-03 19:31:00.090 [INFO ] [.Rule: Durchschnittstemperatur heute] - Durchschnittstemperatur berechnet

==> /var/log/openhab2/events.log <==

The new value should be 26.7 - but it is 24.6

I have also realized if you run the rule every Minute the average changes from run to run - this is strange since I have only values every hour und it stay constant until the next value is persisted.

Georg