maximumSince does not show highest value

Thank you. I will try to fetch the data you suggested.
And I mixed things up with the maximum wind gust rule. It wasn’t provided by you but by @BrianS in an earlier posting. Sorry about that.

When looking into problems with this kind of thing, break it up so you can see the moving parts. Something is not what you expected, find out what. Is that time what you think? Is that whole gubbins something suitable to postUpdate to an Item?

var tt = now.with(LocalTime.of(0,0,0,0)
logInfo("diag", "Using datetime " + tt.toString)
var xx = AT_Dachflache_Wind.maximumSince(tt, "jdbc")
logInfo("diag", "got value " + xx.state.toString)
logInfo("diag", "from " + xx.timestamp.toString)
AT_Dachflache_Wind_MaxDay.postUpdate(xx.state)

I tried this suggestion and here are the log results:

ince5] - Maximum Wind was: 10.44
2022-04-06 18:29:03.086 [INFO ] [core.model.script.Wind Maximumsince5] - Maximum Wind occurred at 2022-04-06T18:29:03.085624+02:00[Europe/Berlin]
2022-04-06 18:30:59.611 [INFO ] [core.model.script.Wind Maximumsince5] - Maximum Wind was: 6.12
2022-04-06 18:30:59.620 [INFO ] [core.model.script.Wind Maximumsince5] - Maximum Wind occurred at 2022-04-06T18:30:59.619834+02:00[Europe/Berlin]
2022-04-06 18:32:00.031 [INFO ] [core.model.script.Wind Maximumsince5] - Maximum Wind5 was: 8.28
2022-04-06 18:32:00.035 [INFO ] [core.model.script.Wind Maximumsince5] - Maximum Wind5 occurred at 2022-04-06T18:32:00.033958+02:00[Europe/Berlin]
2022-04-06 18:33:00.029 [INFO ] [core.model.script.Wind Maximumsince5] - Maximum Wind5 was: 6.12
2022-04-06 18:33:00.033 [INFO ] [core.model.script.Wind Maximumsince5] - Maximum Wind5 occurred at 2022-04-06T18:33:00.032004+02:00[Europe/Berlin]

Apparently, not the highest but the last recorded value is used by the Max5 variable.

How do you know, what recorded data is available for the preceding 5 minutes? Any at all?

This is a bit of a handicap, I’ve no idea how you use that either.
Let’s get openHAB to have a rough look.

var zz = AT_Dachflache_Wind.historicState(now.minusMinutes(5), "jdbc")
// this is NOT a number either
logInfo ("Wind Maximumsince5","5 mins ago was: " + zz.state.toString)    
logInfo ("Wind Maximumsince5","record from  " + zz.getTimestamp.toString)    

It is unlikely there is any record at exactly five minutes ago to the millisecond - what historicState() should do is search backward for the last valid record before that (on the assumption it remained valid until)

You can query the DB through the API Explorer. The persistence: GET /persistence/items/{itemname} endpoint will let you create a query for all entries between two supplied date times (or a date time to now).

1 Like

Thank you for pointing to the API Explorer, @rlkoshak. I can see that values have been persisted for the item. However because I guess time values are Epoch, I cannot tell when the data was recorded.

Interesting behaviour for the historicState. It keeps showing the data for a value that was recorded at 9 p.m. No changes over time:

2022-04-06 21:11:00.673 [INFO ] [core.model.script.Wind Maximumsince5] - Maximum Wind5 was: 0.0
2022-04-06 21:11:00.677 [INFO ] [core.model.script.Wind Maximumsince5] - Maximum Wind5 occurred at 2022-04-06T21:11:00.676203+02:00[Europe/Berlin]
2022-04-06 21:11:00.686 [INFO ] [core.model.script.Wind Maximumsince5] - Wind 5 mins ago was: 0.0
2022-04-06 21:11:00.690 [INFO ] [core.model.script.Wind Maximumsince5] - Wind record from  2022-04-06T21:00:00.277+02:00[Europe/Berlin]
2022-04-06 21:12:00.669 [INFO ] [core.model.script.Wind Maximumsince5] - Maximum Wind5 was: 0.0
2022-04-06 21:12:00.672 [INFO ] [core.model.script.Wind Maximumsince5] - Maximum Wind5 occurred at 2022-04-06T21:12:00.671677+02:00[Europe/Berlin]
2022-04-06 21:12:00.680 [INFO ] [core.model.script.Wind Maximumsince5] - Wind 5 mins ago was: 0.0
2022-04-06 21:12:00.683 [INFO ] [core.model.script.Wind Maximumsince5] - Wind record from  2022-04-06T21:00:00.277+02:00[Europe/Berlin]
2022-04-06 21:12:54.143 [INFO ] [penhab.core.model.script.org.openhab] - Today's max wind gust is 11.933541666666667 m/s at 02:08:00 PM
2022-04-06 21:12:54.029 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'AT_Dachflache_Wind' changed from 0.0 to 7.92
2022-04-06 21:13:00.124 [INFO ] [penhab.core.model.script.org.openhab] - Today's max wind gust is 11.933541666666667 m/s at 02:08:00 PM
2022-04-06 21:13:00.098 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'AT_Dachflache_Wind' changed from 7.92 to 6.12
2022-04-06 21:13:00.667 [INFO ] [core.model.script.Wind Maximumsince5] - Maximum Wind5 was: 6.12
2022-04-06 21:13:00.670 [INFO ] [core.model.script.Wind Maximumsince5] - Maximum Wind5 occurred at 2022-04-06T21:13:00.669890+02:00[Europe/Berlin]
2022-04-06 21:13:00.679 [INFO ] [core.model.script.Wind Maximumsince5] - Wind 5 mins ago was: 0.0
2022-04-06 21:13:00.681 [INFO ] [core.model.script.Wind Maximumsince5] - Wind record from  2022-04-06T21:00:00.277+02:00[Europe/Berlin]
2022-04-06 21:13:05.266 [INFO ] [penhab.core.model.script.org.openhab] - Today's max wind gust is 11.933541666666667 m/s at 02:08:00 PM
2022-04-06 21:13:05.245 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'AT_Dachflache_Wind' changed from 6.12 to 0.0
2022-04-06 21:14:00.668 [INFO ] [core.model.script.Wind Maximumsince5] - Maximum Wind5 was: 0.0
2022-04-06 21:14:00.671 [INFO ] [core.model.script.Wind Maximumsince5] - Maximum Wind5 occurred at 2022-04-06T21:14:00.670668+02:00[Europe/Berlin]
2022-04-06 21:14:00.679 [INFO ] [core.model.script.Wind Maximumsince5] - Wind 5 mins ago was: 0.0
2022-04-06 21:14:00.681 [INFO ] [core.model.script.Wind Maximumsince5] - Wind record from  2022-04-06T21:00:00.277+02:00[Europe/Berlin]
2022-04-06 21:15:00.684 [INFO ] [core.model.script.Wind Maximumsince5] - Maximum Wind5 was: 0.0
2022-04-06 21:15:00.690 [INFO ] [core.model.script.Wind Maximumsince5] - Maximum Wind5 occurred at 2022-04-06T21:15:00.688795+02:00[Europe/Berlin]
2022-04-06 21:15:00.703 [INFO ] [core.model.script.Wind Maximumsince5] - Wind 5 mins ago was: 0.0
2022-04-06 21:15:00.707 [INFO ] [core.model.script.Wind Maximumsince5] - Wind record from  2022-04-06T21:00:00.277+02:00[Europe/Berlin]
1 Like

This approach is interesting. The result looks plausible and consistent:

2022-04-06 21:42:01.816 [INFO ] [.openhab.core.model.script.Wind diag] - Using datetime 2022-04-06T00:00+02:00[Europe/Berlin]
2022-04-06 21:42:01.829 [INFO ] [.openhab.core.model.script.Wind diag] - got value 27.0
2022-04-06 21:42:01.831 [INFO ] [.openhab.core.model.script.Wind diag] - from 2022-04-06T10:00:00.393+02:00[Europe/Berlin]
2022-04-06 21:43:03.157 [INFO ] [.openhab.core.model.script.Wind diag] - Using datetime 2022-04-06T00:00+02:00[Europe/Berlin]
2022-04-06 21:43:03.166 [INFO ] [.openhab.core.model.script.Wind diag] - got value 27.0
2022-04-06 21:43:03.169 [INFO ] [.openhab.core.model.script.Wind diag] - from 2022-04-06T10:00:00.393+02:00[Europe/Berlin]
2022-04-06 21:46:06.183 [INFO ] [.openhab.core.model.script.Wind diag] - Using datetime 2022-04-06T00:00+02:00[Europe/Berlin]
2022-04-06 21:46:06.197 [INFO ] [.openhab.core.model.script.Wind diag] - got value 27.0
2022-04-06 21:46:06.201 [INFO ] [.openhab.core.model.script.Wind diag] - from 2022-04-06T10:00:00.393+02:00[Europe/Berlin]
2022-04-06 21:47:06.188 [INFO ] [.openhab.core.model.script.Wind diag] - Using datetime 2022-04-06T00:00+02:00[Europe/Berlin]
2022-04-06 21:47:06.200 [INFO ] [.openhab.core.model.script.Wind diag] - got value 27.0
2022-04-06 21:47:06.202 [INFO ] [.openhab.core.model.script.Wind diag] - from 2022-04-06T10:00:00.393+02:00[Europe/Berlin]
2022-04-06 21:47:06.208 [INFO ] [.openhab.core.model.script.Wind diag] - Today's max wind gust is 27.0 m/s at 2022-04-06T10:00:00.393+02:00[Europe/Berlin]
2022-04-06 21:48:00.019 [INFO ] [.openhab.core.model.script.Wind diag] - Using datetime 2022-04-06T00:00+02:00[Europe/Berlin]
2022-04-06 21:48:00.029 [INFO ] [.openhab.core.model.script.Wind diag] - got value 27.0
2022-04-06 21:48:00.032 [INFO ] [.openhab.core.model.script.Wind diag] - from 2022-04-06T10:00:00.393+02:00[Europe/Berlin]
2022-04-06 21:48:00.036 [INFO ] [.openhab.core.model.script.Wind diag] - Today's max wind gust is 27.0 m/s at 2022-04-06T10:00:00.393+02:00[Europe/Berlin]
2022-04-06 21:48:18.035 [INFO ] [.openhab.core.model.script.Wind diag] - Using datetime 2022-04-06T00:00+02:00[Europe/Berlin]
2022-04-06 21:48:18.043 [INFO ] [.openhab.core.model.script.Wind diag] - got value 27.0
2022-04-06 21:48:18.045 [INFO ] [.openhab.core.model.script.Wind diag] - from 2022-04-06T10:00:00.393+02:00[Europe/Berlin]
2022-04-06 21:48:18.051 [INFO ] [.openhab.core.model.script.Wind diag] - Today's max wind gust is 27.0 m/s at 2022-04-06T10:00:00.393+02:00[Europe/Berlin]
2022-04-06 21:48:24.227 [INFO ] [.openhab.core.model.script.Wind diag] - Using datetime 2022-04-06T00:00+02:00[Europe/Berlin]
2022-04-06 21:48:24.240 [INFO ] [.openhab.core.model.script.Wind diag] - got value 27.0
2022-04-06 21:48:24.244 [INFO ] [.openhab.core.model.script.Wind diag] - from 2022-04-06T10:00:00.393+02:00[Europe/Berlin]
2022-04-06 21:48:24.251 [INFO ] [.openhab.core.model.script.Wind diag] - Today's max wind gust is 27.0 m/s at 2022-04-06T10:00:00.393+02:00[Europe/Berlin]
2022-04-06 21:48:34.310 [INFO ] [.openhab.core.model.script.Wind diag] - Using datetime 2022-04-06T00:00+02:00[Europe/Berlin]
2022-04-06 21:48:34.319 [INFO ] [.openhab.core.model.script.Wind diag] - got value 27.0
2022-04-06 21:48:34.321 [INFO ] [.openhab.core.model.script.Wind diag] - from 2022-04-06T10:00:00.393+02:00[Europe/Berlin]
2022-04-06 21:48:34.325 [INFO ] [.openhab.core.model.script.Wind diag] - Today's max wind gust is 27.0 m/s at 2022-04-06T10:00:00.393+02:00[Europe/Berlin]
2022-04-06 21:48:42.116 [INFO ] [.openhab.core.model.script.Wind diag] - Using datetime 2022-04-06T00:00+02:00[Europe/Berlin]
2022-04-06 21:48:42.123 [INFO ] [.openhab.core.model.script.Wind diag] - got value 27.0
2022-04-06 21:48:42.125 [INFO ] [.openhab.core.model.script.Wind diag] - from 2022-04-06T10:00:00.393+02:00[Europe/Berlin]
2022-04-06 21:48:42.129 [INFO ] [.openhab.core.model.script.Wind diag] - Today's max wind gust is 27.0 m/s at 2022-04-06T10:00:00.393+02:00[Europe/Berlin]
2022-04-06 21:49:00.017 [INFO ] [.openhab.core.model.script.Wind diag] - Using datetime 2022-04-06T00:00+02:00[Europe/Berlin]
2022-04-06 21:49:00.033 [INFO ] [.openhab.core.model.script.Wind diag] - got value 27.0
2022-04-06 21:49:00.037 [INFO ] [.openhab.core.model.script.Wind diag] - from 2022-04-06T10:00:00.393+02:00[Europe/Berlin]
2022-04-06 21:49:00.044 [INFO ] [.openhab.core.model.script.Wind diag] - Today's max wind gust is 27.0 m/s at 2022-04-06T10:00:00.393+02:00[Europe/Berlin]
2022-04-06 21:50:00.015 [INFO ] [.openhab.core.model.script.Wind diag] - Using datetime 2022-04-06T00:00+02:00[Europe/Berlin]
2022-04-06 21:50:00.027 [INFO ] [.openhab.core.model.script.Wind diag] - got value 27.0
2022-04-06 21:50:00.029 [INFO ] [.openhab.core.model.script.Wind diag] - from 2022-04-06T10:00:00.393+02:00[Europe/Berlin]
2022-04-06 21:50:00.034 [INFO ] [.openhab.core.model.script.Wind diag] - Today's max wind gust is 27.0 m/s at 2022-04-06T10:00:00.393+02:00[Europe/Berlin]

The main difference seems to be LocalTime instead of now.minusMinutes(x). Could this be a source of error?

EDIT:
I tried to adapt the MaxDay rule and separated the rule with another variable for minusMinutes

rule "Wind Maximum 5 Minuten"

when
	//Time cron "0 0/5 * * * ?"
	Item AT_Dachflache_Wind changed or
	Time cron "0 * * * * ?"
then
	var m5 = now.minusMinutes(5)
	logInfo ("Wind diag", "Using datetime Wind Max5 " + m5.toString)
	var Wind_Max5 = AT_Dachflache_Wind.maximumSince(m5, "jdbc")
	logInfo ("Wind diag", "Value Wind Max5 " + Wind_Max5.state.toString)
    logInfo ("Wind diag", "Timestamp Wind Max5 " + Wind_Max5.timestamp.toString)
	AT_Dachflache_Wind_Max5.postUpdate(Wind_Max5.state)
//	AT_Dachflache_Wind_Max5.postUpdate(AT_Dachflache_Wind.maximumSince(ZonedDateTime.now.minusMinutes(5), "jdbc"))
	logInfo ("Wind Maximumsince5","Max5 wind was: " + Wind_Max5.state.toString)    
	logInfo ("Wind Maximumsince5","Max5 occurred at " + Wind_Max5.getTimestamp.toString)  	
//    logInfo ("Wind Maximumsince5","Maximum Wind was: " + AT_Dachflache_Wind_Max5.state + " m/s at " + AT_Dachflache_Wind.maximumSince(now.minusMinutes(5)).timestamp)    
	var zz = AT_Dachflache_Wind.historicState(m5, "jdbc")
// this is NOT a number either
	logInfo ("Wind Maximumsince5","Max5 value 5 mins ago was: " + zz.state.toString)    
	logInfo ("Wind Maximumsince5","Max5 Wind record from  " + zz.getTimestamp.toString)
end

This is the log. minusMinutes fetches the correct time. However, maximumSince always picks the last recorded value.

2022-04-06 22:59:12.785 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'AT_Dachflache_Wind_Max5' changed from 0.0 to 10.44
2022-04-06 22:59:20.011 [INFO ] [core.model.script.Wind Maximumsince5] - Max5 value 5 mins ago was: 0.0
2022-04-06 22:59:20.014 [INFO ] [core.model.script.Wind Maximumsince5] - Max5 Wind record from  2022-04-06T22:30:00.780+02:00[Europe/Berlin]
2022-04-06 22:59:20.020 [INFO ] [.openhab.core.model.script.Wind diag] - Using datetime Wind Max52022-04-06T22:54:20.018264+02:00[Europe/Berlin]
2022-04-06 22:59:20.041 [INFO ] [.openhab.core.model.script.Wind diag] - Value Wind Max5 6.12
2022-04-06 22:59:20.044 [INFO ] [.openhab.core.model.script.Wind diag] - Timestamp Wind Max5 2022-04-06T22:59:20.043624+02:00[Europe/Berlin]
2022-04-06 22:59:20.048 [INFO ] [core.model.script.Wind Maximumsince5] - Max5 wind was: 6.12
2022-04-06 22:59:20.051 [INFO ] [core.model.script.Wind Maximumsince5] - Max5 occurred at 2022-04-06T22:59:20.051067+02:00[Europe/Berlin]
2022-04-06 22:59:20.058 [INFO ] [core.model.script.Wind Maximumsince5] - Max5 value 5 mins ago was: 0.0
2022-04-06 22:59:20.060 [INFO ] [core.model.script.Wind Maximumsince5] - Max5 Wind record from  2022-04-06T22:30:00.780+02:00[Europe/Berlin]
2022-04-06 22:59:20.051 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'AT_Dachflache_Wind_Max5' changed from 10.44 to 6.12
2022-04-06 22:59:26.568 [INFO ] [.openhab.core.model.script.Wind diag] - Using datetime Wind Max5 2022-04-06T22:54:26.565942+02:00[Europe/Berlin]
2022-04-06 22:59:26.576 [INFO ] [.openhab.core.model.script.Wind diag] - Value Wind Max5 7.5600000000000005
2022-04-06 22:59:26.579 [INFO ] [.openhab.core.model.script.Wind diag] - Timestamp Wind Max5 2022-04-06T22:59:26.578408+02:00[Europe/Berlin]
2022-04-06 22:59:26.590 [INFO ] [core.model.script.Wind Maximumsince5] - Max5 wind was: 7.5600000000000005
2022-04-06 22:59:26.594 [INFO ] [core.model.script.Wind Maximumsince5] - Max5 occurred at 2022-04-06T22:59:26.593471+02:00[Europe/Berlin]
2022-04-06 22:59:26.602 [INFO ] [core.model.script.Wind Maximumsince5] - Max5 value 5 mins ago was: 0.0
2022-04-06 22:59:26.606 [INFO ] [core.model.script.Wind Maximumsince5] - Max5 Wind record from  2022-04-06T22:30:00.780+02:00[Europe/Berlin]
2022-04-06 22:59:26.586 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'AT_Dachflache_Wind_Max5' changed from 6.12 to 7.5600000000000005
2022-04-06 22:59:33.967 [INFO ] [.openhab.core.model.script.Wind diag] - Using datetime Wind Max5 2022-04-06T22:54:33.966381+02:00[Europe/Berlin]
2022-04-06 22:59:33.976 [INFO ] [.openhab.core.model.script.Wind diag] - Value Wind Max5 5.76
2022-04-06 22:59:33.979 [INFO ] [.openhab.core.model.script.Wind diag] - Timestamp Wind Max5 2022-04-06T22:59:33.978982+02:00[Europe/Berlin]
2022-04-06 22:59:33.985 [INFO ] [core.model.script.Wind Maximumsince5] - Max5 wind was: 5.76
2022-04-06 22:59:33.988 [INFO ] [core.model.script.Wind Maximumsince5] - Max5 occurred at 2022-04-06T22:59:33.988317+02:00[Europe/Berlin]
2022-04-06 22:59:33.999 [INFO ] [core.model.script.Wind Maximumsince5] - Max5 value 5 mins ago was: 0.0
2022-04-06 22:59:34.002 [INFO ] [core.model.script.Wind Maximumsince5] - Max5 Wind record from  2022-04-06T22:30:00.780+02:00[Europe/Berlin]
2022-04-06 22:59:33.984 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'AT_Dachflache_Wind_Max5' changed from 7.5600000000000005 to 5.76
2022-04-06 22:59:38.302 [INFO ] [.openhab.core.model.script.Wind diag] - Using datetime Wind Max5 2022-04-06T22:54:38.300274+02:00[Europe/Berlin]
2022-04-06 22:59:38.309 [INFO ] [.openhab.core.model.script.Wind diag] - Value Wind Max5 0.0
2022-04-06 22:59:38.311 [INFO ] [.openhab.core.model.script.Wind diag] - Timestamp Wind Max5 2022-04-06T22:59:38.310835+02:00[Europe/Berlin]
2022-04-06 22:59:38.314 [INFO ] [core.model.script.Wind Maximumsince5] - Max5 wind was: 0.0
2022-04-06 22:59:38.317 [INFO ] [core.model.script.Wind Maximumsince5] - Max5 occurred at 2022-04-06T22:59:38.317122+02:00[Europe/Berlin]
2022-04-06 22:59:38.323 [INFO ] [core.model.script.Wind Maximumsince5] - Max5 value 5 mins ago was: 0.0
2022-04-06 22:59:38.326 [INFO ] [core.model.script.Wind Maximumsince5] - Max5 Wind record from  2022-04-06T22:30:00.780+02:00[Europe/Berlin]
2022-04-06 22:59:38.317 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'AT_Dachflache_Wind_Max5' changed from 5.76 to 0.0

The result of that would be that the maximum of the last five minutes is … the current value. (There is no other data available for the last five minutes. historicState() will search backwards to last record whenever … but maximumSince() will not I think)

Sounds like you are not persisting the Item you are querying in the database you are looking at.
When checking data using REST API, don’t forget that needs to be told which database to look in too.

I guess that was the solution, @rossko57. I checked my persistence file again and found a mistake:

I had persisted all weather measurements, including wind, with every30Minutes. For wind explicitely I only persisted all max values (5 mins., 1 hour, all day) with

   AT_Dachflache_Wind_* : strategy = everyChange

However, the original measurement for the item AT_Dachflache_Wind was not stored on everyChange (notice the underscore in the strategy).

Now I went with

   AT_Dachflache_Wind : strategy = everyChange

and my database gets filled with values. I guess that all the suggestions you all made along the way helped to fix errors but as it looks this was the last missing piece of the puzzle.
Thank you all for your support. I will mark this post as the solution and I hope that this thread will help others who are working with maximumSince.

Careful with persist configuration. That is NOT a wildcard in this context. It means to persist all members of a Group named AT_Dachflache_Wind_ , and I will bet you do not even have a Group Item named exactly that.

This is in the docs.

Thank you. You are right. I meant to use it as a wild card.