Issue of the topic: please be detailed explaining your issue
I have a problem with my DateTime group item.
I want to display the oldest value of sensor updates.
The members of the group are updated rule based.
All members in the sitemap are displayed correctly.
Only the group state is UNDEF and so not displayed.
Can someone help.
I’m not at all sure that MIN/MAX aggregations are implemented for DateTime Group types. Not every function makes sense for every possible type e.g. what should AVG or SUM do with dates?
The docs do say that MIN/MAX/AVG are for “decimal type” (Number)
EDIT - so, how to do it instead? Using Group functions is a neat idea, but you’d have to do it with a Group of Number Items holding the “timestamp” as an epoch integer.
Easy enough to populate those from your timestamping rule.
For display, you could use a transform to convert epoch to readable - a javascript I should think.
Or abandon the group, and have your rule populate a dedicated “oldest” Item. The rule would have to retrieve the “old” individual value before updating the timestamp, and compare with current “oldest”.
Hmm, then you’d still need to search for the next-oldest. That’s an interesting little task … I can feel a sorted list coming on somewhere.
I am also trying to a get the oldest lastupdate datetime from a group.
rule "Record LastUpdateTest"
when
Member of LastUpdateTest changed
then
logInfo("LastUpdateTest", "Groupmembertest start")
var oldestDT = LastUpdateTest.members.map[(state as DateTimeType).zonedDateTime].reduce[oldest, curr | oldest = if(curr.isBefore(oldest)) curr else oldest]
logInfo("LastUpdateTest", oldestDT.toStrings)
logInfo("LastUpdateTest", "Groupmembertest end")
end
I get the error: Rule ‘Record LastUpdateTest’: Couldn’t invoke ‘assignValueTo’ for feature param oldest
The group LastUpdateTest contains only DateTime items. They are linked to zwave devices with the profile timestamp-update.
I coincidentally stepped into this and started thinking about enhancing our available group aggregation function by support for MIN and MAX. What I found was an undocumented bunch of DateTime group functions: LATEST and EARLIEST. I guess they will help you to get what you want.
Wonder how long those have been there and how many other little useful features are hiding in OH like this. I could have used this years ago. Great find!
They are available for more than two years (see PR). And I found a piece of documentation in the Concepts -> Items section. Imo Configuration Guide -> Items is a better place for it. No need to describe it twice. Just add a cross reference in the first location.
Example:
Assuming we have a Group containing three timestamps: now().minusDays(10), now() and now().plusSeconds(30). The EARLIEST function returns now().minusDays(10), the LATEST function returns now().plusSeconds(30).