# Purpose of Sum.EnergyValuesHandler

**URL:** <https://community.openems.io/t/purpose-of-sum-energyvalueshandler/10848>\
**Category:** Software-Development\
**Created:** [May 12, 2026, 4:28pm UTC](https://community.openems.io/t/purpose-of-sum-energyvalueshandler/10848 "2026-05-12T16:28:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tsicking](https://community.openems.io/user_avatar/community.openems.io/tsicking/32/954_2.png) [@tsicking](https://community.openems.io/u/tsicking)\
**Post date:** [May 12, 2026, 4:28pm UTC](https://community.openems.io/t/purpose-of-sum-energyvalueshandler/10848/1 "2026-05-12T16:28:35Z")

</div>

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:

```java
	/**
	 * 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

---

<div class="post-metadata">

**Author:** ![stefan.feilmeier](https://community.openems.io/user_avatar/community.openems.io/stefan.feilmeier/32/2585_2.png) [@stefan.feilmeier](https://community.openems.io/u/stefan.feilmeier)\
**Post date:** [May 14, 2026, 5:54pm UTC](https://community.openems.io/t/purpose-of-sum-energyvalueshandler/10848/2 "2026-05-14T17:54:14Z")

</div>

> [@tsicking](#):
>
> 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 would indeed be a big change, but actually something we should consider… In theory calculating energy manually from power has its downsides; but the benefits might be worth it.

---

<div class="post-metadata">

**Author:** ![tsicking](https://community.openems.io/user_avatar/community.openems.io/tsicking/32/954_2.png) [@tsicking](https://community.openems.io/u/tsicking)\
**Post date:** [June 10, 2026, 4:02pm UTC](https://community.openems.io/t/purpose-of-sum-energyvalueshandler/10848/3 "2026-06-10T16:02:01Z")

</div>

Hi Stefan, thanks for the response. I didn’t have time to pursue this further, but I still believe we should handle it the way I suggested. When I find time, I can implement and test it.  
Can you specify the downsides of this approach?

Best regards,  
Thomas

---

<div class="post-metadata">

**Author:** ![stefan.feilmeier](https://community.openems.io/user_avatar/community.openems.io/stefan.feilmeier/32/2585_2.png) [@stefan.feilmeier](https://community.openems.io/u/stefan.feilmeier)\
**Post date:** [November 7, 2026, 9:24pm UTC](https://community.openems.io/t/purpose-of-sum-energyvalueshandler/10848/4 "2026-11-07T21:24:10Z")

</div>

> [@tsicking](#):
>
> Can you specify the downsides of this approach?

Currently the Sum Energy Values are based directly on the Energy Values of the individual Meters. If we calculate Energy in Sum from Power values, we lose this relation.

This direct relation also comes with the downside that if one Meter disappears, its energy value is also missing, which might lead to negative energy. This problem would be solved if we would follow your suggestion.
