What it does: The relevant values are stored at the end of every month to the db. With the Items ChZWPM_Y ánd ChZWPM_M I select year and month from basic ui. Then I calculate the last day of the selected month of witch I want to read out the values.
It might be a problem with the DateTime format? But I can’t see it. Do you have any ideas?
I’m not sure if that DateTime works out to be before your first data record, when time zone is taken into account.
When you use historicState() it is never going to match an exact record to the second. It will return the next oldest record, assuming the data remained valid until next change.
So to get records from last day of month, you can just ask for the first day of the next month.
Thank you for quick help and leading me to the right direction. I use now the first day of the next month. My final solution looks like this:
var String YearMonth = ""
var String FirstDay = ""
var DateTimeType YearMonthDay
var DateTime JodaYearMonthDay
var DateTime ExactDay
rule "Historische Verbrauchsdaten"
when
Item ChZWPM_Y changed or
Item ChZWPM_M changed
then
YearMonth = ChZWPM_Y.state + "-" + ChZWPM_M.state + "-01T23:59"
YearMonthDay = DateTimeType.valueOf(YearMonth)
JodaYearMonthDay = new DateTime(YearMonthDay.toString)
FirstDay = JodaYearMonthDay.plusMonths(1).dayOfMonth().withMinimumValue().toString
ExactDay = new DateTime(FirstDay.toString)
HisValHa.postUpdate(ZHWirkenergieZAp.historicState(ExactDay,"influxdb").state as Number)
HisValWP.postUpdate(ZWWirkenergieZAp.historicState(ExactDay,"influxdb").state as Number)
end
It’s bad luck your first “exact day” worked out to be before your oldest data. I believe the database always stores by UTC, and the persistence framework converts to/from your local timezone.