New template Sensors for Energy start new day with negative value

I have several template sensor with this configuration

template:
  - sensor:
    - name: "Laptop"
      unique_id: "laptop_daily_energy"
      unit_of_measurement: "kWh"
      state_class: measurement
      device_class: energy
      state: '{{ states("sensor.laptop_total_daily_energy") | float }}'
      attributes:
        last_reset: '1970-01-01T00:00:00+00:00'

They are visible on energy dashboard and reset every day. But every new day they start with negative values. If I check the sensor itself it shows it goes every day at midnight to 0. But it get shown with negative value.


Any idea why this happens? Why are they not starting also on the dashboard with 0?

The energy dashboard updates once an hour. It then subtracts the value from the current hour from the value of the previous hour. So at midnight it will be 0 - value from 11 PM, which results in a negative value. You need to feed a total energy consumption sensor to the enrrgy dashboard to get correct results.