I’ve created a template energy sensor to display on the energy dashboard which takes the values of 4 related sensors, and combines them into one. My issue is that the page is reporting way above what the individual sensors are.
The total reported by each of the sensors adds up to 8.415 kWh (which is the total, not todays values) but the energy dashboard shows 21.06kWh for the same sensor. I thought it would reset each night.
Can anyone shed light on what may be happening.
The template sensor is shown below, and I believe is configured correctly.
And to top it all off, I woke this morning to find that the fridge had actually been generating energy overnight and the greenhouse sensor (combined) actually aligns with the 4 that I mentioned originally.
Did you ever find the problem? I have a similar issue where I combine the energy of 2 phases to see the total and the template sensor is significantly higher than the sum
No, I threw everything into the too-hard basket for a while. Having returned to it the other day, I did notice figures were above what they should be. I deleted the sensor from the view and re-added it and so far appears to be fine.
I don’t really understand as the sensor itself seems to set correctly as per the below config. It would be nice if someone could give it a once over.
- sensor:
- name: Greenhouse Total Consumption
unique_id: greenhouse_total_consumption
device_class: energy
state_class: total_increasing
unit_of_measurement: kWh
state: >
{% set bucket_pump = states('sensor.tasmota_greenhouse_bucket_pump_energy_total') | float(0) %}
{% set nft_pump = states('sensor.tasmota_greenhouse_nft_pump_energy_total') | float(0) %}
{% set exhaust = states('sensor.tasmota_greenhouse_exhaust_energy_total') | float(0) %}
{% set cooler = states('sensor.tasmota_greenhouse_cooler_energy_total') | float(0) %}
{{ ((bucket_pump + nft_pump + exhaust + cooler)) }}
availability: >
{{ bucket_pump != none and nft_pump != none and exhaust != none and cooler != none }}
So, I found the root cause of the problem (not yet the solution as I’m trying couple of options:) ).
To simplify the explanation, let’s assume you have a sensor named sensortotal which is the sum of two other sensors (sensor1 + sensor2).
Because there are no triggers defined for sensortotal, every change on either sensor1 or sensor2 will trigger the sensortotal to be calculated.
At 12 AM every day, both sensor1 and sensor2 will be reset to zero. But that is not an atomic operation and instead one of the sensors is zeroed before the other.
As soon as one of the sensors is zeroed (i.e. sensor1), the calculation for sensortotal is triggered. And the calculation will be sensor1=0 + sensor2=xx(old value) at 12AM.
So, you have one value at 12:00AM (next day) for the combined sensor.
And because it’s auto-increment, you start the day with some value that breaks the daily calculations.