Hi all,
I recently stumbled across the EnergyValuesHandler in the Sum-Component. According to the Javadoc. it is supposed to make sure that energy values are steadily rising. However, I don’t think it is doing that. Have a look at the main method:
/**
* Sets the value of the Channel if it is greater-or-equals the lastValue.
*
* @param channelId the Channel-Id
* @param value the energy value
* @return the value that was set; might be null
*/
public Long setValue(Sum.ChannelId channelId, Long value) {
if (!this.lastEnergyValues.containsKey(channelId)) {
// lastValue was not initialized yet -> ignore value
value = null;
} else if (value == null) {
// if value is null, replace it by last value
var lastValue = this.lastEnergyValues.get(channelId);
value = lastValue;
}
this.parent.channel(channelId).setNextValue(value);
this.lastEnergyValues.put(channelId, value);
return value;
}
Nowhere in the code it is checked whether value is greater or equals to the last value of the channel. All this method does is to wait for initialisation by the Timedata (first if-clause), and using the last value from the Timedata if value == null. And indeed we have seen that e.g. if a grid meter is exchanged and the new grid meter starts counting at 0 again, the values of _sum/GridBuyActiveEnergy and _sum/GridSellActiveEnergy will decrease, leading to wrong energy values in the UI-history (for the whole year actually).
I know it would be a big change, but wouldn’t it make more sense to calculate the energy values of the Sum component with CalculateEnergyFromPower, e.g. calculate _sum/GridBuyActiveEnergy and _sum/GridSellActiveEnergy from _sum/GridActivePower? It is a well established way in OpenEMS, and I think it would solve a lot of problems regarding hardware exchanges. Or am I missing something?
Let me know what you think.
Best regards,
Thomas