Template sensor is doing wrong calculations

Hey flolks,
sorry i but i go cracy! I want to do a simple sum of energy values but i get all the time wrong calculations.
I have three energy values wich are mainly derived from an utility meter and i want to sum them up to calculate the main power used in an building.
It is energy from net + energy from pv - energy given to net ..... the sad thin is i get jumps at the end of each hour - maybe it comes from summing up utility meters ......


Any help is appreciated and i cant find an simmilar problem in the forum maybe anyone has had the same issue

kind regards
Heli

The template will update when any of the source sensor states changes. If they are utility meters that update periodically, you will get this symptom.

You could, in YAML, make a trigger-based sensor that only updates at a specific time: either a time within an hour, or when only one of the sensors changes.

This indeed is very strange.
You are adding the pv energy (orange) to the energy from net (blue) end subtract the energy given back to the net (yellow, which is zero in this period)?
According to the graph this should not show those steps in the resultant energy (green).
But are you sure about the shown units of the sensors?
These are all in kWh, and your decimal sign is a comma?
That would mean that your solar panels did supply more than 200 kWh in four hours, and there is more then 600 kWh imported from the net in the same period?
What kind of building is this? A factory?

Yes I am pretty sure about the units - because som of them had Wh and some kWh so I am already past that :slight_smile: . Yes the measured values are correct (yes indeed it is not an factory but an campus)

Thx Ill give it a try- do you think the steps may arise from the hourly reset in the utility meters?

I would do this the other way around: sum the source sensors, and create a utility meter for that resulting sensor. Note: this will only work correctly if the sensor values are only ever increasing and not resetting.

1 Like

Thx but I have already tried this but as you mentioned this does not work because the sensors are resetting- which made me to use utility meters....

If you sum the sensors on a static period using a trigger based template entity, then provide that to utility meter, it should work. You'll likely need to make sure that the value is 0 for these at midnight by checking the time in the template. This is assuming that your entities reset at midnight.

1 Like

So as marked a solution I've used trigger based sensor (Thx for your help petro and troon) and now thing are calculated correct. But honestly I think this is a BUG.
it is cracy how far calculations are going to drift away