I am a little bit puzzled.
I have searched the WWW to get the job done with less work, but then I stumpled into trouble after few minutes.
SYSTEM / INSTALLATION
Homematic CCU3
Version: 3.2.0.M4 (Build)
User: openhab (Active Process 18408)
User Groups: openhab tty dialout audio
Directories: Folder Name | Path | User:Group
----------- | ---- | ----------
OPENHAB_HOME | /usr/share/openhab | openhab:openhab
OPENHAB_RUNTIME | /usr/share/openhab/runtime | openhab:openhab
OPENHAB_USERDATA | /var/lib/openhab | openhab:openhab
OPENHAB_CONF | /etc/openhab | openhab:openhab
OPENHAB_LOGDIR | /var/log/openhab | openhab:openhab
OPENHAB_BACKUPS | /var/lib/openhab/backups | root:root
INTRO
In most examples (not specific for the Homematic WeatherStation) the people just use deltaSince(..)
(openHAB documentation Persistence | openHAB) to calculate the delta between two dates, e.g. from now
to now.minusDays(1)
.
I tried this, and I already have logged data based on rrd4
stored in /var/lib/openhab/persistence/rrd4j
. The file is recently refreshed during the writting of this post:
I have not done any additional setup, everything was already present with openHAB3. As far as I see, approx 99% of all tutorials in the WWW are about openHAB2 persistence for which additional setup is needed, but not for openHAB3.
The binding in openHAB looks like this:
And the item configuration in /var/lib/openhab/jsondb/org.openhab.core.items.Item.json
as follows:
"Wetterstation_RainCounter": {
"class": "org.openhab.core.items.ManagedItemProvider$PersistedItem",
"value": {
"groupNames": [
"Wetterstation"
],
"itemType": "Number:Length",
"tags": [
"Point"
],
"label": "Rain Counter",
"category": "Rain"
}
},
In my CCU3 it looks like this (I do not why the amount of rain is approx 22 and not 29 as seen in the previous screenshot, that is not my question):
ISSUE
Few minutes (maybe a hour) ago I have put up to 1 liter of water into the sensor, the is raining
switch signaled this immediatelly, fine.
Now, when I try to get the delta from yesterday to right now, I always get the full amout of rain since start of the measurement/device installation two weeks ago.
My log instructions:
logInfo("INFO", String::format("%s Hour 1: %s", now.minusHours( 1), Wetterstation_RainCounter.deltaSince(now.minusHours( 1))))
logInfo("INFO", String::format("%s Hour 2: %s", now.minusHours( 2), Wetterstation_RainCounter.deltaSince(now.minusHours( 2))))
logInfo("INFO", String::format("%s Hour 3: %s", now.minusHours( 3), Wetterstation_RainCounter.deltaSince(now.minusHours( 3))))
logInfo("INFO", String::format("%s Hour 4: %s", now.minusHours( 4), Wetterstation_RainCounter.deltaSince(now.minusHours( 4))))
logInfo("INFO", String::format("%s Hour 5: %s", now.minusHours( 5), Wetterstation_RainCounter.deltaSince(now.minusHours( 5))))
logInfo("INFO", String::format("%s Hour 6: %s", now.minusHours( 6), Wetterstation_RainCounter.deltaSince(now.minusHours( 6))))
logInfo("INFO", String::format("%s Hour 7: %s", now.minusHours( 7), Wetterstation_RainCounter.deltaSince(now.minusHours( 7))))
logInfo("INFO", String::format("%s Hour 8: %s", now.minusHours( 8), Wetterstation_RainCounter.deltaSince(now.minusHours( 8))))
logInfo("INFO", String::format("%s Hour 9: %s", now.minusHours( 9), Wetterstation_RainCounter.deltaSince(now.minusHours( 9))))
logInfo("INFO", String::format("%s Days 1: %s", now.minusDays( 1), Wetterstation_RainCounter.deltaSince(now.minusDays( 1))))
logInfo("INFO", String::format("%s Days 2: %s", now.minusDays( 2), Wetterstation_RainCounter.deltaSince(now.minusDays( 2))))
logInfo("INFO", String::format("%s Days 3: %s", now.minusDays( 3), Wetterstation_RainCounter.deltaSince(now.minusDays( 3))))
logInfo("INFO", String::format("%s Days 4: %s", now.minusDays( 4), Wetterstation_RainCounter.deltaSince(now.minusDays( 4))))
logInfo("INFO", String::format("%s Days 5: %s", now.minusDays( 5), Wetterstation_RainCounter.deltaSince(now.minusDays( 5))))
logInfo("INFO", String::format("%s Days 6: %s", now.minusDays( 6), Wetterstation_RainCounter.deltaSince(now.minusDays( 6))))
logInfo("INFO", String::format("%s Days 7: %s", now.minusDays( 7), Wetterstation_RainCounter.deltaSince(now.minusDays( 7))))
The output of this looks like:
2021-11-11 08:33:15.026- 2021-11-11T08:33+01:00[Europe/Berlin]
2021-11-11 08:33:15.031- 2021-11-11T07:33:15.027617+01:00[Europe/Berlin] Hour1: 29.1708
2021-11-11 08:33:15.036- 2021-11-11T06:33:15.032677+01:00[Europe/Berlin] Hour2: 29.172599999999999996
2021-11-11 08:33:15.041- 2021-11-11T05:33:15.037773+01:00[Europe/Berlin] Hour3: 29.172599999999999996
2021-11-11 08:33:15.044- 2021-11-11T04:33:15.042213+01:00[Europe/Berlin] Hour4: 29.172599999999999996
2021-11-11 08:33:15.047- 2021-11-11T03:33:15.045551+01:00[Europe/Berlin] Hour5: 29.172599999999999996
2021-11-11 08:33:15.051- 2021-11-11T02:33:15.048737+01:00[Europe/Berlin] Hour6: 29.172599999999999996
2021-11-11 08:33:15.053- 2021-11-11T01:33:15.051784+01:00[Europe/Berlin] Hour7: 29.172599999999999996
2021-11-11 08:33:15.056- 2021-11-11T00:33:15.054623+01:00[Europe/Berlin] Hour8: 29.172599999999999996
2021-11-11 08:33:15.059- 2021-11-10T23:33:15.057553+01:00[Europe/Berlin] Hour9: 29.172599999999999996
2021-11-11 08:33:15.062- 2021-11-10T08:33:15.060504+01:00[Europe/Berlin] Days1: 29.172599999999999996
2021-11-11 08:33:15.065- 2021-11-09T08:33:15.063243+01:00[Europe/Berlin] Days2: 29.172899999999999997
2021-11-11 08:33:15.068- 2021-11-08T08:33:15.065974+01:00[Europe/Berlin] Days3: 29.173399999999999998
2021-11-11 08:33:15.071- 2021-11-07T08:33:15.068801+01:00[Europe/Berlin] Days4: 29.1758
2021-11-11 08:33:15.074- 2021-11-06T08:33:15.072227+01:00[Europe/Berlin] Days5: 29.1791
2021-11-11 08:33:15.076- 2021-11-05T08:33:15.075063+01:00[Europe/Berlin] Days6: 29.1793
2021-11-11 08:33:15.079- 2021-11-04T08:33:15.077785+01:00[Europe/Berlin] Days7: 29.1829
As you can see, all calculations provide the total amount.
By the way… this diff looks interesting as well:
When I use historicState(..)
it would be possible to calculate the delta on my own, but why should I when some functionality already exist ?
Call of historicState(..)
:
logInfo("INFO", String::format("%s Hour 1: %s", now.minusHours( 1), Wetterstation_RainCounter.historicState(now.minusHours( 1)).state.toString))
logInfo("INFO", String::format("%s Hour 2: %s", now.minusHours( 2), Wetterstation_RainCounter.historicState(now.minusHours( 2)).state.toString))
logInfo("INFO", String::format("%s Hour 3: %s", now.minusHours( 3), Wetterstation_RainCounter.historicState(now.minusHours( 3)).state.toString))
..
..
Output:
2021-11-11 08:33:15.087 [INFO ] 2021-11-11T06:33:15.084252+01:00[Europe/Berlin] Hour 2: 0.027400000000000004 m
2021-11-11 08:33:15.089 [INFO ] 2021-11-11T05:33:15.087895+01:00[Europe/Berlin] Hour 3: 0.027400000000000004 m
2021-11-11 08:33:15.092 [INFO ] 2021-11-11T04:33:15.090703+01:00[Europe/Berlin] Hour 4: 0.027400000000000004 m
BUT, when I try to use the same approach for other values like the amount of power I produced with my solarplant everything looks fine:
logInfo("INFO", String::format("%s Hour 1: %s", now.minusHours( 1), PV_Garage_ETotal.deltaSince(now.minusHours( 1))))
logInfo("INFO", String::format("%s Hour 2: %s", now.minusHours( 2), PV_Garage_ETotal.deltaSince(now.minusHours( 2))))
logInfo("INFO", String::format("%s Hour 3: %s", now.minusHours( 3), PV_Garage_ETotal.deltaSince(now.minusHours( 3))))
Output:
2021-11-11 08:33:15.132 [INFO ] 2021-11-11T07:33:15.131868+01:00[Europe/Berlin] Hour 1: 0.055
2021-11-11 08:33:15.134 [INFO ] 2021-11-11T06:33:15.133515+01:00[Europe/Berlin] Hour 2: 0.055
2021-11-11 08:33:15.135 [INFO ] 2021-11-11T05:33:15.135031+01:00[Europe/Berlin] Hour 3: 0.055
This output seems to be correct as since August I have produced approx 248 kW and today the sun is rising in the moment, so the amount is very low.
Question
Do I have to change any setting for the persistance of the rain values?
Do you need more information for giving any suggestions?
What should I do to calculate the correct delta between two time values?