Open 5iver opened 5 years ago
Thanks for reporting. Why don't you submit a PR on your own? That will be appreciated.
My hands are a bit full ATM, but I plan to get one together if nobody gets it in before I free up.
As a workaround, I removed the group function and I'm manually updating the group state using the following algorithm:
windDirectionItemStates = map(lambda item: item.state.intValue(), ir.getItem("gForecast_WindDirection_" + str(index)).getMembers())
windDirectionAvg = reduce(lambda x, y: (((x + y) / 2) if y - x < 180 else (x + y + 360) / 2) % 360, windDirectionItemStates)
events.postUpdate("gForecast_WindDirection_" + str(index), str(windDirectionAvg))
I came across this while setting up groups to calculate daily forecasts for OWM using a free API key, so @cweitkamp may be enticed to look into this one.
The Avg group function calculates the average of angles incorrectly. This Wikipedia article explains, and has a formula that could be used.
https://github.com/eclipse/smarthome/blob/master/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/library/types/ArithmeticGroupFunction.java#L216