I obtain simlar data from my anemometer and I have also setup routines in OH to determine max and mins using persistance data. My persistence strategy is the same as yours.
Looking at your data it appears the maximumSince function is not finding the maxuimum value during the period but rather the wind value at the instant the function is called by the cron. Here are a few ideas:
-
Could be a java time issue. See this post… Migrate JodaTime to Java LocalDateTime in OH3 (withTimeAtStartOfDay)
-
Also, In my rule, it executes when the wind speed changes, not at a regular interval as per a cron
Here is my working code where it calculates the maximum wind gust for the day. It may help in your situation:
import java.time.ZonedDateTime
rule "Calculate today's max wind gust"
when
Item Anemometer_WindGust1MinutePeak changed
then
// formatter is needed in the conversion of Java time (ZoneDateTime) to DateTime.
// See the following link for discussion on time conversion. https://community.openhab.org/t/datetime-conversion-openhab-3-x/107197/16.
// See in particular post from Bartkummel in Jan21
val formatter = java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
Maximum_wind_gust_today.postUpdate(Anemometer_WindGust1MinutePeak.maximumSince(now.with(LocalTime.of(0,0,0,0))).state)
// get time of max gust. This is returned in Java time (ZoneDateTime variable)
var time_of_max_gust = Anemometer_WindGust1MinutePeak.maximumSince(now.with(LocalTime.of(0,0,0,0))).timestamp
// convert to string using above formatter anmd then convert to DateTime variable using DateTimeType
Timeof_Maximum_wind_gust_today.postUpdate(DateTimeType.valueOf(time_of_max_gust.format(formatter)))
//logInfo("org.openhab","Today's max wind gust is " + Maximum_wind_gust_today.state + " km/hr at " + Timeof_Maximum_wind_gust_today.state.format("%1$tr"))
end
Note: To run this code, you will need to create 2 items; Maximum_wind_gust_today (number) and Timeof_Maximum_wind_gust_today (DateTime).
Hope this helps.